<?php
// File: api/get_next_bel.php
header('Content-Type: application/json');
require_once '../config/database.php';

$hari = $_GET['hari'] ?? '';

if (!$hari) {
    echo json_encode(['found' => false]);
    exit;
}

$currentTime = date('H:i:s');

// Ambil jadwal berikutnya dari tabel belloto_jadwal
$stmt = $conn->prepare("SELECT * FROM belloto_jadwal WHERE hari = ? AND jam > ? AND aktif = 1 ORDER BY jam ASC LIMIT 1");
$stmt->bind_param("ss", $hari, $currentTime);
$stmt->execute();
$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {
    echo json_encode([
        'found' => true,
        'jam' => substr($row['jam'], 0, 5),
        'kegiatan' => $row['nama_kegiatan'],
        'audio_file' => $row['audio_file']
    ]);
} else {
    echo json_encode(['found' => false]);
}

$conn->close();
?>