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

echo "<h2>Debug Presensi Data</h2>";

// Login dulu
$login_result = api_login('Widia', 'qwerty5*');
if ($login_result['success']) {
    $token = $login_result['data']['token'];
    $_SESSION['token'] = $token;
    $_SESSION['user_data'] = $login_result['data'];

    // Get presensi today
    $presensi_today_result = api_get_presensi_today($token);
    $presensi_today = $presensi_today_result['success'] ? $presensi_today_result['data'] : [];

    echo "<h3>Raw Presensi Today Response:</h3>";
    echo "<pre>" . json_encode($presensi_today, JSON_PRETTY_PRINT) . "</pre>";

    echo "<h3>Extracted Data:</h3>";
    $presensi_data_today = $presensi_today['data'] ?? [];
    $masuk_time = $presensi_data_today['jam_masuk'] ?? null;
    $istirahat_mulai = $presensi_data_today['mulai_istirahat'] ?? null;
    $istirahat_selesai = $presensi_data_today['beres_istirahat'] ?? null;
    $pulang_time = $presensi_data_today['jam_pulang'] ?? null;

    echo "masuk_time: " . var_export($masuk_time, true) . "<br>";
    echo "istirahat_mulai: " . var_export($istirahat_mulai, true) . "<br>";
    echo "istirahat_selesai: " . var_export($istirahat_selesai, true) . "<br>";
    echo "pulang_time: " . var_export($pulang_time, true) . "<br>";

    echo "<h3>Status Check:</h3>";
    echo "Masuk sudah rekam: " . (($masuk_time && $masuk_time !== '00:00' && $masuk_time !== null) ? 'YES' : 'NO') . "<br>";
    echo "Istirahat sudah rekam: " . (($istirahat_mulai && $istirahat_mulai !== '00:00' && $istirahat_mulai !== null) ? 'YES' : 'NO') . "<br>";
    echo "Pulang sudah rekam: " . (($pulang_time && $pulang_time !== '00:00' && $pulang_time !== null) ? 'YES' : 'NO') . "<br>";
} else {
    echo "Login gagal: " . json_encode($login_result['data']);
}
