<?php
/* ============================================================
   POST api/logout.php  →  إنهاء الجلسة
   ============================================================ */

declare(strict_types=1);
require __DIR__ . '/bootstrap.php';
require __DIR__ . '/helpers.php';

exp_start_session($CONFIG);
exp_require_post();
exp_check_origin();

$_SESSION = [];
if (ini_get('session.use_cookies')) {
  $p = session_get_cookie_params();
  setcookie(session_name(), '', [
    'expires'  => time() - 42000,
    'path'     => $p['path'],
    'domain'   => $p['domain'],
    'secure'   => $p['secure'],
    'httponly' => $p['httponly'],
    'samesite' => 'Strict',
  ]);
}
session_destroy();

exp_json(['ok' => true]);
