<?php
/**
 * Admin Dedicated Login Page
 * Path: admin/login.php
 */

session_start();

require_once '../config.php';
require_once '../function.php';

$site_name = get_site_setting('site_name');
$site_logo = get_site_logo(true);

// ইউজার যদি অলরেডি লগইন করা থাকে, তবে তাকে সরাসরি ইনডেক্স ড্যাশবোর্ডে পাঠিয়ে দেবে
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
    header('Location: index.php');
    exit;
}

$login_error = '';

// লগইন রিকোয়েস্ট সাবমিশন হ্যান্ডলিং (DB password → fallback admin123)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'admin_login') {
    $password = isset($_POST['password']) ? trim($_POST['password']) : '';

    if (verify_admin_password($password)) {
        $_SESSION['admin_logged_in'] = true;
        header('Location: index.php');
        exit;
    } else {
        $login_error = "ভুল পাসওয়ার্ড! অনুগ্রহ করে আবার চেষ্টা করুন।";
    }
}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Secure Login - Admin Panel</title>
    <!-- Tailwind CSS & FontAwesome -->
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-slate-950 flex flex-col justify-between min-h-screen text-slate-100">

    <!-- Top Empty space for centering -->
    <div class="flex-1 flex items-center justify-center p-4">
        
        <div class="w-full max-w-md bg-slate-900 border border-slate-800/80 rounded-3xl p-8 shadow-2xl relative overflow-hidden">
            <!-- Decorative gradient blur -->
            <div class="absolute -top-12 -right-12 w-24 h-24 bg-sky-500/10 rounded-full blur-2xl"></div>
            
            <div class="text-center mb-8">
                <!-- Round shape Logo of client -->
                <img class="w-16 h-16 rounded-full object-cover mx-auto border-2 border-sky-500/30 mb-4 shadow-lg shadow-sky-500/5" src="<?php echo htmlspecialchars($site_logo); ?>" alt="Company Logo">
                <h1 class="text-lg font-black text-sky-400 uppercase tracking-widest"><?php echo htmlspecialchars($site_name); ?></h1>
                <p class="text-xs text-slate-500 uppercase tracking-widest font-bold mt-1">Management Portal</p>
            </div>

            <!-- Login Error Alerts -->
            <?php if (!empty($login_error)): ?>
                <div class="mb-6 p-4 bg-red-950/40 border border-red-800/80 text-red-200 text-xs rounded-xl flex items-center">
                    <i class="fa-solid fa-triangle-exclamation mr-3 text-sm"></i>
                    <?php echo htmlspecialchars($login_error); ?>
                </div>
            <?php endif; ?>

            <!-- Login Form -->
            <form method="post" action="" class="space-y-5">
                <input type="hidden" name="action" value="admin_login">
                
                <div>
                    <label class="block text-xs font-black uppercase text-slate-400 tracking-wider mb-2">পাসওয়ার্ড লিখুন</label>
                    <div class="relative">
                        <span class="absolute inset-y-0 left-0 pl-4 flex items-center text-slate-500"><i class="fa-solid fa-lock"></i></span>
                        <input type="password" name="password" placeholder="Enter admin password" required class="w-full bg-slate-950/80 border border-slate-800/80 rounded-xl pl-11 pr-4 py-3.5 text-sm text-slate-100 focus:outline-none focus:ring-2 focus:ring-sky-500/80 transition-all placeholder-slate-600">
                    </div>
                </div>

                <button type="submit" class="w-full bg-sky-500 hover:bg-sky-600 text-slate-950 font-black py-4 rounded-xl transition-all shadow-lg hover:shadow-sky-500/10 text-xs uppercase tracking-wider flex items-center justify-center">
                    লগইন করুন <i class="fa-solid fa-right-to-bracket ml-2"></i>
                </button>
            </form>
        </div>

    </div>

    <!-- Mini Bottom Footer -->
    <footer class="py-6 text-center text-[10px] text-slate-600 uppercase tracking-widest border-t border-slate-900/60">
        <p>&copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars($site_name); ?>. Secure Console.</p>
    </footer>

</body>
</html>