<?php
// Initialize variables for announcements
$announcement_1 = "";
$announcement_2 = "";
$announcement_3 = "";

require_once __DIR__ . '/includes/database.php';

// Fetch the three most recent announcements from the 'headers' table
$result = $conn->query("SELECT message FROM headers ORDER BY id DESC LIMIT 3");

if ($result) {
    $i = 0;
    while ($row = $result->fetch_assoc()) {
        if ($i == 0) {
            $announcement_1 = $row['message'];
        } elseif ($i == 1) {
            $announcement_2 = $row['message'];
        } elseif ($i == 2) {
            $announcement_3 = $row['message'];
        }
        $i++;
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <?php
    $seo = [
        'title'       => 'Car Third Party Insurance Online - Swift, Innova, Alto & More | Etaxpay.in',
        'description' => 'Buy car third party insurance online instantly. Best rates for Swift, Innova, Alto, WagonR and all car models. Instant policy, secure payment at etaxpay.in.',
        'keywords'    => 'car third party insurance online, four wheeler insurance India, car insurance Punjab, car insurance Haryana, car insurance Uttar Pradesh, car insurance Delhi, car insurance Rajasthan, car insurance Himachal Pradesh, car insurance Uttarakhand, car insurance Chandigarh, vehicle insurance North India, Swift insurance Punjab, Alto insurance Haryana, Innova insurance UP, WagonR insurance Delhi, car insurance instantly online',
        'canonical'   => 'https://etaxpay.in/car',
    ];
    include __DIR__ . '/includes/seo.php';
    ?>
    <!-- JSON-LD: Insurance Service + FAQ Schema -->
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Service",
      "name": "Car Third Party Insurance Online",
      "provider": {
        "@type": "Organization",
        "name": "Etaxpay",
        "url": "https://etaxpay.in"
      },
      "url": "https://etaxpay.in/car",
      "description": "Buy car third party insurance online instantly. Coverage for Swift, Innova, Alto, WagonR and all car models. Best rates with instant policy issuance.",
      "areaServed": {
        "@type": "Country",
        "name": "India"
      },
      "serviceType": "Car Third Party Insurance"
    }
    </script>
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "FAQPage",
      "mainEntity": [
        {
          "@type": "Question",
          "name": "How to buy car third party insurance online?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Visit etaxpay.in/car, select your car model, fill in vehicle details and pay online. Your third party insurance policy will be issued instantly."
          }
        },
        {
          "@type": "Question",
          "name": "What does car third party insurance cover?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Third party car insurance covers damages caused to other vehicles, property, or persons in an accident. It is mandatory under the Motor Vehicles Act in India."
          }
        },
        {
          "@type": "Question",
          "name": "Which car models are covered?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "We provide third party insurance for all car models including Maruti Swift, Toyota Innova, Maruti Alto, WagonR, Hyundai i20, Creta, and all other four-wheelers registered in India."
          }
        }
      ]
    }
    </script>
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [
        {"@type": "ListItem", "position": 1, "name": "Home", "item": "https://etaxpay.in/"},
        {"@type": "ListItem", "position": 2, "name": "Car Insurance", "item": "https://etaxpay.in/car"}
      ]
    }
    </script>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
    /* Add this new style for the end date */
    .dropdown-content {
        display: none;
        position: absolute;
        background-color: #f9f9f9;
        min-width: 160px;
        box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.2);
        z-index: 1;
    }

    /* Show the dropdown content when hovering over the menu */
    .dropdown:hover .dropdown-content {
        display: block;
    }

    /* Style the dropdown links */
    .dropdown-content a {
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
    }

    .dropdown-content a:hover {
        background-color: #ddd;
    }

    /* Scrolling text */
    .scrolling-text2 {
        animation: scroll 10s linear infinite;
    }

    .scrolling-text {
        animation: scroll 30s linear infinite;
    }

    @keyframes scroll {
        0% {
            transform: translateX(1%);
        }

        100% {
            transform: translateX(-100%);
        }
    }

    /* Dropdown menu */
    .dropdown:hover .dropdown-content {
        display: block;
    }

    /* Mobile-specific styles */
    @media (max-width: 768px) {
        /* Top notification bar */
        .top-notification {
            flex-direction: column;
            padding: 0.5rem;
            text-align: center;
        }

        .scrolling-text {
            width: 100%;
            animation: scroll 3s linear infinite;
            padding-left: 100%;
        }

        .scrolling-text2 {
            width: 100%;
            animation: scroll 2s linear infinite;
            padding-left: 100%;
        }

        .top-links {
            display: none;
        }

        h1 {
            position: static;
            transform: none;
            margin: 0.5rem 0;
            font-size: 1.5rem;
            width: 100%;
            text-align: center;
        }

        .text-right {
            text-align: center;
            margin-top: 0.5rem;
        }

        /* Navigation */
        nav .container {
            padding: 0;
            overflow-x: auto;
            white-space: nowrap;
        }

        nav .flex {
            display: inline-flex;
            padding: 0.5rem 0;
        }

        nav a,
        .dropdown>a {
            padding: 0.5rem 1rem;
        }

        .dropdown-content {
            position: absolute;
            width: auto;
        }
    }
    </style>
