<?php $assetBase =
    basename(rtrim(FCPATH, "\\/")) === "public"
        ? "assets/"
        : "public/assets/"; ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= $mode === "setup"
        ? "Create admin account"
        : "Admin sign in" ?> · BrandSquare</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= base_url($assetBase . "css/admin.css") ?>">
</head>
<body class="auth-page">
    <main class="auth-shell">
        <section class="auth-brand">
            <a href="<?= base_url() ?>" class="admin-logo">Brand<span>Square.</span></a>
            <div>
                <span class="auth-kicker">Brand management</span>
                <h1><?= $mode === "setup"
                    ? "Your private control room."
                    : "Welcome back." ?></h1>
                <p>Manage enquiries, contact details, and email delivery from one focused workspace.</p>
            </div>
            <small>Secure · Private · Built for BrandSquare</small>
        </section>
        <section class="auth-form-wrap">
            <form method="post" class="auth-form">
                <?= csrf_field() ?>
                <span class="auth-step"><?= $mode === "setup"
                    ? "One-time setup"
                    : "Admin access" ?></span>
                <h2><?= $mode === "setup"
                    ? "Create the first admin"
                    : "Sign in to continue" ?></h2>
                <p><?= $mode === "setup"
                    ? "This setup page closes automatically after your account is created."
                    : "Use your BrandSquare administrator account." ?></p>

                <?php if (session("error")): ?>
                    <div class="alert error"><?= esc(session("error")) ?></div>
                <?php endif; ?>
                <?php if (session("success")): ?>
                    <div class="alert success"><?= esc(
                        session("success"),
                    ) ?></div>
                <?php endif; ?>
                <?php if (!empty($errors)): ?>
                    <div class="alert error"><?= esc(
                        implode(" ", $errors),
                    ) ?></div>
                <?php endif; ?>

                <?php if ($mode === "setup"): ?>
                    <label>Your name<input name="name" required value="<?= esc(
                        old("name"),
                    ) ?>" autocomplete="name"></label>
                <?php endif; ?>
                <label>Email address<input name="email" type="email" required value="<?= esc(
                    old("email"),
                ) ?>" autocomplete="email"></label>
                <label>Password<input name="password" type="password" required minlength="<?= $mode ===
                "setup"
                    ? "12"
                    : "1" ?>" autocomplete="<?= $mode === "setup"
    ? "new-password"
    : "current-password" ?>"></label>
                <?php if ($mode === "setup"): ?>
                    <label>Confirm password<input name="password_confirm" type="password" required minlength="12" autocomplete="new-password"></label>
                    <small class="password-note">Use at least 12 characters. A password manager is recommended.</small>
                <?php endif; ?>
                <button type="submit"><?= $mode === "setup"
                    ? "Create admin account"
                    : "Sign in" ?> <span>→</span></button>
                <a class="back-link" href="<?= base_url() ?>">← Back to website</a>
            </form>
        </section>
    </main>
</body>
</html>
