<?php include 'header.php'; ?>


<div class="px-0 py-3 md:p-2 lg:p-6">


    <div
        class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-5 bg-white p-4 rounded-lg border border-gray-200">

        <div>
            <h1 class="text-2xl font-bold text-gray-800">
                Customers
            </h1>
        
            <p class="text-sm text-gray-500">
                Manage all customer registrations and details from here
            </p>
        </div>

        <div class="flex flex-col sm:flex-row gap-3">

            <div class="relative">

                <input type="text" placeholder="Search here..."
                    class="w-full sm:w-[220px] pl-10 pr-4 py-2.5 rounded-xl border border-gray-200 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 outline-none text-sm">
                    <i class="ri-search-line absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"></i>
            </div>

            <button id="openFilter"
                class="px-4 py-2.5 rounded-xl border border-blue-100 bg-white hover:bg-gradient-to-r hover:from-blue-500 hover:to-indigo-600 hover:text-white transition-all duration-300 text-sm text-blue-600 flex items-center gap-2">
                <i class="ri-filter-3-line"></i>
                Filter
            </button>

            <!--<a href="add_puresaas_customer.php"-->
            <!--    class="w-full sm:w-auto px-5 py-2.5 rounded-xl bg-gradient-to-r from-blue-500 to-indigo-600 text-white font-medium text-sm flex items-center justify-center gap-2 shadow-lg hover:from-blue-600 hover:to-indigo-700 transition-all duration-300">-->
            <!--    <i class="ri-add-line"></i>-->
            <!--    <span>Add Customer</span>-->

            <!--</a>-->

        </div>

    </div>

<div class="bg-white rounded-lg border border-gray-200 shadow-sm overflow-x-auto overflow-y-hidden mb-5">

    <div class="p-4 border-b border-gray-200">
        <div class="flex flex-wrap gap-2">

            <!-- PureEstate -->
            <button onclick="filterProduct('PureEstate')"
                class="px-4 py-2 rounded-xl border border-blue-200 bg-blue-50 text-blue-600 text-sm font-medium hover:bg-blue-100">
                PureEstate
               <span id="pureEstateCount" class="ml-1 px-2 py-0.5 text-xs rounded-full bg-blue-600 text-white">0</span>
            </button>

            <!-- BuilderPro -->
            <button onclick="filterProduct('BuilderPro')"
                class="px-4 py-2 rounded-xl border border-green-200 bg-green-50 text-green-600 text-sm font-medium hover:bg-green-100">
                BuilderPro
                <span id="builderProCount" class="ml-1 px-2 py-0.5 text-xs rounded-full bg-green-600 text-white">0</span>
            </button>

            <!-- SocietyPro -->
            <button onclick="filterProduct('SocietyPro')"
                class="px-4 py-2 rounded-xl border border-purple-200 bg-purple-50 text-purple-600 text-sm font-medium hover:bg-purple-100">
                SocietyPro
                <span id="societyProCount" class="ml-1 px-2 py-0.5 text-xs rounded-full bg-purple-600 text-white">0</span>
            </button>

            <!-- Total -->
            <button onclick="filterProduct('all')"
                class="px-4 py-2 rounded-xl border border-gray-200 bg-gray-50 text-gray-700 text-sm font-medium hover:bg-gray-100">
                Total
                <span id="totalProductCount" class="ml-1 px-2 py-0.5 text-xs rounded-full bg-gray-700 text-white">0</span>
            </button>

        </div>
    </div>

</div>

