<?php
ob_start();
session_start();
require_once 'config/database.php';
require_once 'includes/functions.php';
require_once 'includes/translation.php';

// Log logout activity if user is logged in
if (isset($_SESSION['user_id'])) {
    try {
        $db = new Database();
        $conn = $db->getConnection();
        
        logActivity($conn, $_SESSION['user_id'], 'تسجيل خروج');
    } catch (Exception $e) {
        // Handle error silently
        error_log("Logout error: " . $e->getMessage());
    }
}

// Destroy session
session_destroy();
ob_end_clean();

// Redirect to login page
$base_url = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\') . '/';
header('Location: ' . $base_url . 'login.php');
exit();
?>
