<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type");

require_once "../config/database.php";

try {
     = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS);
    ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

     = ->prepare("
        SELECT * FROM tatkal_appointments 
        ORDER BY appointment_date DESC, time_slot ASC
    ");
    ->execute();
     = ->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode([
        "success" => true,
        "appointments" => 
    ]);

} catch (Exception ) {
    echo json_encode([
        "success" => false,
        "message" => "Error: " . ->getMessage()
    ]);
}
?>