<div class="bg-white rounded-lg border border-gray-200 shadow-sm mb-5">
    <div class="p-4">
        <div class="flex flex-wrap gap-2">

            <button onclick="filterStatus('pending')" class="px-4 py-2 rounded-xl border border-yellow-200 bg-yellow-50 text-yellow-600 text-sm font-medium">
                Pending
               <span id="pendingCount" class="ml-1 px-2 py-0.5 rounded-full bg-yellow-600 text-white text-xs">0</span>
            </button>

            <button  onclick="filterStatus('active')" class="px-4 py-2 rounded-xl border border-green-200 bg-green-50 text-green-600 text-sm font-medium">
                Active
               <span id="activeCount" class="ml-1 px-2 py-0.5 rounded-full bg-green-600 text-white text-xs">0</span>
            </button>

            <button onclick="filterStatus('all')" class="px-4 py-2 rounded-xl border border-blue-200 bg-blue-50 text-blue-600 text-sm font-medium">
                Total
                <span id="totalStatusCount" class="ml-1 px-2 py-0.5 rounded-full bg-blue-600 text-white text-xs">0</span>
            </button>

        </div>
    </div>
</div>

    <div class="bg-white rounded-lg border border-gray-200 shadow-sm overflow-x-auto overflow-y-hidden">

        <div class="overflow-x-auto">

            <table class="w-full min-w-[1000px] whitespace-nowrap">

                <thead class="bg-gray-50 border-b border-gray-200">
                    <tr class="text-left">

                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                            Sr No
                        </th>
                        
                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                            Mobile Number
                        </th>
                        
                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                           Product
                        </th>

                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                            Full Name
                        </th>
                        
                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                            City
                        </th>
                        
                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                            Reference Code
                        </th>

                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider whitespace-nowrap">
                            Status
                        </th>

                        <th
                            class="px-6 py-4 text-xs font-semibold text-gray-500 uppercase tracking-wider text-center w-40">
                            Action
                        </th>

                    </tr>
                </thead>

                <tbody class="divide-y divide-gray-100 bg-white">

                    <!-- Row 1 -->
                    <tr class="hover:bg-gray-50 transition"
                        data-product="PureEstate"
                        data-status="pending">
                
                        <td class="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">1</td>
                        <td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">9876543211</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">PureEstate</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-500 whitespace-nowrap">Raj Patel</td>
                        <td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">Surat</td>
                
                        <td class="px-6 py-4">
                            <div class="inline-flex flex-col rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-2">
                                <span class="text-xs font-bold uppercase tracking-wide text-indigo-600">
                                    RJP001
                                </span>
                                <span class="mt-1 text-sm font-medium text-gray-800">
                                    Rajesh Patel
                                </span>
                            </div>
                        </td>
                
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-3 py-1 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-600">
                                Pending
                            </span>
                        </td>
                
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="flex items-center justify-center gap-2">
                
                                <a href="view_puresaas_customer.php"
                                    class="w-9 h-9 rounded-lg bg-green-50 text-green-600 flex items-center justify-center">
                                    <i class="ri-eye-line"></i>
                                </a>
                
                                <a href="#"
                                    class="w-9 h-9 rounded-lg bg-blue-50 text-blue-600 flex items-center justify-center">
                                    <i class="ri-pencil-line"></i>
                                </a>
                
                                <button onclick="deleteRow(this)"
                                    class="w-9 h-9 rounded-lg bg-red-50 text-red-600 flex items-center justify-center">
                                    <i class="ri-delete-bin-line"></i>
                                </button>
                
                            </div>
                        </td>
                
                    </tr>
                
                    <!-- Row 2 -->
                    <tr class="hover:bg-gray-50 transition"
                        data-product="SocietyPro"
                        data-status="active">
                
                        <td class="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">2</td>
                        <td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">9876543210</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">SocietyPro</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-500 whitespace-nowrap">Dev Mistry</td>
                        <td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">Surat</td>
                
                        <td class="px-6 py-4">
                            <div class="inline-flex flex-col rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-2">
                                <span class="text-xs font-bold uppercase tracking-wide text-indigo-600">
                                    SP015
                                </span>
                                <span class="mt-1 text-sm font-medium text-gray-800">
                                    Shubham Patel
                                </span>
                            </div>
                        </td>
                
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-3 py-1 rounded-full text-xs font-semibold bg-green-100 text-green-600">
                                Active
                            </span>
                        </td>
                
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="flex items-center justify-center gap-2">
                
                                <a href="view_puresaas_customer.php"
                                    class="w-9 h-9 rounded-lg bg-green-50 text-green-600 flex items-center justify-center">
                                    <i class="ri-eye-line"></i>
                                </a>
                
                                <a href="#"
                                    class="w-9 h-9 rounded-lg bg-blue-50 text-blue-600 flex items-center justify-center">
                                    <i class="ri-pencil-line"></i>
                                </a>
                
                                <button onclick="deleteRow(this)"
                                    class="w-9 h-9 rounded-lg bg-red-50 text-red-600 flex items-center justify-center">
                                    <i class="ri-delete-bin-line"></i>
                                </button>
                
                            </div>
                        </td>
                
                    </tr>
                
                    <!-- BuilderPro Sample -->
                    <tr class="hover:bg-gray-50 transition"
                        data-product="BuilderPro"
                        data-status="active">
                
                        <td class="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">3</td>
                        <td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">9876543209</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-800 whitespace-nowrap">BuilderPro</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-500 whitespace-nowrap">Amit Shah</td>
                        <td class="px-6 py-4 text-sm text-gray-700 whitespace-nowrap">Ahmedabad</td>
                
                        <td class="px-6 py-4">
                            <div class="inline-flex flex-col rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-2">
                                <span class="text-xs font-bold uppercase tracking-wide text-indigo-600">
                                    BSP021
                                </span>
                                <span class="mt-1 text-sm font-medium text-gray-800">
                                    Bharat Patel
                                </span>
                            </div>
                        </td>
                
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="px-3 py-1 rounded-full text-xs font-semibold bg-green-100 text-green-600">
                                Active
                            </span>
                        </td>
                
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="flex items-center justify-center gap-2">
                
                                <a href="view_puresaas_customer.php"
                                    class="w-9 h-9 rounded-lg bg-green-50 text-green-600 flex items-center justify-center">
                                    <i class="ri-eye-line"></i>
                                </a>
                
                                <a href="#"
                                    class="w-9 h-9 rounded-lg bg-blue-50 text-blue-600 flex items-center justify-center">
                                    <i class="ri-pencil-line"></i>
                                </a>
                
                                <button onclick="deleteRow(this)"
                                    class="w-9 h-9 rounded-lg bg-red-50 text-red-600 flex items-center justify-center">
                                    <i class="ri-delete-bin-line"></i>
                                </button>
                
                            </div>
                        </td>
                
                    </tr>
                    <tr class="hover:bg-gray-50 transition" data-product="PureEstate" data-status="active">

                        <td class="px-6 py-4 text-sm font-medium text-gray-800">4</td>
                        <td class="px-6 py-4 text-sm text-gray-700">9876543212</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-800">PureEstate</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-500">Karan Patel</td>
                        <td class="px-6 py-4 text-sm text-gray-700">Vadodara</td>
                    
                        <td class="px-6 py-4">
                            <div class="inline-flex flex-col rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-2">
                                <span class="text-xs font-bold uppercase tracking-wide text-indigo-600">
                                    PE002
                                </span>
                                <span class="mt-1 text-sm font-medium text-gray-800">
                                    Rajesh Patel
                                </span>
                            </div>
                        </td>
                    
                        <td class="px-6 py-4">
                            <span class="px-3 py-1 rounded-full text-xs font-semibold bg-green-100 text-green-600">
                                Active
                            </span>
                        </td>
                    
                        <td class="px-6 py-4">
                            <div class="flex items-center justify-center gap-2">
                                <a href="view_puresaas_customer.php"
                                    class="w-9 h-9 rounded-lg bg-green-50 text-green-600 flex items-center justify-center">
                                    <i class="ri-eye-line"></i>
                                </a>
                            </div>
                        </td>
                    
                    </tr>
                    
                    <tr class="hover:bg-gray-50 transition" data-product="BuilderPro" data-status="pending">
                    
                        <td class="px-6 py-4 text-sm font-medium text-gray-800">5</td>
                        <td class="px-6 py-4 text-sm text-gray-700">9876543213</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-800">BuilderPro</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-500">Meet Shah</td>
                        <td class="px-6 py-4 text-sm text-gray-700">Surat</td>
                    
                        <td class="px-6 py-4">
                            <div class="inline-flex flex-col rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-2">
                                <span class="text-xs font-bold uppercase tracking-wide text-indigo-600">
                                    BP002
                                </span>
                                <span class="mt-1 text-sm font-medium text-gray-800">
                                    Amit Shah
                                </span>
                            </div>
                        </td>
                    
                        <td class="px-6 py-4">
                            <span class="px-3 py-1 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-600">
                                Pending
                            </span>
                        </td>
                    
                        <td class="px-6 py-4">
                            <div class="flex items-center justify-center gap-2">
                                <a href="view_puresaas_customer.php"
                                    class="w-9 h-9 rounded-lg bg-green-50 text-green-600 flex items-center justify-center">
                                    <i class="ri-eye-line"></i>
                                </a>
                            </div>
                        </td>
                    
                    </tr>
                    <tr class="hover:bg-gray-50 transition" data-product="SocietyPro" data-status="pending">
                    
                        <td class="px-6 py-4 text-sm font-medium text-gray-800">6</td>
                        <td class="px-6 py-4 text-sm text-gray-700">9876543214</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-800">SocietyPro</td>
                        <td class="px-6 py-4 text-sm font-medium text-gray-500">Nirav Patel</td>
                        <td class="px-6 py-4 text-sm text-gray-700">Ahmedabad</td>
                    
                        <td class="px-6 py-4">
                            <div class="inline-flex flex-col rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-2">
                                <span class="text-xs font-bold uppercase tracking-wide text-indigo-600">
                                    SP020
                                </span>
                                <span class="mt-1 text-sm font-medium text-gray-800">
                                    Shubham Patel
                                </span>
                            </div>
                        </td>
                    
                        <td class="px-6 py-4">
                            <span class="px-3 py-1 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-600">
                                Pending
                            </span>
                        </td>
                    
                        <td class="px-6 py-4">
                            <div class="flex items-center justify-center gap-2">
                                <a href="view_puresaas_customer.php"
                                    class="w-9 h-9 rounded-lg bg-green-50 text-green-600 flex items-center justify-center">
                                    <i class="ri-eye-line"></i>
                                </a>
                            </div>
                        </td>
                    
                    </tr>
                
                </tbody>

            </table>

        </div>

        <div class="px-4 py-4 border-t border-gray-100 flex flex-col md:flex-row items-center justify-between gap-4">

            <p class="text-sm text-gray-500">
                Showing 1 to 4 of 62 tasks
            </p>

            <div class="flex items-center gap-2">

                <button class="w-9 h-9 rounded-lg border border-gray-200 text-gray-500 hover:bg-gray-100 transition">
                    <i class="ri-arrow-left-s-line"></i>
                </button>

                <button
                    class="w-9 h-9 rounded-xl bg-gradient-to-r from-blue-500 to-indigo-600 text-white font-medium shadow-md">
                    1
                </button>

                <button class="w-9 h-9 rounded-lg border border-gray-200 text-gray-600 hover:bg-gray-100 transition">
                    2
                </button>

                <button class="w-9 h-9 rounded-lg border border-gray-200 text-gray-600 hover:bg-gray-100 transition">
                    3
                </button>

                <button class="w-9 h-9 rounded-lg border border-gray-200 text-gray-600 hover:bg-gray-100 transition">
                    4
                </button>

                <button class="w-9 h-9 rounded-lg border border-gray-200 text-gray-500 hover:bg-gray-100 transition">
                    <i class="ri-arrow-right-s-line"></i>
                </button>

            </div>

        </div>

    </div>

