<?php
// =====================================================
//  SAVORIA Restaurant — Configuration
//  Edit the values below to match your server.
// =====================================================

define('DB_HOST', 'localhost');
define('DB_NAME', 'savoria');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_CHARSET', 'utf8mb4');

define('SITE_NAME', 'SAVORIA');
define('SITE_EMAIL', 'reservations@savoria.com');
define('SITE_PHONE', '+1 (555) 123-4567');

define('DELIVERY_FEE', 5.00);
define('FREE_DELIVERY_THRESHOLD', 80.00);
define('TAX_RATE', 0.08);

define('ADMIN_PASSWORD', 'savoria2024');

// ── Database connection ───────────────────────────────
function getDB(): PDO {
    static $pdo = null;
    if ($pdo === null) {
        $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET;
        $pdo = new PDO($dsn, DB_USER, DB_PASS, [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ]);
    }
    return $pdo;
}

// ── Session start ─────────────────────────────────────
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// ── Helper: redirect ──────────────────────────────────
function redirect(string $url): void {
    header("Location: $url");
    exit;
}

// ── Helper: sanitize output ───────────────────────────
function e(string $s): string {
    return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
}

// ── Helper: is admin ──────────────────────────────────
function isAdmin(): bool {
    return isset($_SESSION['savoria_admin']) && $_SESSION['savoria_admin'] === true;
}
