<?php
class AdminAuthMiddleware {
    public static function authenticate() {
        if (session_status() === PHP_SESSION_NONE) {
            session_start();
        }

        if (!isset($_SESSION['admin_id'])) {
            $basePath = defined('BASE_PATH') ? BASE_PATH : (str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])) === '/' ? '' : str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])));
            header('Location: ' . $basePath . '/admin?page=login');
            exit;
        }

        return true;
    }
}