</div>

<div id="filterSidebar"
    class="fixed top-0 right-[-400px] w-[320px] h-full bg-white shadow-2xl z-50 transition-all duration-300 border-l border-gray-200">

    <div class="flex items-center justify-between p-5 border-b border-gray-100">
        <h2 class="text-lg font-bold text-gray-800">
            Filters
        </h2>
        <button id="closeFilter" class="w-9 h-9  text-black  flex items-center justify-center">

            <i class="ri-close-line text-xl"></i>

        </button>
    </div>
    <div class="p-5 space-y-5 pb-28 overflow-y-auto">
        <div class="w-full">
            <label class="mb-1 block text-sm font-medium text-slate-700">
                From Date
            </label>
            <div class="relative">
                <i class="ri-calendar-line absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"></i>
                <input type="date" id="fromDate"
                    class="h-11 w-full rounded-md border border-slate-200 bg-slate-50 pl-10 pr-4 text-sm text-slate-700 outline-none transition focus:border-blue-500 focus:bg-white focus:ring-2 focus:ring-blue-100">
            </div>
        </div>
        <div class="w-full">
            <label class="mb-1 block text-sm font-medium text-slate-700">
                To Date
            </label>
            <div class="relative">
                <i class="ri-calendar-line absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"></i>
                <input type="date" id="toDate"
                    class="h-11 w-full rounded-md border border-slate-200 bg-slate-50 pl-10 pr-4 text-sm text-slate-700 outline-none transition focus:border-blue-500 focus:bg-white focus:ring-2 focus:ring-blue-100">
            </div>
        </div>
        <div class="w-full">
            <label class="mb-1 block text-sm font-medium text-slate-700">
                Full Name
            </label>

            <div class="relative">
                <i class="ri-user-line absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"></i>

                <input type="text" id="fullName" placeholder="Enter Full Name"
                    class="h-11 w-full rounded-md border border-slate-200 bg-slate-50 pl-10 pr-4 text-sm text-slate-700 outline-none transition focus:border-blue-500 focus:bg-white focus:ring-2 focus:ring-blue-100">
            </div>
        </div>
        <div class="w-full">
            <label class="mb-1 block text-sm font-medium text-slate-700">
                Product
            </label>
        
            <div class="relative">
                <i class="ri-box-3-line absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 z-10"></i>
        
                <select id="productSelect">
                    <option value="">Select Product</option>
                    <option value="PureEstate">PureEstate</option>
                    <option value="BuilderPro">BuilderPro</option>
                    <option value="SocietyPro">SocietyPro</option>
                </select>
            </div>
        </div>

    </div>
    <div class="absolute bottom-0 left-0 w-full border-t border-gray-200 bg-white p-4">
        <div class="flex flex-row items-center justify-center gap-3 whitespace-nowrap">
            <button
                class="w-1/2 h-11 rounded-md border border-slate-200 bg-slate-100 text-sm font-medium text-slate-700 transition hover:bg-slate-200">
                Reset
            </button>
            <button
                class="w-1/2 h-11 rounded-md bg-gradient-to-r from-blue-500 to-indigo-600 text-sm font-medium text-white shadow-md transition hover:from-blue-600 hover:to-indigo-700">
                Apply Filter
            </button>
        </div>
    </div>
