<?php
require_once __DIR__ . '/session.php';

$user = getCurrentUser();
if ($user) {
    try {
        // Update user status
        db()->prepare("UPDATE users SET status = 'offline' WHERE id = ?")->execute([$user['id']]);
        // Clean up DB session
        db()->prepare("DELETE FROM voice_sessions WHERE user_id = ?")->execute([$user['id']]);
    } catch (Exception $e) {
        // Ignore errors during logout cleanup
    }
}

session_destroy();
header('Location: login.php');
exit;
