<?php
echo "Test PHP: " . phpversion() . "<br>";
echo "Test Time: " . date('Y-m-d H:i:s') . "<br>";

require_once __DIR__ . '/../config.php';

$login = api_login('Widia', 'qwerty5*');
echo "Login Success: " . ($login['success'] ? 'YES' : 'NO') . "<br>";

if ($login['success']) {
    $token = $login['data']['token'];
    $berita = api_get_berita($token);
    echo "Berita Success: " . ($berita['success'] ? 'YES' : 'NO') . "<br>";
    echo "Berita Count: " . (is_array($berita['data']) ? count($berita['data']) : 'N/A') . "<br>";

    if ($berita['success'] && !empty($berita['data'])) {
        echo "Data Structure: <pre>" . print_r($berita['data'], true) . "</pre>";
        echo "Data Keys: " . implode(', ', array_keys($berita['data'])) . "<br>";

        // Try different access methods
        if (isset($berita['data'][0])) {
            $first = $berita['data'][0];
            echo "First Judul (index 0): " . ($first['judul'] ?? 'N/A') . "<br>";
        } else {
            echo "No index 0 found<br>";
            // Try to get first element
            $first = reset($berita['data']);
            echo "First Element (reset): " . ($first['judul'] ?? 'N/A') . "<br>";
        }
    }
}
