<?php
require_once 'config.php';

$page_title  = 'Luxury Rooms & Suites - YASH GRANDE';
$page_desc   = 'Discover our luxury accommodations at YASH GRANDE - Executive Suites, Deluxe Rooms, Family Residencies, and Premium Hostel Rooms.';
$loader_text = 'Loading Luxury Accommodations';

try {
    $pdo   = getConnection();
    $rooms = $pdo->query("SELECT * FROM rooms WHERE is_active = 1 ORDER BY sort_order ASC")->fetchAll();
} catch (PDOException $e) {
    $rooms = [];
}

include 'includes/header.php';
?>

    <!-- Page Header -->
    <section class="page-header">
        <div class="hero-overlay"></div>
        <div class="hero-content">
            <h1>Luxury Accommodations</h1>
            <p>Discover our exquisite rooms and suites designed for the ultimate comfort experience</p>
        </div>
    </section>

    <!-- Rooms Section -->
    <section class="section">
        <div class="section-header">
            <h2>Our Room Categories</h2>
            <p>Each accommodation is thoughtfully designed to provide luxury, comfort, and unforgettable experiences</p>
        </div>
        <div class="rooms-grid">
            <?php if (!empty($rooms)): ?>
                <?php foreach ($rooms as $room): ?>
                    <?php 
                    // Fetch gallery images for this room
                    $stmt = $pdo->prepare("SELECT image_path FROM room_gallery WHERE room_id = ? ORDER BY sort_order ASC");
                    $stmt->execute([$room['id']]);
                    $gallery = $stmt->fetchAll(PDO::FETCH_COLUMN);
                    // Add primary image to the start of gallery
                    array_unshift($gallery, $room['image_path']);
                    ?>
                    <div class="room-card">
                        <div class="room-image slideshow-container" data-room-id="<?php echo $room['id']; ?>">
                            <?php foreach ($gallery as $index => $img): ?>
                                <a href="room-details.php?id=<?php echo $room['id']; ?>" class="room-slide <?php echo $index === 0 ? 'active' : ''; ?>">
                                    <img src="<?php echo htmlspecialchars($img); ?>" alt="<?php echo htmlspecialchars($room['name']); ?>">
                                </a>
                            <?php endforeach; ?>
                            
                            <?php if (count($gallery) > 1): ?>
                                <div class="slideshow-dots">
                                    <?php foreach ($gallery as $index => $img): ?>
                                        <span class="dot <?php echo $index === 0 ? 'active' : ''; ?>"></span>
                                    <?php endforeach; ?>
                                </div>
                            <?php endif; ?>
                        </div>
                        <div class="room-content">
                            <h4><?php echo htmlspecialchars($room['name']); ?></h4>
                            <p><?php echo htmlspecialchars($room['description']); ?></p>
                            <a href="room-details.php?id=<?php echo $room['id']; ?>" class="btn-secondary">View Details</a>
                        </div>
                    </div>
                <?php endforeach; ?> <?php else: ?>
                <div class="empty-state" style="grid-column: 1/-1; text-align: center; padding: 5rem 2rem;">
                    <i class="fas fa-bed" style="font-size: 4rem; color: var(--primary-gold); margin-bottom: 1.5rem;"></i>
                    <h3 style="color: var(--soft-white); margin-bottom: 1rem;">No Rooms Available</h3>
                    <p style="color: var(--premium-gray); font-size: 1.1rem; margin-bottom: 2rem;">We're currently updating our room listings. Please contact us directly for availability and reservations.</p>
                    <a href="contact.php" class="btn-primary">Contact Us</a>
                </div>
            <?php endif; ?>
        </div>
    </section>

    <!-- Room Features Section -->
    <section class="section">
        <div class="section-header">
            <h2>Premium Room Features</h2>
            <p>Every room includes these luxury amenities and services</p>
        </div>
        <div class="features-grid">
            <div class="feature-card"><i class="fas fa-wifi"></i><h4>High-Speed WiFi</h4><p>Complimentary high-speed internet access throughout your stay for seamless connectivity.</p></div>
            <div class="feature-card"><i class="fas fa-tv"></i><h4>Smart Entertainment</h4><p>55" Smart TV with premium channels, streaming services, and personalized entertainment options.</p></div>
            <div class="feature-card"><i class="fas fa-snowflake"></i><h4>Climate Control</h4><p>Individual climate control systems ensuring perfect temperature and comfort year-round.</p></div>
            <div class="feature-card"><i class="fas fa-coffee"></i><h4>Premium Minibar</h4><p>Curated selection of premium beverages, snacks, and local specialties available 24/7.</p></div>
            <div class="feature-card"><i class="fas fa-bath"></i><h4>Luxury Bathroom</h4><p>Marble bathrooms with rain showers, premium toiletries, and plush towels and robes.</p></div>
            <div class="feature-card"><i class="fas fa-concierge-bell"></i><h4>24/7 Room Service</h4><p>Round-the-clock room service featuring our restaurant's signature dishes and beverages.</p></div>
        </div>
    </section>

    <!-- CTA -->
    <section class="cta">
        <h2>Reserve Your Perfect Stay</h2>
        <p>Experience luxury accommodations tailored to your preferences and needs</p>
        <a href="contact.php" class="btn-primary">Check Availability</a>
    </section>

<?php include 'includes/footer.php'; ?>
