<!DOCTYPE html>
<html class="dark" lang="en">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<?php
if (!file_exists(__DIR__ . '/../admin/includes/config.php')) {
    header("Location: ../admin/install.php");
    exit;
}
require_once '../admin/includes/config.php';
require_once '../admin/includes/branding.php';
?>
<title><?= htmlspecialchars(getBrandName()) ?> - Premium Car Rentals</title>
<?php
$base_path = "../admin/";
include '../admin/includes/tailwind_config_include.php';
?>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&amp;display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
    <link rel="stylesheet" href="../admin/includes/responsive.css">
<style>
    .glass-effect { backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
    body { font-family: 'Inter', sans-serif; min-height: max(884px, 100dvh); }

    </style>
</head>
<body class="bg-background-light dark:bg-background-dark font-display text-slate-900 dark:text-white min-h-screen pb-24">
<!-- Top Navigation Bar -->
<header class="sticky top-0 z-50 bg-background-light/80 dark:bg-background-dark/80 backdrop-blur-md border-b border-slate-200 dark:border-slate-800">
<div class="flex items-center p-4 justify-between responsive-container">
<div class="flex size-10 shrink-0 items-center justify-center" onclick="openDrawer()">
<span class="material-symbols-outlined cursor-pointer">menu</span>
</div>
<div class="flex-1 flex justify-center items-center gap-2">
    <?php $logo = getAppLogo(); ?>
    <?php if ($logo): ?>
        <img src="<?= htmlspecialchars($logo) ?>" alt="Logo" class="h-8 w-auto object-contain">
    <?php endif; ?>
    <h2 class="text-lg font-bold leading-tight tracking-tight"><?= htmlspecialchars(getBrandName()) ?></h2>
</div>
<div class="flex w-10 items-center justify-end">
<a href="profile.php" class="flex size-10 cursor-pointer items-center justify-center overflow-hidden rounded-full bg-primary/10 text-primary">
<span class="material-symbols-outlined">account_circle</span>
</a>
</div>
</div>
</header>
<main class="responsive-container">
<!-- Welcome Section -->
<div class="px-4 py-6">
<h1 class="text-clamp-2xl font-bold tracking-tight">Welcome Back!</h1>
<p class="text-slate-500 dark:text-slate-400 mt-1">Find your perfect ride today</p>
</div>
<!-- Quick Actions -->
<div class="grid grid-cols-1 xs:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 4xl:grid-cols-8 6xl:grid-cols-10 8xl:grid-cols-12 gap-clamp-4 px-4">
<a href="browse_cars.php" class="flex flex-col items-center justify-center p-clamp-4 bg-white dark:bg-[#192633] rounded-xl border border-slate-200 dark:border-slate-800 shadow-sm active:scale-95 transition-transform">
<div class="size-12 md:size-16 4xl:size-24 8xl:size-32 rounded-full bg-primary flex items-center justify-center mb-3">
<span class="material-symbols-outlined text-white text-clamp-2xl">directions_car</span>
</div>
<span class="text-clamp-sm font-bold">Rent a Car</span>
</a>
<a href="delivery_booking.php" class="flex flex-col items-center justify-center p-clamp-4 bg-white dark:bg-[#192633] rounded-xl border border-slate-200 dark:border-slate-800 shadow-sm active:scale-95 transition-transform">
<div class="size-12 md:size-16 4xl:size-24 8xl:size-32 rounded-full bg-amber-500 flex items-center justify-center mb-3">
<span class="material-symbols-outlined text-white text-clamp-2xl">local_shipping</span>
</div>
<span class="text-clamp-sm font-bold">Book Delivery</span>
</a>
<a href="my_bookings.php" class="flex flex-col items-center justify-center p-clamp-4 bg-white dark:bg-[#192633] rounded-xl border border-slate-200 dark:border-slate-800 shadow-sm active:scale-95 transition-transform">
<div class="size-12 md:size-16 4xl:size-24 8xl:size-32 rounded-full bg-slate-100 dark:bg-slate-800 flex items-center justify-center mb-3">
<span class="material-symbols-outlined text-primary text-clamp-2xl">confirmation_number</span>
</div>
<span class="text-clamp-sm font-bold">My Bookings</span>
</a>
</div>
<!-- Featured Cars -->
<div class="px-4 pt-6 pb-2">
<h2 class="text-clamp-xl font-bold tracking-tight">Featured Cars</h2>
</div>
<div id="featuredCars" class="grid grid-cols-1 xs:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 4xl:grid-cols-8 6xl:grid-cols-10 8xl:grid-cols-12 gap-clamp-4 p-4">
    <!-- Loading skeleton -->
    <div class="animate-pulse flex flex-col bg-white dark:bg-[#192633] rounded-xl overflow-hidden shadow-sm border border-slate-100 dark:border-slate-800/50">
        <div class="w-full aspect-[4/3] bg-slate-200 dark:bg-slate-800"></div>
        <div class="p-3 space-y-2">
            <div class="h-4 bg-slate-200 dark:bg-slate-800 rounded w-3/4"></div>
            <div class="h-4 bg-slate-200 dark:bg-slate-800 rounded w-1/4"></div>
        </div>
    </div>
</div>
</main>
<!-- Bottom Navigation Bar -->
<?php include 'includes/bottom_nav.php'; ?>

<!-- Navigation Drawer -->
<?php include 'includes/nav_drawer.php'; ?>

<script>
async function loadFeaturedCars() {
    const container = document.getElementById('featuredCars');
    try {
        const response = await fetch('../api/vehicles.php?featured=1&limit=6');
        if (!response.ok) throw new Error('Network response was not ok');
        const data = await response.json();

        if (data.success && data.data) {
            if (data.data.length === 0) {
                container.innerHTML = '<p class="col-span-full text-center text-slate-500 py-8">No featured cars at the moment.</p>';
                return;
            }

            container.innerHTML = data.data.map(vehicle => `
                <div class="flex flex-col bg-white dark:bg-[#192633] rounded-xl overflow-hidden shadow-sm border border-slate-100 dark:border-slate-800/50 hover:shadow-md transition-shadow">
                    <a href="vehicle_details.php?id=${vehicle.id}" class="relative w-full aspect-[4/3] bg-slate-200 dark:bg-slate-800 bg-center bg-no-repeat bg-cover block" style='background-image: url("${vehicle.display_image}");'>
                        <div class="absolute top-2 left-2 flex items-center gap-1 bg-white/90 dark:bg-black/80 backdrop-blur-sm px-2 py-1 rounded-full border border-amber-500/30 shadow-sm">
                            <span class="material-symbols-outlined text-[14px] text-amber-500 fill-1">star</span>
                            <span class="text-[10px] font-bold text-slate-800 dark:text-white uppercase tracking-tight">Featured</span>
                        </div>
                    </a>
                    <div class="p-clamp-3">
                        <a href="vehicle_details.php?id=${vehicle.id}" class="text-slate-900 dark:text-white text-clamp-base font-bold leading-tight mb-1 block hover:text-primary transition-colors">${vehicle.make} ${vehicle.model}</a>
                        <p class="text-primary text-clamp-sm font-bold mb-2">₱${parseFloat(vehicle.daily_rate).toFixed(2)}<span class="text-slate-500 dark:text-slate-400 font-normal">/day</span></p>
                        <a href="checkout_summary.html?vehicle=${vehicle.id}" class="text-clamp-xs font-semibold text-primary">Book Now →</a>
                    </div>
                </div>
            `).join('');
        } else {
            throw new Error(data.error || 'Failed to load featured cars');
        }
    } catch (error) {
        console.error('Error loading featured cars:', error);
        container.innerHTML = '<p class="col-span-full text-center text-red-500 py-8">Unable to load featured cars at this time.</p>';
    }
}

document.addEventListener('DOMContentLoaded', loadFeaturedCars);
</script>

<!-- Firebase SDK (Compat) -->
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-database-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js"></script>
<!-- Firebase Config -->
<script src="../admin/includes/firebase_config.js?v=1.0.2"></script>
<script src="../admin/includes/notification_manager.js"></script>
<!-- Floating Chat Logic -->
<script src="../admin/includes/floating_chat.js?v=1.0.2"></script>

<script>
document.addEventListener('DOMContentLoaded', function() {
    <?php if (isset($_SESSION['user_id'])): ?>
    if (typeof NotificationManager !== 'undefined') {
        NotificationManager.init(<?= $_SESSION['user_id'] ?>, 'customer');
    }
    <?php endif; ?>
});
</script>
<style>
    #floating-chat-container {
        position: fixed !important;
        z-index: 2147483647 !important;
    }
    #floating-chat-button {
        box-shadow: 0 0 20px rgba(19, 127, 236, 0.6) !important;
    }
    .dark #floating-chat-menu {
        background-color: #1e293b !important;
        border-color: #334155 !important;
        color: white !important;
    }
</style>

</body>
</html>
