<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'max_power');

define('ADMIN_USER', 'admin');
define('ADMIN_PASS', 'admin123');

try {
    $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8", DB_USER, DB_PASS);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch(PDOException $e) {
    die("Veritabanı bağlantı hatası: " . $e->getMessage());
}

$products = [
    0 => [
        'name' => '1 Kutu Max Power 30lu Kapsül',
        'price' => '1499.00'
    ],
    1 => [
        'name' => '2 Kutu Max Power 30lu Kapsül',
        'price' => '2299.00'
    ],
    2 => [
        'name' => '3 Kutu Max Power 30lu Kapsül',
        'price' => '2999.00'
    ]
];

$payment_types = [
    'kapidanakit' => ['label' => 'Kapıda Nakit', 'icon' => 'fa-money-bill', 'color' => 'warning', 'bg' => '#fff3cd', 'text' => '#856404'],
    'kapidakart' => ['label' => 'Kapıda Kredi Kartı', 'icon' => 'fa-credit-card', 'color' => 'primary', 'bg' => '#cce5ff', 'text' => '#004085']
];

$statuses = [
    'pending' => ['label' => 'Onay Bekleyen', 'color' => 'warning', 'bg' => '#fff3cd', 'text' => '#856404'],
    'approved' => ['label' => 'Onaylanan', 'color' => 'info', 'bg' => '#d1ecf1', 'text' => '#0c5460'],
    'shipped' => ['label' => 'Kargoda', 'color' => 'primary', 'bg' => '#cce5ff', 'text' => '#004085'],
    'delivered' => ['label' => 'Teslim Edilen', 'color' => 'success', 'bg' => '#d4edda', 'text' => '#155724']
];

function getProductName($id) {
    global $products;
    return isset($products[$id]) ? $products[$id]['name'] : 'Bilinmeyen Ürün';
}

function getProductPrice($id) {
    global $products;
    return isset($products[$id]) ? $products[$id]['price'] : '0.00';
}

function getStatusLabel($status) {
    global $statuses;
    return isset($statuses[$status]) ? $statuses[$status]['label'] : 'Bilinmeyen';
}

function getStatusBadge($status) {
    global $statuses;
    if (!isset($statuses[$status])) return '<span class="badge bg-secondary">Bilinmeyen</span>';
    $s = $statuses[$status];
    return '<span class="badge" style="background-color: '.$s['bg'].'; color: '.$s['text'].';">'.$s['label'].'</span>';
}

function getPaymentLabel($type) {
    global $payment_types;
    return isset($payment_types[$type]) ? $payment_types[$type]['label'] : 'Bilinmeyen';
}

function getPaymentBadge($type) {
    global $payment_types;
    if (!isset($payment_types[$type])) return '<span class="badge bg-secondary">Bilinmeyen</span>';
    $p = $payment_types[$type];
    return '<span class="badge" style="background-color: '.$p['bg'].'; color: '.$p['text'].';"><i class="fas '.$p['icon'].' me-1"></i>'.$p['label'].'</span>';
}

function isLoggedIn() {
    return isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true;
}

function redirect($url) {
    header("Location: $url");
    exit;
}

function cleanInput($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
