<?php
// Public API: returns news items as JSON
header('Content-Type: application/json; charset=utf-8');
$newsFile = __DIR__ . '/data/news.json';
$news = ['enabled'=>false,'sales_item'=>[], 'items'=>[]];
if (file_exists($newsFile)) {
    $tmp = @json_decode(file_get_contents($newsFile), true);
    if (is_array($tmp)) $news = $tmp;
}
// return only items and sales_item
$out = [
    'enabled' => !empty($news['enabled']),
    'sales_item' => $news['sales_item'] ?? [],
    'items' => $news['items'] ?? []
];
echo json_encode($out, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
