<?php
// /elms/auth/logout.php
declare(strict_types=1);

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

unset($_SESSION['admin']);
unset($_SESSION['admin_id'], $_SESSION['admin_name'], $_SESSION['admin_role']);

unset($_SESSION['user']);
unset($_SESSION['user_id'], $_SESSION['user_name'], $_SESSION['user_role']);

unset($_SESSION['role']);
unset($_SESSION['role_code']);
unset($_SESSION['branch_id'], $_SESSION['branch_ids']);
unset($_SESSION['csrf']);
unset($_SESSION['login_failures'], $_SESSION['locked_until']);

$_SESSION = [];

if (ini_get('session.use_cookies')) {
    $params = session_get_cookie_params();

    setcookie(
        session_name(),
        '',
        time() - 42000,
        $params['path'],
        $params['domain'],
        $params['secure'],
        $params['httponly']
    );
}

session_destroy();

header('Location: /elms/auth/login.php');
exit;