<?php
// public/api/get-session.php
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../includes/ProxyHelper.php';

$proxy = new ProxyHelper();
$cookies = $proxy->getCookies();
$csrf = $proxy->getCsrfToken();

// Load active office token
$cookiesDir = __DIR__ . '/../cookies';
$officeTokenFile = $proxy->getActiveOfficeFile();
$officeToken = '';
if (file_exists($officeTokenFile)) {
    $activeToken = trim(file_get_contents($officeTokenFile));
    if ($activeToken !== '') {
        $officeToken = $proxy->getOfficeToken($activeToken);
    }
}

echo json_encode([
    'ok' => true,
    'csrf_token' => $csrf,
    'cookie_string' => $cookies,
    'data_token' => $officeToken
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
?>
