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

// Check if user is logged in
if (!isset($_SESSION['token'])) {
    echo "Token not found. Please login first.";
    exit;
}

$token = $_SESSION['token'];

echo "<h1>Debug Lembur Data</h1>";
echo "<p>Token: " . substr($token, 0, 20) . "...</p>";

// Get lembur data
$lembur_result = api_get_lembur($token);
echo "<h2>API Result:</h2>";
echo "<pre>";
print_r($lembur_result);
echo "</pre>";

$lembur_data = $lembur_result['success'] ? $lembur_result['data'] : [];

echo "<h2>Lembur Data:</h2>";
echo "<pre>";
print_r($lembur_data);
echo "</pre>";

echo "<h2>Data Analysis:</h2>";
echo "<p>Success: " . ($lembur_result['success'] ? 'YES' : 'NO') . "</p>";
echo "<p>HTTP Code: " . $lembur_result['http_code'] . "</p>";
echo "<p>Data empty: " . (empty($lembur_data) ? 'YES' : 'NO') . "</p>";
echo "<p>Data is array: " . (is_array($lembur_data) ? 'YES' : 'NO') . "</p>";

if (is_array($lembur_data)) {
    echo "<p>Data count: " . count($lembur_data) . "</p>";

    if (isset($lembur_data['data'])) {
        echo "<p>Data['data'] is array: " . (is_array($lembur_data['data']) ? 'YES' : 'NO') . "</p>";
        if (is_array($lembur_data['data'])) {
            echo "<p>Data['data'] count: " . count($lembur_data['data']) . "</p>";
        }
    }
}