</div>

<script>
const openFilter = document.getElementById("openFilter");
const closeFilter = document.getElementById("closeFilter");
const filterSidebar = document.getElementById("filterSidebar");
const sidebarOverlay = document.getElementById("sidebarOverlay");

openFilter.addEventListener("click", () => {

    filterSidebar.style.right = "0";
    sidebarOverlay.classList.remove("hidden");

});

closeFilter.addEventListener("click", () => {

    filterSidebar.style.right = "-400px";
    sidebarOverlay.classList.add("hidden");

});

sidebarOverlay.addEventListener("click", () => {

    filterSidebar.style.right = "-400px";
    sidebarOverlay.classList.add("hidden");

});
</script>

<script>
    const productSelect = new TomSelect("#productSelect", {
    create: false,
    maxOptions: 50,
    placeholder: "Search Product...",
    openOnFocus: true,

    onType: function(str) {
        if (str.trim().length > 0) {
            this.open();
        } else {
            this.close();
        }
    }
});

// Prevent open on click
productSelect.control.addEventListener("click", function() {
    if (productSelect.control_input.value.trim() === "") {
        productSelect.close();
    }
});
</script>

<script>
function deleteRow(button) {

    Swal.fire({

        title: "Delete Record?",
        text: "This row will be deleted.",
        icon: "warning",

        width: "320px",
        padding: "1rem",

        showCancelButton: true,
        scrollbarPadding: false,
        confirmButtonText: "Delete",
        cancelButtonText: "Cancel",

        confirmButtonColor: "#2563eb",
        cancelButtonColor: "#ef4444",

        customClass: {
            popup: "rounded-2xl",
            title: "text-lg font-semibold",
            htmlContainer: "text-sm text-gray-500",
            confirmButton: "px-4 py-2 rounded-lg text-sm",
            cancelButton: "px-4 py-2 rounded-lg text-sm"
        }

    }).then((result) => {

        if (result.isConfirmed) {

            // Row Delete
            button.closest("tr").remove();

            updateCounts();
            applyFilters();

            // Success Alert
            Swal.fire({
                icon: "success",
                title: "Deleted!",
                text: "Record removed successfully.",
                width: "300px",
                padding: "1rem",
                showConfirmButton: false,
                timer: 1400
            });

        }

    });

}
</script>