</head>

<body class="bg-gray-50 font-sans">
    <!-- Top Notification Bar -->
    <div class="bg-[#1c366b] text-white text-sm py-1 px-4 flex justify-between items-center">
        <div class="overflow-hidden whitespace-nowrap w-[50%]">
            <div class="scrolling-text inline-block pl-[100%]">
                Please pay tax in advance to avoid any last-minute hassle.
            </div>
        </div>
        <div class="flex items-center space-x-3 ml-4">
            <a href="index.php" class="hover:text-blue-200 transition">Home</a>
            <span>|</span>
            <a href="https://api.whatsapp.com/send/?phone=9417178593" class="hover:text-blue-200 transition">Contact
                us</a>
            <span>|</span>
            <a href="#" class="hover:text-blue-200 transition">Skip main content</a>
            <span>|</span>
            <span class="flex space-x-1">
                <a href="#" class="hover:text-blue-200 transition">A+</a>
                <a href="#" class="hover:text-blue-200 transition">A</a>
                <a href="#" class="hover:text-blue-200 transition">A-</a>
            </span>
        </div>
    </div>

    <!-- Header Section -->
    <header class="bg-[#4A9DD0] shadow-md">
        <div class="container mx-auto px-4 flex items-center justify-between">
            <div class="flex items-center w-full relative">
                <!-- Logo on the left -->
                <div class="h-[5rem] flex justify-center items-center">
                    <a href="index.php">
                        <img src="mainlogo.png" alt="Etaxpay Logo" class="" width="130px">
                    </a>
                </div>
                <!-- Site name absolutely centered in the container -->
                <h1 class="hidden md:block text-2xl font-bold text-white absolute left-1/2 transform -translate-x-1/2">
                    Etaxpay
                </h1>
            </div>
            <div class="text-right">
                <div class="text-sm font-semibold text-white">AssistPortal</div>
                <div class="text-xs text-gray-200">By Etaxpay.in</div>
            </div>
        </div>
    </header>

    <!-- Navigation Bar -->
    <nav class="text-white shadow-lg" style="background-color: rgb(41, 88, 159);">
        <div class="container mx-auto px-4">
            <div class="flex items-center space-x-3">
                <a href="index.php" class="flex items-center px-2 py-2 rounded hover:bg-blue-600 transition">
                    <i class="fas fa-home mr-2"></i> Home
                </a>

                <!-- Static Services Dropdown -->
                <div class="dropdown relative">
                    <a href="#"
                        class="dropdown-toggle flex items-center px-3 py-2 rounded hover:bg-blue-600 transition">
                        <i class="fas fa-user mr-2"></i> Services <i class="fas fa-caret-down ml-1"></i>
                    </a>
                    <div
                        class="dropdown-content hidden absolute left-0 mt-1 w-48 bg-white text-gray-800 rounded-md shadow-lg z-10">
                        <a href="taxform.php"
                            class="block px-4 py-2 hover:bg-[#d1d5db] hover:text-white rounded-t-md">Tax Payment</a>

                        <?php
                        include('config.php');
                        $query = "SELECT * FROM services ORDER BY id ASC";
                        $result = mysqli_query($conn, $query);
                        while ($row = mysqli_fetch_assoc($result)) {
                            echo "<a href='{$row['service_link']}' class='block px-4 py-2 hover:bg-[#d1d5db] hover:text-white'>{$row['service_name']}</a>";
                        }
                        ?>
                    </div>
                </div>

                <!-- Add mobile menu toggle button here -->
                <div class="mobile-menu-toggle lg:hidden ml-auto">
                    <i class="fas fa-bars"></i>
                </div>

                <!-- Dynamic Menus & Submenus (Loaded Here) -->
                <div id="menu-list" class="flex items-center space-x-5"></div>
            </div>
        </div>
    </nav>
    <div class="border-t border-gray-800"></div>
    
    <!-- Scrolling Announcement Section -->
    <div class="bg-[#29589F] px-4 py-1">
        <div class="flex items-center overflow-hidden whitespace-nowrap">
            <div class="scrolling-text inline-block pl-[100%] text-[#FFFFFF] font-bold text-sm">
                <?= htmlspecialchars($announcement_3) ?>
            </div>
        </div>
    </div>
    <hr>
    <div class="bg-[#ADD8E6] px-4 mb-5  py-1">
        <div class="flex items-center overflow-hidden whitespace-nowrap">
            <div class="scrolling-text inline-block pl-[100%] text-[#ed1010] font-semibold text-sm">
                <?= htmlspecialchars($announcement_2) ?>
            </div>
        </div>
    </div>

    <!-- Main content would go here -->

