<?php
/**
 * 芋头CMS（yutoucms）
 */

session_start();

define('ROOT_PATH', dirname(__DIR__) . '/');
define('CORE_PATH', ROOT_PATH . 'core/');
define('DATA_PATH', ROOT_PATH . 'data/');

if (file_exists(DATA_PATH . 'config.php')) {
    header('Location: /admin/login.php');
    exit;
}

$step = isset($_GET['step']) ? max(1, min(4, intval($_GET['step']))) : 1;
$stepTitles = [
    1 => '环境检测',
    2 => '数据库配置',
    3 => '站点配置',
    4 => '安装完成',
];
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>芋头CMS（yutoucms）安装向导</title>
    <link rel="stylesheet" href="../public/css/install.css">
</head>
<body>
    <div class="install-shell">
        <div class="install-noise"></div>
        <div class="install-layout">
            <aside class="install-aside">
                <div class="brand-badge">yutoucms</div>
                <h1>芋头CMS</h1>
                <p class="brand-subtitle">企业建站系统安装向导</p>
                <div class="brand-card">
                    <div class="brand-card-label">当前步骤</div>
                    <div class="brand-card-title"><?php echo $stepTitles[$step]; ?></div>
                    <div class="brand-card-text">上传到虚拟主机后，访问根目录即可自动进入安装流程。</div>
                </div>
                <div class="feature-list">
                    <div class="feature-item">
                        <span class="feature-dot"></span>
                        <div>
                            <strong>示例数据恢复</strong>
                            <p>支持一键导入当前测试站点数据</p>
                        </div>
                    </div>
                    <div class="feature-item">
                        <span class="feature-dot"></span>
                        <div>
                            <strong>虚拟主机兼容</strong>
                            <p>无需扩展组件，标准 PHP + MySQL 即可安装</p>
                        </div>
                    </div>
                    <div class="feature-item">
                        <span class="feature-dot"></span>
                        <div>
                            <strong>授权控制保留</strong>
                            <p>免费版可安装，高级功能仍需授权激活</p>
                        </div>
                    </div>
                </div>
            </aside>

            <main class="install-main">
                <div class="install-main-header">
                    <div>
                        <div class="main-kicker">Installation Wizard</div>
                        <h2>芋头CMS（yutoucms）</h2>
                    </div>
                    <a class="reinstall-link" href="?reinstall=1&step=1">重新安装</a>
                </div>

                <div class="install-progress">
                    <?php foreach ($stepTitles as $index => $title): ?>
                    <div class="step <?php echo $step === $index ? 'active' : ''; ?> <?php echo $step > $index ? 'done' : ''; ?>">
                        <span class="step-num"><?php echo $index; ?></span>
                        <span class="step-name"><?php echo $title; ?></span>
                    </div>
                    <?php endforeach; ?>
                </div>

                <div class="install-body">
                    <?php
                    switch ($step) {
                        case 1:
                            include ROOT_PATH . 'install/step1.php';
                            break;
                        case 2:
                            include ROOT_PATH . 'install/step2.php';
                            break;
                        case 3:
                            include ROOT_PATH . 'install/step3.php';
                            break;
                        case 4:
                            include ROOT_PATH . 'install/step4.php';
                            break;
                    }
                    ?>
                </div>
            </main>
        </div>
    </div>
</body>
</html>
