<?php
/**
 * Main Router File
 * Handles all requests and routes to appropriate pages
 */

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

// Include configuration
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/config/constants.php';
require_once __DIR__ . '/includes/init.php';

// Include Router
require_once __DIR__ . '/includes/Router.php';

// Get matched route
$matchedFile = $router->match();

if ($matchedFile && file_exists(__DIR__ . '/' . $matchedFile)) {
    // Include the matched file
    require_once __DIR__ . '/' . $matchedFile;
} else {
    // 404 - Page not found
    http_response_code(404);
    if (file_exists(__DIR__ . '/404-electronics.php')) {
        require_once __DIR__ . '/404-electronics.php';
    } else {
        echo "404 - Page not found";
    }
}
?>