<!-- Main Form Section -->
<main class="container mx-auto px-4 pt-2 pb-4">
    <div class="max-w-2xl mx-auto bg-white rounded-lg shadow-md overflow-hidden">
        <!-- Header Section -->
        <div class="bg-[#29589f] text-white py-4 px-6">
            <h2 class="text-xl font-semibold">CAR (Third Party Insurance)</h2>
            <p class="text-blue-100 text-sm mt-1">Swift/figo/Dezire/i20/i10</p>
        </div>

        <!-- Form Section -->
        <div class="p-6">
            <form method="POST" action="process_car_insurance.php" class="space-y-4" id="carInsuranceForm" enctype="multipart/form-data">
                <!-- Car Selection Dropdown -->
                <div>
                    <label for="car_model" class="block text-sm font-medium text-gray-700 mb-1">
                        <i class="fas fa-car mr-1 text-blue-600"></i>
                        Select Car <span class="text-red-500">*</span>
                    </label>
                   <select id="car_model" name="car_model" required
    class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 dynamic-select"
    onchange="updatePricing()">
    <option value="">-- Select Car Model --</option>
    <?php
    $model_result = $conn->query("SELECT * FROM car_insurance_models WHERE status = 1 ORDER BY car_model ASC");
    while ($car = $model_result->fetch_assoc()) {
        $model = htmlspecialchars($car['car_model']);
        $premium = $car['premium'];
        $fee = $car['fee'];
        $charge = $car['charge'];
        echo "<option value='{$model}' data-price='{$premium}' data-fee='{$fee}' data-charge='{$charge}'>{$model}</option>";
    }
    ?>
</select>
                </div>

               <!-- Mobile Number Input -->
                <div>
                    <label for="mobile_number" class="block text-sm font-medium text-gray-700 mb-1">
                        <i class="fas fa-mobile-alt mr-1 text-blue-600"></i>
                        Enter Your Mobile Number <span class="text-red-500">*</span>
                    </label>
                    <div class="phone-input">
                        <span>+91</span>
                        <input type="tel" id="mobile_number" name="mobile_number" 
                            pattern="[0-9]{10}" maxlength="10" required
                            placeholder="Enter 10-digit mobile number"
                            class="flex-1 border-none px-3 py-2 focus:outline-none">
                    </div>
                </div>
                
                <div>
    <label for=" Vehicle RC Front" class="block text-sm font-medium text-gray-700 mb-1">
        <i class="fas fa-id-card mr-1 text-blue-600"></i>
        Vehicle RC Front <span class="text-red-500">*</span>
    </label>
    <input type="file" id="vehicle_rc_front" name="vehicle_rc_front" required
        class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4
               file:rounded-md file:border-0 file:text-sm file:font-semibold
               file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"/>
</div>
                
                <div>
    <label for=" Vehicle RC Back" class="block text-sm font-medium text-gray-700 mb-1">
        <i class="fas fa-id-card mr-1 text-blue-600"></i>
        Vehicle RC Back <span class="text-red-500"></span>
    </label>
    <input type="file" id="vehicle_rc_back" name="vehicle_rc_back" 
        class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4
               file:rounded-md file:border-0 file:text-sm file:font-semibold
               file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"/>
