<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/core/bootstrap.php';

audit_log('logout', 'users', isset($_SESSION['admin_id']) ? (int) $_SESSION['admin_id'] : null);
admin_clear_auth_cookie();
$_SESSION = [];

if (ini_get('session.use_cookies')) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', [
        'expires' => time() - 3600,
        'path' => $params['path'] ?: '/',
        'domain' => $params['domain'] ?: '',
        'secure' => (bool) $params['secure'],
        'httponly' => (bool) $params['httponly'],
        'samesite' => 'Lax',
    ]);
}

session_destroy();
redirect('/admin/login.php');
