<?php
// ডাটাবেস এবং সেশন লোড
require_once '../config/database.php';

// আগে থেকে লগইন থাকলে সরাসরি ড্যাশবোর্ডে পাঠিয়ে দেবে
if(isset($_SESSION['is_admin_logged_in']) && $_SESSION['is_admin_logged_in'] === true) {
    header("Location: dashboard.php");
    exit();
}

$error_msg = '';

// ফর্ম সাবমিট হলে এই ফাইলেই ডাইরেক্ট প্রসেস হবে
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    
    // 🔥 ডাইরেক্ট লগইন (আপাতত ক্লিক করলেই ড্যাশবোর্ডে নিয়ে যাবে)
    $_SESSION['is_admin_logged_in'] = true;
    header("Location: dashboard.php");
    exit();

    /* 
    ===================================================================
    পরবর্তীতে আসল ডাটাবেস লগইন চালু করতে চাইলে উপরের ৩ লাইন মুছে নিচের কোডগুলো আনকমেন্ট করে দিবেন:
    ===================================================================
    $email = $_POST['email'];
    $password = $_POST['password'];

    $stmt = $db->prepare("SELECT * FROM admins WHERE email = :email LIMIT 1");
    $stmt->execute(['email' => $email]);
    $admin = $stmt->fetch();

    if ($admin && password_verify($password, $admin['password'])) {
        $_SESSION['is_admin_logged_in'] = true;
        header("Location: dashboard.php");
        exit();
    } else {
        $error_msg = "Invalid Email or Password!";
    }
    */
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login - Plexio IT</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- FontAwesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        :root { --primary-blue: #0147C9; }
        body {
            background-color: #f0f4f8;
            background-image: radial-gradient(circle at top right, rgba(1, 71, 201, 0.1), transparent 500px),
                              radial-gradient(circle at bottom left, rgba(1, 71, 201, 0.05), transparent 400px);
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
        }
        
        .glass-card {
            background: rgba(255, 255, 255, 0.85);
            backdrop-filter: blur(15px);
            -webkit-backdrop-filter: blur(15px);
            border: 1px solid rgba(255, 255, 255, 0.6);
            border-radius: 16px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.05);
            width: 100%;
            max-width: 420px;
            padding: 40px 30px;
        }
        
        .brand-logo { text-align: center; margin-bottom: 30px; }
        .brand-logo h2 { color: var(--primary-blue); font-weight: 800; letter-spacing: 0.5px; }
        
        .form-control {
            background: rgba(255, 255, 255, 0.9);
            border: 1px solid rgba(0, 0, 0, 0.08);
            padding: 12px 15px;
            box-shadow: none;
        }
        .form-control:focus {
            border-color: var(--primary-blue);
            box-shadow: 0 0 0 0.25rem rgba(1, 71, 201, 0.15);
        }
        .input-group-text {
            background: rgba(255, 255, 255, 0.9);
            border: 1px solid rgba(0, 0, 0, 0.08);
            color: #888;
        }
        
        .btn-primary {
            background-color: var(--primary-blue);
            border: none;
            padding: 12px;
            border-radius: 8px;
            font-weight: 600;
            letter-spacing: 0.5px;
            transition: all 0.3s;
        }
        .btn-primary:hover {
            background-color: #013699;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(1, 71, 201, 0.3);
        }
    </style>
</head>
<body>

    <div class="glass-card">
        <div class="brand-logo">
            <h2><i class="fas fa-server"></i> Plexio IT</h2>
            <p class="text-muted mb-0" style="font-size: 14px;">Secure Admin Access</p>
        </div>
        
        <?php
        // এরর মেসেজ দেখানোর অপশন
        if(!empty($error_msg)) {
            echo '<div class="alert alert-danger py-2 text-center border-0 shadow-sm" style="font-size: 14px;"><i class="fas fa-exclamation-circle me-1"></i> '.$error_msg.'</div>';
        }
        ?>

        <!-- action="" মানে একই পেজে সাবমিট হবে -->
        <form action="" method="POST">
            <div class="mb-3">
                <label class="form-label text-muted fw-semibold" style="font-size: 13px; text-transform: uppercase; letter-spacing: 1px;">Email Address</label>
                <div class="input-group">
                    <span class="input-group-text border-end-0"><i class="fas fa-envelope"></i></span>
                    <input type="email" name="email" class="form-control border-start-0 ps-0" placeholder="admin@plexioit.com" required>
                </div>
            </div>
            
            <div class="mb-4">
                <label class="form-label text-muted fw-semibold" style="font-size: 13px; text-transform: uppercase; letter-spacing: 1px;">Password</label>
                <div class="input-group">
                    <span class="input-group-text border-end-0"><i class="fas fa-lock"></i></span>
                    <input type="password" name="password" class="form-control border-start-0 ps-0" placeholder="••••••••" required>
                </div>
            </div>
            
            <button type="submit" class="btn btn-primary w-100 mt-2"><i class="fas fa-sign-in-alt me-2"></i> Login</button>
        </form>
    </div>

</body>
</html>