</div>
                
                 <!-- Aadhar Card Front Upload -->
<div>
    <label for="aadhar_front" class="block text-sm font-medium text-gray-700 mb-1">
        <i class="fas fa-id-card mr-1 text-blue-600"></i>
        Aadhar Card Front <span class="text-red-500">*</span>
    </label>
    <input type="file" id="aadhar_front" name="aadhar_front" required
        class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4
               file:rounded-md file:border-0 file:text-sm file:font-semibold
               file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"/>
</div>

<!-- Aadhar Card Back Upload -->
<div>
    <label for="aadhar_back" class="block text-sm font-medium text-gray-700 mb-1">
        <i class="fas fa-id-card mr-1 text-blue-600"></i>
        Aadhar Card Back <span class="text-red-500"></span>
    </label>
    <input type="file" id="aadhar_back" name="aadhar_back" 
        class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4
               file:rounded-md file:border-0 file:text-sm file:font-semibold
               file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"/>
</div>

<!-- PAN Card Upload -->
<div>
    <label for="pan_card" class="block text-sm font-medium text-gray-700 mb-1">
        <i class="fas fa-id-card mr-1 text-blue-600"></i>
        Pan Card <span class="text-red-500"></span>
    </label>
    <input type="file" id="pan_card" name="pan_card" 
        class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4
               file:rounded-md file:border-0 file:text-sm file:font-semibold
               file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"/>
</div>
                <!-- Price Summary -->
                <div id="taxSummary" class="border border-gray-200 rounded-md p-4">
                    <h3 class="font-medium text-lg text-blue-800 mb-2">Payment Summary</h3>
                    <div class="space-y-1">
                        <p class="flex justify-between">
                            <span>Insurance Premium:</span>
                            <span class="font-medium" id="displayPremium">₹0.00</span>
                        </p>
                        <p class="flex justify-between">
                            <span>Convenience Fees:</span>
                            <span class="font-medium" id="displayFee">₹0.00</span>
                        </p>
                        <p class="flex justify-between">
                            <span>Service Charge:</span>
                            <span class="font-medium" id="displayCharge">₹0.00</span>
                        </p>
                        <p class="flex justify-between border-t border-gray-200 pt-2 mt-2">
                            <span class="font-semibold">Total:</span>
                            <span class="font-semibold text-blue-800" id="displayTotal">₹0.00</span>
                        </p>
                    </div>
                </div>
                
                <!-- Hidden fields for form processing -->
                <input type="hidden" name="insurance_premium" id="insurancePremium" value="0">
                <input type="hidden" name="convenience_fee" id="convenienceFee" value="0">
                <input type="hidden" name="service_charge" id="serviceCharge" value="0">
                
                
                
                <!-- Submit button -->
                <div class="pt-4">
                    <button type="submit"
                        class="w-full bg-[#29589f] hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md shadow-sm transition duration-150 ease-in-out focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
                        Proceed to Pay
                    </button>
                </div>
            </form>
        </div>
    </div>
</main>

<script>
function updatePricing() {
    const carSelect = document.getElementById('car_model');
    const selectedOption = carSelect.options[carSelect.selectedIndex];
    
    if (selectedOption.value) {
        const premium = parseFloat(selectedOption.getAttribute('data-price')) || 0;
        const fee = parseFloat(selectedOption.getAttribute('data-fee')) || 0;
        const charge = parseFloat(selectedOption.getAttribute('data-charge')) || 0;
        const total = premium + fee + charge;
        
        // Update displayed values
        document.getElementById('displayPremium').textContent = '₹' + premium.toFixed(2);
        document.getElementById('displayFee').textContent = '₹' + fee.toFixed(2);
        document.getElementById('displayCharge').textContent = '₹' + charge.toFixed(2);
        document.getElementById('displayTotal').textContent = '₹' + total.toFixed(2);
        
        // Update hidden fields
        document.getElementById('insurancePremium').value = premium;
        document.getElementById('convenienceFee').value = fee;
        document.getElementById('serviceCharge').value = charge;
    } else {
        // Reset if no selection
        document.getElementById('displayPremium').textContent = '₹0.00';
        document.getElementById('displayFee').textContent = '₹0.00';
        document.getElementById('displayCharge').textContent = '₹0.00';
        document.getElementById('displayTotal').textContent = '₹0.00';
    }
}

