<?php
session_start();
require_once __DIR__ . '/../config.php';

echo "<h2>Quick Test</h2>";

// Cek token
$token = $_SESSION['token'] ?? '';
echo "Token: " . ($token ? substr($token, 0, 20) . "..." : "TIDAK ADA") . "<br>";

if (empty($token)) {
    echo "<p style='color:red'>Token tidak ada, coba login dulu</p>";
    echo "<a href='login.php'>Login</a>";
    exit;
}

// Test API berita
echo "<h3>Test API Berita:</h3>";
$result = api_get_berita($token);

echo "<pre>";
echo "Success: " . ($result['success'] ? 'YES' : 'NO') . "\n";
echo "HTTP Code: " . $result['http_code'] . "\n";
echo "Response: " . substr($result['raw_response'], 0, 300) . "...\n";
echo "</pre>";

if ($result['success'] && !empty($result['data']['data'])) {
    echo "<p style='color:green'>✅ Berita ditemukan: " . count($result['data']['data']) . " item</p>";

    foreach (array_slice($result['data']['data'], 0, 2) as $item) {
        echo "<div style='border:1px solid #ccc;padding:10px;margin:5px 0;'>";
        echo "<h4>📅 " . htmlspecialchars($item['tanggal'] ?? '') . " — " . htmlspecialchars($item['judul'] ?? '') . "</h4>";
        echo "<p>" . nl2br(htmlspecialchars($item['isi'] ?? '')) . "</p>";
        echo "</div>";
    }
} else {
    echo "<p style='color:red'>❌ Berita tidak ditemukan</p>";
}
