<?php
//require_once __DIR__ . 'db.php';
require_once 'db.php';

//$categoryId = $_GET['category_id'] ?? 0;
$categoryId = $_GET['category_id'] ?? null;

$stmt = $pdo->prepare("SELECT r.id, r.room_number, c.price_per_night FROM rooms r JOIN room_categories c ON r.category_id = c.id WHERE r.category_id = ? AND r.status = 'available'");
$stmt->execute([$categoryId]);

if ($categoryId) {
    $stmt = $pdo->prepare("SELECT id, room_number, price FROM rooms WHERE category_id = ? AND status = 'available'");
    $stmt->execute([$categoryId]);
    echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
} else {
    echo json_encode([]);
}

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
?>

