<?php
declare(strict_types=1);

require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php';

function is_admin_logged_in(): bool
{
    return isset($_SESSION['admin_id']) && (int)$_SESSION['admin_id'] > 0;
}

function require_admin_login(): void
{
    if (!is_admin_logged_in()) {
        set_flash('error', 'Please login first.');
        redirect_to(admin_url('admins/login.php'));
    }
}

function current_admin_id(): int
{
    return isset($_SESSION['admin_id']) ? (int)$_SESSION['admin_id'] : 0;
}

function current_admin_name(): string
{
    return $_SESSION['admin_name'] ?? '';
}

function current_admin_username(): string
{
    return $_SESSION['admin_username'] ?? '';
}

function current_admin_role(): string
{
    return $_SESSION['admin_role'] ?? '';
}

function logout_admin(): void
{
    unset($_SESSION['admin_id']);
    unset($_SESSION['admin_name']);
    unset($_SESSION['admin_username']);
    unset($_SESSION['admin_role']);
    session_regenerate_id(true);
}
?>