
<?php
header('Content-Type: application/json; charset=utf-8');
$settingsFile = __DIR__ . '/../data/settings.json';
$settings = file_exists($settingsFile) ? json_decode((string)file_get_contents($settingsFile), true) : [];
if (!is_array($settings)) $settings = [];
if (array_key_exists('chat_enabled', $settings) && empty($settings['chat_enabled'])) { echo json_encode(['ok'=>false,'error'=>'Chat offline']); exit; }
$file = __DIR__ . '/../data/chat.json';
$data = file_exists($file) ? json_decode((string)file_get_contents($file), true) : [];
if (!is_array($data)) $data = [];
echo json_encode(['ok'=>true,'messages'=>array_slice($data, -120)]);
