<?php
echo "=== DEBUG INDEX ===<br>";
echo "PHP Version: " . phpversion() . "<br>";
echo "Current directory: " . getcwd() . "<br>";

// Verificar bootstrap
$bootstrap_path = __DIR__ . '/../src/bootstrap.php';
echo "Bootstrap path: $bootstrap_path<br>";
echo "Bootstrap exists: " . (file_exists($bootstrap_path) ? "YES" : "NO") . "<br>";

try {
    echo "Loading bootstrap...<br>";
    require_once $bootstrap_path;
    echo "✅ Bootstrap loaded<br>";
    
    // Test database
    echo "Testing database...<br>";
    $db = App\Services\Database::getInstance();
    $result = $db->query("SELECT 1 as test")->fetch();
    echo "✅ Database OK<br>";
    
    // Test session
    echo "Session status: " . session_status() . "<br>";
    echo "Session ID: " . (session_id() ?: 'Not started') . "<br>";
    
    // Test AuthController
    echo "Testing AuthController...<br>";
    $auth = new App\Controllers\AuthController();
    echo "✅ AuthController OK<br>";
    
    // Test routing
    echo "<h2>Route Test</h2>";
    $request_uri = $_SERVER['REQUEST_URI'] ?? '/';
    $path = parse_url($request_uri, PHP_URL_PATH);
    $path = rtrim($path, '/');
    if (empty($path)) {
        $path = '/';
    }
    
    echo "REQUEST_URI: $request_uri<br>";
    echo "Parsed path: $path<br>";
    
    switch ($path) {
        case '/':
        case '/login':
            echo "✅ Would show login<br>";
            break;
        case '/dashboard':
            echo "✅ Would show dashboard<br>";
            break;
        default:
            echo "❓ Unknown route: $path<br>";
    }
    
} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage() . "<br>";
    echo "<pre>" . $e->getTraceAsString() . "</pre>";
}

echo "=== END DEBUG ===";
?>