<?php
require_once __DIR__ . '/includes/header.php';

$pdo = db();
// Get hot deals
$hotDeals = $pdo->query("SELECT c.*, ci.image_path FROM cars c LEFT JOIN car_images ci ON c.id = ci.car_id AND ci.is_main = 1 WHERE c.is_hot_deal = 1 AND c.status = 'approved' LIMIT 6")->fetchAll();

$testimonials = [
    [
        'name' => 'Ahmad Wali',
        'city' => 'Kabul',
        'text' => 'Found my dream Land Cruiser here. The process was smooth and the seller was very professional. Highly recommended for premium cars in Afghanistan!',
        'rating' => 5
    ],
    [
        'name' => 'Mariam Sadat',
        'city' => 'Herat',
        'text' => 'As a first-time car buyer, I felt very safe using AfgCars. The verified listings give me peace of mind. Excellent service!',
        'rating' => 5
    ],
    [
        'name' => 'Zubair Khan',
        'city' => 'Mazar-i-Sharif',
        'text' => 'The best marketplace in the country. Clean interface and very easy to contact sellers. Sold my Corolla within 3 days!',
        'rating' => 4
    ]
];
?>

<section class="hero" style="background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)), url('assets/images/hero-home.jpg') center/cover no-repeat fixed;">
    <div style="z-index: 2; position: relative;">
        <h1>Find Your Premium Ride</h1>
        <p>Exclusive luxury vehicles and reliable everyday cars in Afghanistan's most trusted marketplace.</p>
        <div style="display: flex; gap: 1.5rem; justify-content: center;">
            <a href="cars.php" class="btn btn-primary">View Marketplace</a>
            <?php if (!isset($_SESSION['user_id'])): ?>
                <a href="register.php" class="btn btn-outline">Start Selling</a>
            <?php else: ?>
                <a href="dashboard.php" class="btn btn-outline">My Account</a>
            <?php endif; ?>
        </div>
    </div>
</section>

<div class="container">
    <h2 class="section-title">Hot Deals</h2>
    <div class="grid">
        <?php foreach ($hotDeals as $car): ?>
            <div class="car-card glass">
                <div class="car-img-container" style="overflow: hidden; height: 240px; border-bottom: 1px solid var(--glass-border);">
                    <div class="car-img" style="background-image: url('<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>'); background-size: cover; background-position: center; height: 100%;"></div>
                </div>
                <div class="car-info">
                    <div class="car-meta">
                        <span>📅 <?= htmlspecialchars($car['year']) ?></span>
                        <span>📍 <?= htmlspecialchars($car['city']) ?></span>
                    </div>
                    <h3><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
                    <div class="car-price">$<?= number_format($car['price']) ?></div>
                    <a href="car_detail.php?id=<?= $car['id'] ?>" class="btn btn-outline" style="width: 100%; text-align: center;">View Details</a>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<section style="background: rgba(212, 175, 55, 0.03); padding: 8rem 0;">
    <div class="container">
        <h2 class="section-title">What Our Clients Say</h2>
        <div class="grid">
            <?php foreach ($testimonials as $t): ?>
                <div class="box">
                    <div class="review-stars" style="color: var(--primary-color); margin-bottom: 1.5rem;">
                        <?php for($i=0; $i<$t['rating']; $i++) echo '★'; ?>
                    </div>
                    <p style="font-style: italic; color: var(--text-secondary); line-height: 1.8; margin-bottom: 2rem;">"<?= htmlspecialchars($t['text']) ?>"</p>
                    <div class="review-author" style="display: flex; align-items: center; gap: 1rem;">
                        <div style="width: 45px; height: 45px; background: var(--primary-color); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #000;">
                            <?= substr($t['name'], 0, 1) ?>
                        </div>
                        <div>
                            <h4 style="margin: 0; font-size: 1rem;"><?= htmlspecialchars($t['name']) ?></h4>
                            <p style="margin: 0; font-size: 0.8rem; color: var(--text-secondary);"><?= htmlspecialchars($t['city']) ?></p>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<div class="container">
    <h2 class="section-title">Our Physical Showrooms</h2>
    <div class="grid">
        <div class="box" style="text-align: center;">
            <div style="font-size: 3rem; margin-bottom: 1.5rem;">📍</div>
            <h3>Kabul HQ</h3>
            <p style="color: var(--text-secondary); margin-bottom: 1rem;">Wazir Akbar Khan, Street 15</p>
            <p style="font-weight: 700; color: var(--primary-color); font-size: 1.1rem;">+93 700 123 456</p>
        </div>
        <div class="box" style="text-align: center;">
            <div style="font-size: 3rem; margin-bottom: 1.5rem;">📍</div>
            <h3>Herat Branch</h3>
            <p style="color: var(--text-secondary); margin-bottom: 1rem;">Jada-e-Main, Near Blue Mosque</p>
            <p style="font-weight: 700; color: var(--primary-color); font-size: 1.1rem;">+93 700 987 654</p>
        </div>
        <div class="box" style="text-align: center;">
            <div style="font-size: 3rem; margin-bottom: 1.5rem;">📍</div>
            <h3>Mazar-i-Sharif</h3>
            <p style="color: var(--text-secondary); margin-bottom: 1rem;">Balkh Gate Road</p>
            <p style="font-weight: 700; color: var(--primary-color); font-size: 1.1rem;">+93 700 456 789</p>
        </div>
    </div>
</div>

<div class="container" style="text-align: center; margin-bottom: 4rem;">
    <div class="box" style="padding: 6rem 3rem; background: linear-gradient(135deg, rgba(212, 175, 55, 0.08), transparent);">
        <h2 style="font-size: 3rem; margin-bottom: 1.5rem; font-weight: 900;">Ready to sell your car?</h2>
        <p style="color: var(--text-secondary); margin-bottom: 3rem; max-width: 600px; margin-left: auto; margin-right: auto; font-size: 1.1rem;">Join thousands of Afghans who have successfully sold their vehicles through our platform. No hidden fees, just results.</p>
        <a href="register.php" class="btn btn-primary" style="padding: 1.2rem 3rem;">Start Listing Now</a>
    </div>
</div>

<?php require_once __DIR__ . '/includes/footer.php'; ?>