<?php
require_once __DIR__ . '/../../helpers/TurnstileHelper.php';
$turnstileHelper = new TurnstileHelper();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login - <?= htmlspecialchars($settings['site_title'] ?? 'Admin Panel') ?></title>
    <?php if (isset($settings['favicon_path']) && !empty($settings['favicon_path'])): ?>
    <link rel="icon" href="<?= htmlspecialchars($settings['favicon_path']) ?>" type="image/x-icon">
    <link rel="shortcut icon" href="<?= htmlspecialchars($settings['favicon_path']) ?>" type="image/x-icon">
    <?php endif; ?>

    <!-- Locally built Tailwind CSS -->
    <link rel="stylesheet" href="/public/css/styles.css">
    <link rel="stylesheet" href="/public/css/admin.css">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">

    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background-color: #0f172a;
        }
    </style>
</head>
<body class="bg-darker text-white min-h-screen flex items-center justify-center">
    <div class="login-container">
        <div class="login-header">
            <?php if (isset($settings['logo_path']) && !empty($settings['logo_path'])): ?>
                <div class="logo-container">
                    <img src="<?= htmlspecialchars($settings['logo_path']) ?>" alt="<?= htmlspecialchars($settings['site_title'] ?? 'Site Logo') ?>" class="h-16 max-w-full" onerror="this.src='https://placehold.co/200x80/0F172A/2C7BE5?text=Admin+Panel&font=Poppins'">
                </div>
            <?php endif; ?>
            <h1 class="text-xl font-semibold mt-4 mb-2">Admin Login</h1>
            <p class="text-gray-400 text-sm">Enter your credentials to access the admin panel of <?= htmlspecialchars($settings['site_title'] ?? 'the site') ?></p>
        </div>

        <?php if (!empty($error)): ?>
            <div class="bg-red-900 text-white p-3 rounded-md mb-4 text-sm">
                <i class="fas fa-exclamation-circle mr-2"></i><?= $error ?>
            </div>
        <?php endif; ?>

        <form class="login-form" method="POST" action="/admin/login">
            <div class="mb-4">
                <input type="email" name="email" placeholder="Email" required>
            </div>
            <div class="mb-4">
                <input type="password" name="password" placeholder="Password" required>
            </div>
            <div class="remember-me">
                <input type="checkbox" name="remember_me" id="remember_me">
                <label for="remember_me" class="text-gray-300 text-sm">Remember me</label>
            </div>

            <?php if ($turnstileHelper->isEnabled()): ?>
            <?= $turnstileHelper->renderWidget() ?>
            <?php endif; ?>

            <button type="submit" class="login-button">
                <i class="fas fa-sign-in-alt mr-2"></i> Login
            </button>

            <div class="mt-4 text-center">
                <a href="/" class="text-primary text-sm hover:underline">
                    <i class="fas fa-arrow-left mr-1"></i> Back to site
                </a>
            </div>
        </form>
    </div>
</body>
</html>