<?php
session_start();
require_once 'config/database.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $usuario = $_POST['usuario'];
    $password = $_POST['password'];
    
    $stmt = $pdo->prepare("SELECT * FROM admin_users WHERE username = ?");
    $stmt->execute([$usuario]);
    $admin = $stmt->fetch();
    
    if ($admin && hash('sha256', $password) === $admin['password']) {
        $_SESSION['admin_usuario'] = $usuario;
        header('Location: admin/');
        exit();
    } else {
        header('Location: admin_login.php?error=1');
        exit();
    }
} else {
    header('Location: admin_login.php');
    exit();
}
?>