<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Setup - Qpanel</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
    <link rel="stylesheet" href="{{ url_for('static', path='/css/custom.css') }}">
    <script src="https://unpkg.com/htmx.org@1.9.12"></script>
    <style>
        body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
    </style>
</head>
<body class="bg-dark-eops">
    <div class="card" style="width: 28rem;">
        <div class="card-body p-4">
            <div class="text-center mb-4">
                <i class="bi bi-shield-lock" style="font-size: 2.5rem;"></i>
                <h3 class="mt-2">Welcome to Qpanel Setup</h3>
                <p class="text-muted">Please create a master password to secure your panel.</p>
            </div>
            
            <form id="setup-form"
                  hx-post="/api/setup"
                  hx-swap="innerHTML"
                  hx-target="#feedback"
                  hx-on::after-request="if(event.detail.successful) { setTimeout(() => window.location.href='/login', 1500) }">
                <div class="mb-3">
                    <label for="password" class="form-label">Master Password</label>
                    <input type="password" class="form-control" id="password" name="password" required autofocus>
                </div>
                 <div class="mb-3">
                    <label for="confirm_password" class="form-label">Confirm Password</label>
                    <input type="password" class="form-control" id="confirm_password" required>
                </div>
                <div id="feedback" class="mb-3"></div>
                <button type="submit" class="btn btn-primary w-100">Set Password & Start</button>
            </form>
        </div>
    </div>
    <script>
        const form = document.getElementById('setup-form');
        const password = document.getElementById('password');
        const confirm_password = document.getElementById('confirm_password');

        form.addEventListener('submit', function(e) {
            if (password.value !== confirm_password.value) {
                e.preventDefault();
                const feedback = document.getElementById('feedback');
                feedback.innerHTML = '<div class="alert alert-danger">Passwords do not match!</div>';
            }
        });
    </script>
</body>
</html>