<script>

let selectedProduct = "PureEstate";
let selectedStatus = "pending";

// -------------------- Product Filter --------------------

function filterProduct(product) {
    selectedProduct = product;
    selectedStatus = "pending";

    updateCounts();
    applyFilters();
}

// -------------------- Status Filter --------------------

function filterStatus(status) {
    selectedStatus = status;

    updateCounts();
    applyFilters();
}

// -------------------- Apply Filter --------------------

function applyFilters() {

    document.querySelectorAll("tbody tr").forEach(row => {

        const product = row.dataset.product;
        const status = row.dataset.status;

        const productMatch =
            selectedProduct === "all" ||
            product === selectedProduct;

        const statusMatch =
            selectedStatus === "all" ||
            status === selectedStatus;

        row.style.display = (productMatch && statusMatch) ? "" : "none";

    });

}

// -------------------- Update Counts --------------------

function updateCounts() {

    const rows = document.querySelectorAll("tbody tr");

    let pureEstate = 0;
    let builderPro = 0;
    let societyPro = 0;

    let pending = 0;
    let active = 0;
    let total = 0;

    rows.forEach(row => {

        const product = row.dataset.product;
        const status = row.dataset.status;

        // Product Count
        if(product === "PureEstate") pureEstate++;
        if(product === "BuilderPro") builderPro++;
        if(product === "SocietyPro") societyPro++;

        // Status Count (Selected Product)
        if(selectedProduct === "all" || product === selectedProduct){

            total++;

            if(status === "pending") pending++;
            if(status === "active") active++;

        }

    });

    // Product Chips
    document.getElementById("pureEstateCount").innerText = pureEstate;
    document.getElementById("builderProCount").innerText = builderPro;
    document.getElementById("societyProCount").innerText = societyPro;
    document.getElementById("totalProductCount").innerText = rows.length;

    // Status Chips
    document.getElementById("pendingCount").innerText = pending;
    document.getElementById("activeCount").innerText = active;
    document.getElementById("totalStatusCount").innerText = total;

}

// -------------------- Page Load --------------------

document.addEventListener("DOMContentLoaded", function () {

    updateCounts();
    applyFilters();

});

</script>


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