// Initialize pricing on page load if there's a selected option
document.addEventListener('DOMContentLoaded', function() {
    const carSelect = document.getElementById('car_model');
    if (carSelect.selectedIndex > 0) {
        updatePricing();
    }
});
</script>

<!-- Rest of your original footer and scripts would go here -->
    
    <!-- Scrolling Announcement Section for Announcement 3 -->
    <div class="bg-[#1c366b] px-4 py-1">
        <div class="flex items-center overflow-hidden whitespace-nowrap">
            <div class="scrolling-text inline-block pl-[100%] text-[#FFFFFF] font-bold text-sm">
                <?= htmlspecialchars($announcement_1) ?>
            </div>
        </div>
    </div>
<?php include __DIR__ . '/includes/footer.php'; ?>

    <script>
    document.addEventListener("DOMContentLoaded", function() {
        console.log("📌 Page Loaded. Fetching menus...");
        loadMenus();
        loadButtons();
    });

    function loadMenus() {
        fetch("fetch_menus.php?t=" + new Date().getTime())
            .then(response => response.text())
            .then(data => {
                console.log("📌 Fetched Menu Data:", data);

                let menuList = document.getElementById("menu-list");
                if (!menuList) {
                    console.error("❌ Element #menu-list not found in index.html");
                    return;
                }

                menuList.innerHTML = data;

                // Hide all dropdowns by default
                document.querySelectorAll('.dropdown-content').forEach(dropdown => {
                    dropdown.classList.add('hidden');
                });

                // After loading the menus, ensure the dropdown functionality works
                setupDropdowns();
            })
            .catch(error => console.error('❌ Error fetching menus:', error));
    }

    function loadButtons() {
        fetch("fetch_buttons.php?t=" + new Date().getTime())
            .then(response => response.text())
            .then(data => {
                console.log("📌 Fetched Button Data:", data);

                let dynamicButtons = document.getElementById("dynamic-buttons");
                if (!dynamicButtons) {
                    console.error("❌ Element #dynamic-buttons not found");
                    return;
                }

                dynamicButtons.innerHTML = data;
            })
            .catch(error => console.error('❌ Error fetching buttons:', error));
    }

    function setupDropdowns() {
        document.querySelectorAll('.dropdown-toggle').forEach(item => {
            item.addEventListener('click', function(e) {
                e.preventDefault(); // Prevent default link behavior

                // Find the closest dropdown container
                let dropdown = item.closest('.dropdown');
                let dropdownContent = dropdown.querySelector('.dropdown-content');

                // Toggle the hidden class to show/hide the dropdown content
                dropdownContent.classList.toggle('hidden');

                // Close all other dropdowns
                document.querySelectorAll('.dropdown-content').forEach(otherDropdown => {
                    if (otherDropdown !== dropdownContent) {
                        otherDropdown.classList.add('hidden');
                    }
                });
            });
        });

        document.querySelectorAll('.dropdown').forEach(dropdown => {
            const dropdownContent = dropdown.querySelector('.dropdown-content');

            let hideTimeout;

            // Show dropdown immediately on mouse enter
            dropdown.addEventListener('mouseenter', function() {
                clearTimeout(hideTimeout); // Cancel any scheduled hiding
                dropdownContent.classList.remove('hidden');
            });

            // Delay hiding the dropdown on mouse leave
            dropdown.addEventListener('mouseleave', function() {
                hideTimeout = setTimeout(() => {
                    dropdownContent.classList.add('hidden');
                }, 300); // delay in ms (e.g., 300ms = 0.3 seconds)
            });

            // Prevent dropdown from closing when clicking inside it
            dropdownContent.addEventListener('click', function(e) {
                e.stopPropagation();
            });
        });

        // Close dropdown when clicking outside
        document.addEventListener('click', function(e) {
            document.querySelectorAll('.dropdown-content').forEach(dropdown => {
                if (!dropdown.closest('.dropdown').contains(e.target)) {
                    dropdown.classList.add('hidden');
                }
            });
        });
    }
    </script>
</body>
</html>