<?php
require_once __DIR__ . '/../includes/bootstrap.php';
header('Content-Type: application/json');

$status = ugfx_chat_public_status();
if (!$status['enabled']) {
    echo json_encode([
        'ok' => false,
        'messages' => [],
        'disabled' => true,
        'message' => $status['message'],
        'meta' => ['server_time' => date('c')],
    ], JSON_UNESCAPED_SLASHES);
    exit;
}

$messages = ugfx_chat_messages(150);
echo json_encode([
    'ok' => true,
    'messages' => $messages,
    'meta' => [
        'server_time' => date('c'),
    ],
], JSON_UNESCAPED_SLASHES);
