<?php
/**
 * 首页 fallback
 * - 如果 index.html 存在（已生成静态页），直接跳转
 * - 如果不存在（首次部署/未生成），显示提示页引导去后台
 */
declare(strict_types=1);

$htmlFile = __DIR__ . '/index.html';

if (is_file($htmlFile) && is_readable($htmlFile)) {
    // 已生成静态首页，直接输出（保留 SEO 友好性）
    header('Content-Type: text/html; charset=UTF-8');
    readfile($htmlFile);
    exit;
}

// 静态页未生成，显示提示页
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$adminUrl = $protocol . '://' . $host . '/admin_x9k2m7/';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex,nofollow">
<title>网站初始化中 - 美硕智能装备</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #f3f4f6; color: #1a1a2e; }
.box { background: #fff; padding: 48px; border-radius: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); max-width: 480px; text-align: center; }
.icon { width: 64px; height: 64px; background: #c0392b; border-radius: 16px; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; color: #fff; font-weight: 700; font-size: 20px; }
h1 { font-size: 22px; margin-bottom: 12px; }
p { color: #6b7280; line-height: 1.7; margin-bottom: 20px; font-size: 14px; }
.steps { text-align: left; background: #f9fafb; padding: 16px 20px; border-radius: 8px; margin: 20px 0; font-size: 13px; color: #374151; line-height: 1.8; }
.steps ol { padding-left: 20px; }
.btn { display: inline-block; padding: 12px 28px; background: #c0392b; color: #fff; text-decoration: none; border-radius: 8px; font-weight: 600; margin-top: 12px; }
.btn:hover { background: #a93226; }
.hint { font-size: 12px; color: #9ca3af; margin-top: 16px; }
</style>
</head>
<body>
<div class="box">
    <div class="icon">MS</div>
    <h1>网站初始化中</h1>
    <p>前台静态页面尚未生成，请先登录后台生成。</p>
    <div class="steps">
        <strong>📋 操作步骤：</strong>
        <ol>
            <li>点击下方按钮登录管理后台</li>
            <li>使用默认账号 <code>admin</code> / <code>admin</code></li>
            <li>进入「重新生成静态页」</li>
            <li>点击「立即生成」按钮</li>
            <li>返回本页刷新即可看到网站</li>
        </ol>
    </div>
    <a href="<?= htmlspecialchars($adminUrl, ENT_QUOTES, 'UTF-8') ?>" class="btn">→ 进入管理后台</a>
    <p class="hint">⚠️ 首次登录后请立即在「站点设置」中修改默认密码</p>
</div>
</body>
</html>
