<?php
// config.php — Travelica Agency Configuration

$is_local = (php_sapi_name() === 'cli')
         || in_array($_SERVER['HTTP_HOST'] ?? '', ['localhost', '127.0.0.1', 'travel_new.test', 'travel.test']) 
         || (isset($_SERVER['HTTP_HOST']) && (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false || str_ends_with($_SERVER['HTTP_HOST'], '.test')));

if ($is_local) {
    // ── Localhost / Laragon ────────────────────────────────────
    $host    = '127.0.0.1';
    $db      = 'travelica';
    $user    = 'root';
    $pass    = '';
} else {
    // ── Production / Rumahweb cPanel ───────────────────────────
    $host    = 'localhost';
    $db      = 'tent2559_travel';
    $user    = 'tent2559_travel';
    $pass    = 'tent2559_travel';
}

$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];

try {
    $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
    throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

// ── Admin credentials ──────────────────────────────────────
define('ADMIN_USER', 'admin');
define('ADMIN_PASS', password_hash('travelica2026', PASSWORD_DEFAULT));

// ── Flag Helper ────────────────────────────────────────────
require_once __DIR__ . '/includes/flags.php';

// ── Site Settings Helper ───────────────────────────────────
require_once __DIR__ . '/includes/settings.php';
