<?php
require_once 'config.php';

$page_title  = 'Guest Experiences - YASH GRANDE';
$page_desc   = 'Hear from our valued guests about their luxury stay and dining experience at YASH GRANDE.';
$loader_text = 'Reading Guest Reviews';

try {
    $pdo = getConnection();
    $testimonials = $pdo->query("SELECT * FROM testimonials WHERE is_active = 1 AND status = 'approved' ORDER BY sort_order ASC, id DESC")->fetchAll();
} catch (PDOException $e) {
    $testimonials = [];
}

include 'includes/header.php';
?>

    <!-- Page Header -->
    <section class="page-header" style="background: linear-gradient(var(--overlay), var(--overlay)), url('https://images.unsplash.com/photo-1544124499-58912cbddaad?ixlib=rb-4.0.3&auto=format&fit=crop&w=2070&q=80') center/cover;">
        <div class="hero-overlay"></div>
        <div class="hero-content">
            <h1>Guest Experiences</h1>
            <p>Voices of satisfaction from those who have experienced YASH GRANDE hospitality</p>
        </div>
    </section>

    <!-- Testimonials Section -->
    <section class="section">
        <div class="section-header">
            <h2>Luxury through their eyes</h2>
            <p>Every guest stay is a unique story of comfort and elegance</p>
        </div>

        <div class="testimonials-grid">
            <?php if (!empty($testimonials)): ?>
                <?php foreach ($testimonials as $t): ?>
                    <div class="testimonial-card">
                        <?php if (!empty($t['image_path'])): ?>
                            <div class="testimonial-image" style="width: 80px; height: 80px; margin: 0 auto 1.5rem; border-radius: 50%; overflow: hidden; border: 2px solid var(--primary-gold);">
                                <img src="<?php echo htmlspecialchars($t['image_path']); ?>" alt="<?php echo htmlspecialchars($t['name']); ?>" style="width: 100%; height: 100%; object-fit: cover;">
                            </div>
                        <?php endif; ?>
                        
                        <div class="rating" style="color: var(--primary-gold); margin-bottom: 1rem; font-size: 1.2rem; text-align: center;">
                            <?php 
                            for ($i = 1; $i <= 5; $i++) {
                                if ($i <= ($t['rating'] ?? 5)) {
                                    echo '<i class="fas fa-star"></i>';
                                } else {
                                    echo '<i class="far fa-star"></i>';
                                }
                            }
                            ?>
                        </div>
                        <p class="testimonial-text" style="text-align: center;">"<?php echo htmlspecialchars($t['testimonial']); ?>"</p>
                        <div class="testimonial-author" style="text-align: center; margin-top: 1.5rem;">
                            <span style="display: block; font-weight: 700; color: var(--soft-white);"><?php echo htmlspecialchars($t['name']); ?></span>
                            <?php if (!empty($t['location'])): ?>
                                <span style="font-size: 0.9rem; color: var(--primary-gold);"><i class="fas fa-map-marker-alt" style="font-size: 0.8rem; margin-right: 0.5rem;"></i><?php echo htmlspecialchars($t['location']); ?></span>
                            <?php endif; ?>
                        </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-comments" style="font-size: 4rem; color: var(--primary-gold); margin-bottom: 1.5rem;"></i>
                    <h3 style="color: var(--soft-white); margin-bottom: 1rem;">No Testimonials Yet</h3>
                    <p style="color: var(--premium-gray); font-size: 1.1rem;">We are waiting for our guests to share their experiences. Be the first one!</p>
                </div>
            <?php endif; ?>
        </div>
    </section>

    <!-- Stats Section -->
    <section class="stats">
        <div class="stats-grid">
            <div class="stat-item"><span class="stat-number">4.9<i class="fas fa-star" style="font-size: 2rem; margin-left: 0.5rem;"></i></span><span class="stat-label">Average Rating</span></div>
            <div class="stat-item"><span class="stat-number">100%</span><span class="stat-label">Guest Satisfaction</span></div>
            <div class="stat-item"><span class="stat-number">5K+</span><span class="stat-label">Verified Reviews</span></div>
            <div class="stat-item"><span class="stat-number">24/7</span><span class="stat-label">Concierge Support</span></div>
        </div>
    </section>

    <!-- CTA Section -->
    <section class="cta">
        <h2>Experience the Excellence</h2>
        <p>Your luxury story begins here at YASH GRANDE</p>
        <a href="contact.php" class="btn-primary">Reserve Your Stay</a>
    </section>

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