<?php
/**
 * Admin Logout API
 * Endpoint: /admin/adminapi/logout.php
 * 
 * Invalidates the current auth token.
 */

require_once __DIR__ . '/includes/auth.php';
require_once __DIR__ . '/includes/activity_logger.php';

header('Content-Type: application/json');

$token = extractToken();

if ($token) {
    // Get admin ID before invalidating
    $adminId = validateAuthToken($token);
    
    if ($adminId) {
        logLogout($adminId);
    }
    
    invalidateToken($token);
}

echo json_encode(['success' => true, 'message' => 'Logged out']);
