<?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(15, 23, 42, 0.85), rgba(15, 23, 42, 0.85)), url('assets/images/hero-home.jpg') center/cover no-repeat fixed;">
    <div style="z-index: 2; position: relative;">
        <h1 class="fw-black" style="color: #ffffff; font-size: 5.5rem; letter-spacing: -3px; line-height: 1;">Find Your Premium Ride</h1>
        <p class="text-secondary mt-2 mb-3" style="font-size: 1.4rem; max-width: 800px; margin-left: auto; margin-right: auto; font-weight: 500;">Afghanistan's most trusted elite automotive marketplace. Where luxury meets reliability.</p>
        <div class="flex justify-center gap-1">
            <a href="cars.php" class="btn btn-primary btn-lg fw-black">View Marketplace</a>
            <?php if (!isset($_SESSION['user_id'])): ?>
                <a href="register.php" class="btn btn-outline btn-lg fw-black">Start Selling Today</a>
            <?php else: ?>
                <a href="dashboard.php" class="btn btn-outline btn-lg fw-black">Access My Portal</a>
            <?php endif; ?>
        </div>
    </div>
</section>

<div class="container" style="padding: 8rem 0;">
    <h2 class="section-title justify-center mb-4" style="font-size: 3.5rem;">🔥 Current Hot Deals</h2>
    <div class="grid grid-3 mt-3">
        <?php foreach ($hotDeals as $car): ?>
            <div class="card">
                <div style="overflow: hidden; height: 260px; border-bottom: 1px solid var(--glass-border); position: relative;">
                    <img src="<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>" class="w-full" style="height: 100%; object-fit: cover;">
                    <span class="badge badge-danger" style="position: absolute; top: 1.5rem; left: 1.5rem; z-index: 5;">Hot Deal</span>
                </div>
                <div class="card-content">
                    <div class="flex gap-1 text-secondary text-sm fw-black mb-1" style="text-transform: uppercase; letter-spacing: 1px;">
                        <span>📅 <?= htmlspecialchars($car['year']) ?> Model</span>
                        <span>📍 <?= htmlspecialchars($car['city']) ?></span>
                    </div>
                    <h3 class="fw-black mb-2" style="font-size: 1.6rem; color: #fff;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
                    <div class="flex justify-between align-center mt-2 pt-2" style="border-top: 1px solid var(--glass-border);">
                        <div class="price-tag" style="font-size: 1.8rem;">$<?= number_format($car['price']) ?></div>
                        <a href="car_detail.php?id=<?= $car['id'] ?>" class="btn btn-outline btn-sm fw-bold">View Details</a>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<section style="background: rgba(30, 41, 59, 0.4); padding: 10rem 0; border-top: 1px solid var(--glass-border); border-bottom: 1px solid var(--glass-border);">
    <div class="container">
        <h2 class="section-title justify-center mb-4" style="font-size: 3.5rem;">What Our Clients Say</h2>
        <div class="grid grid-3 mt-3">
            <?php foreach ($testimonials as $t): ?>
                <div class="glass" style="padding: 4rem; background: rgba(15, 23, 42, 0.6);">
                    <div style="color: var(--primary-color); margin-bottom: 2rem; font-size: 1.5rem; letter-spacing: 5px;">
                        <?php for($i=0; $i<$t['rating']; $i++) echo '★'; ?>
                    </div>
                    <p class="text-secondary mb-3" style="font-style: italic; line-height: 2; font-size: 1.2rem; font-weight: 500;">"<?= htmlspecialchars($t['text']) ?>"</p>
                    <div class="flex align-center gap-1">
                        <div style="width: 60px; height: 60px; background: var(--primary-color); border-radius: 16px; display: flex; align-items: center; justify-content: center; font-weight: 900; color: #000; font-size: 1.4rem;">
                            <?= substr($t['name'], 0, 1) ?>
                        </div>
                        <div>
                            <h4 class="fw-black" style="margin: 0; font-size: 1.2rem; color: #fff;"><?= htmlspecialchars($t['name']) ?></h4>
                            <p class="text-secondary text-sm fw-bold" style="margin: 0;"><?= htmlspecialchars($t['city']) ?></p>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<div class="container" style="padding: 10rem 0;">
    <h2 class="section-title justify-center mb-4" style="font-size: 3.5rem;">Elite Showrooms</h2>
    <div class="grid grid-3 mt-3">
        <div class="box text-center" style="padding: 5rem 3rem;">
            <div style="font-size: 5rem; margin-bottom: 2.5rem; filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));">📍</div>
            <h3 class="fw-black mb-1" style="font-size: 1.8rem; color: #fff;">Kabul Headquarters</h3>
            <p class="text-secondary mb-2 fw-bold">Wazir Akbar Khan, Street 15</p>
            <p class="text-gold fw-black" style="font-size: 1.4rem;">+93 700 123 456</p>
        </div>
        <div class="box text-center" style="padding: 5rem 3rem;">
            <div style="font-size: 5rem; margin-bottom: 2.5rem; filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));">📍</div>
            <h3 class="fw-black mb-1" style="font-size: 1.8rem; color: #fff;">Herat Elite Branch</h3>
            <p class="text-secondary mb-2 fw-bold">Jada-e-Main, Near Blue Mosque</p>
            <p class="text-gold fw-black" style="font-size: 1.4rem;">+93 700 987 654</p>
        </div>
        <div class="box text-center" style="padding: 5rem 3rem;">
            <div style="font-size: 5rem; margin-bottom: 2.5rem; filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));">📍</div>
            <h3 class="fw-black mb-1" style="font-size: 1.8rem; color: #fff;">Mazar Luxury Center</h3>
            <p class="text-secondary mb-2 fw-bold">Balkh Gate Road Center</p>
            <p class="text-gold fw-black" style="font-size: 1.4rem;">+93 700 456 789</p>
        </div>
    </div>
</div>

<div class="container" style="text-align: center; margin-bottom: 10rem;">
    <div class="box" style="padding: 10rem 5rem; background: linear-gradient(135deg, rgba(212, 175, 55, 0.15), rgba(30, 41, 59, 0.4)); border-radius: 48px;">
        <h2 class="fw-black mb-2" style="font-size: 4.5rem; color: #fff; line-height: 1;">Ready to sell your vehicle?</h2>
        <p class="text-secondary mb-4" style="max-width: 800px; margin-left: auto; margin-right: auto; font-size: 1.4rem; line-height: 1.8; font-weight: 500;">Experience the most professional automotive trading platform in Afghanistan. Verified buyers and seamless documentation guaranteed.</p>
        <a href="register.php" class="btn btn-primary btn-lg fw-black" style="padding: 1.8rem 5rem; font-size: 1.2rem; letter-spacing: 1px;">START SELLING TODAY</a>
    </div>
</div>

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