<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

if (version_compare(PHP_VERSION, '8.3.0', '<')) {
    header('HTTP/1.1 500 Internal Server Error');
    echo '<!DOCTYPE html><html><head><meta charset="utf-8"><title>PHP 版本过低</title></head><body style="display:flex;justify-content:center;align-items:center;height:100vh;margin:0;font-family:sans-serif;background:#f5f5f5"><div style="text-align:center;padding:40px;background:#fff;border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,0.1)"><h1 style="color:#F53F3F">PHP 版本过低</h1><p>CmsPro 需要 PHP 8.3.0 或更高版本，当前版本：<strong>' . PHP_VERSION . '</strong></p></div></body></html>';
    exit;
}

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

if (!file_exists(__DIR__ . '/../storage/installed.lock')) {
    $installUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')
        . '://' . $_SERVER['HTTP_HOST']
        . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\')
        . '/install.php';
    header('Location: ' . $installUrl);
    exit;
}

// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
    require $maintenance;
}

// Register the Composer autoloader...
require __DIR__.'/../vendor/autoload.php';

// Bootstrap Laravel and handle the request...
/** @var Application $app */
$app = require_once __DIR__.'/../bootstrap/app.php';

$app->handleRequest(Request::capture());
