<?php
require_once __DIR__ . '/../app/helpers.php';
require_once __DIR__ . '/../app/db.php';
require_once __DIR__ . '/../app/audit.php';
session_start();
$uid = (int)($_SESSION['user_id'] ?? 0);
$cid = (int)($_SESSION['company_id'] ?? 0);
if ($uid > 0 || $cid > 0) {
  try {
    $pdo = db();
    audit_log($pdo, ['company_id'=>$cid ?: null,'user_id'=>$uid ?: null,'module'=>'auth','action'=>'LOGOUT','entity_type'=>'user','entity_id'=>$uid > 0 ? (string)$uid : null,'description'=>'تسجيل خروج']);
  } catch (Throwable $e) {}
}
session_destroy();
header("Location: " . url("/auth/login.php"));
exit;
