<?php
require_once __DIR__ . '/../includes/bootstrap.php';
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');

$status = ugfx_icecast_status();
$displayListeners = max(ugfx_listener_count_fast(), (int)($status['total_listener_connections'] ?? 0), (int)($status['server_listeners'] ?? 0));

echo json_encode([
    'ok' => true,
    'listeners' => $displayListeners,
    'current_listeners' => $displayListeners,
    'active_listeners' => $displayListeners,
    'total_listener_connections' => $displayListeners,
    'mount' => (string)($status['mount'] ?? ''),
    'title' => (string)($status['title'] ?? ''),
    'is_live' => !empty($status['is_live']),
    'ts' => time(),
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
