<?php
session_start();
require 'config/db.php';

$email = $_POST['email'];
$password = $_POST['password'];

$stmt = $pdo->prepare("SELECT * FROM admins WHERE email=? AND status='Active' LIMIT 1");
$stmt->execute([$email]);
$admin = $stmt->fetch();

if ($admin && password_verify($password, $admin['password'])) {

    $_SESSION['admin_id'] = $admin['id'];
    $_SESSION['admin_name'] = $admin['name'];
    $_SESSION['admin_role'] = $admin['role'];

    header("Location: index.php");
    exit;
}

$_SESSION['error'] = "Invalid login credentials";
header("Location: login.php");
