<?php
/**
 * Logout - clear session and redirect
 */

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

$role = $_SESSION['role'] ?? '';
$mobileParam = isset($_GET['mobile']) ? strtolower(trim((string)$_GET['mobile'])) : '';
$fromMobileUi = $mobileParam !== '' && $mobileParam !== '0' && $mobileParam !== 'false';
// Field team uses the mobile app; after logout, home (/) is blocked on phones — send them to mobile login.
$redirectMobileLogin = ($role === 'data_collector') || $fromMobileUi;

logout();

header('Location: ' . ($redirectMobileLogin ? BASE_PATH . '/mobile/login' : BASE_PATH . '/'));
exit;
