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

require_once "config.php";

try {
    $stmt = $pdo->prepare("
        SELECT 
            id,
            hotel_id,
            hotel_name,
            location,
            description,
            logo
        FROM hotels
        WHERE status = 'active'
        ORDER BY hotel_name ASC
    ");

    $stmt->execute();
    $hotels = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode([
        "status" => true,
        "count" => count($hotels),
        "hotels" => $hotels
    ]);

} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode([
        "status" => false,
        "message" => "Failed to fetch hotels"
    ]);
}
