<?php
// includes/config.php
// Database configuration
define('DB_HOST', 'localhost');
define('DB_NAME', 'sellbazar');
define('DB_USER', 'root');
define('DB_PASS', '');

error_reporting(E_ALL);
ini_set('display_errors', 1);
// Base URL - CHANGE THIS TO MATCH YOUR SETUP
define('BASE_URL', 'http://localhost/');
define('ASSETS_URL', BASE_URL . 'assets/');

// Start session
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Database connection
try {
    $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, 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("Connection failed: " . $e->getMessage());
}

// Make pdo available globally
$GLOBALS['pdo'] = $pdo;

// ========================================
// FACEBOOK PIXEL SETTINGS
// ========================================
// Define constants after database connection
// We'll use function to get settings instead

// Function to get setting - defined here for config
function getSettingFromDB($key) {
    global $pdo;
    try {
        $stmt = $pdo->prepare("SELECT value FROM settings WHERE `key` = ?");
        $stmt->execute([$key]);
        $result = $stmt->fetch();
        return $result ? $result['value'] : null;
    } catch (Exception $e) {
        return null;
    }
}

// Define Facebook Pixel constants
define('FACEBOOK_PIXEL_ID', getSettingFromDB('facebook_pixel_id'));
define('FACEBOOK_ACCESS_TOKEN', getSettingFromDB('facebook_access_token'));
define('FACEBOOK_CAPI_ENABLED', getSettingFromDB('facebook_capi_enabled'));
define('FACEBOOK_PIXEL_TEST_CODE', getSettingFromDB('facebook_pixel_test_code'));
?>