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

<div class=" bg-slate-100 px-0 py-4 md:p-2 lg:p-6">

    <!-- Container -->
    <div class="mx-auto max-w-7xl">

        <!-- Header Card -->
        <div
            class="mb-6 flex flex-col gap-5 rounded-2xl border border-slate-200 bg-white p-6 shadow-sm lg:flex-row lg:items-center lg:justify-between">

    <!-- Title -->
    <div>

        <h1 class="text-3xl font-bold text-slate-800">
            Payroll List
        </h1>

        <p class="text-sm text-slate-500">
            Manage all payrolls from here
        </p>

    </div>


            <!-- Right -->
            <div class="flex flex-col gap-4 sm:flex-row sm:items-center">

                <!-- Search -->
                <div class="relative">

                    <i
                        class="ri-search-line absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>

                    <input type="text"
                        placeholder="Search Users..."
                        class="h-12 w-full rounded-xl border border-slate-300 bg-slate-50 pl-11 pr-4 text-sm text-slate-700 outline-none transition focus:border-indigo-500 focus:bg-white focus:ring-4 focus:ring-indigo-100 sm:w-72">

                </div>

                <!-- Filter -->
                <button id="openFilter"
                    class="flex h-12 items-center justify-center gap-2 rounded-xl border border-slate-300 bg-white px-5 text-sm font-semibold text-indigo-600 transition hover:bg-indigo-50">

                    <i class="ri-filter-3-line"></i>
                    Filter

                </button>

                <!-- Add Button -->
<!-- Add Button -->
<a href="add_payroll.php"
    class="flex h-12 items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-indigo-500 to-blue-600 px-6 text-sm font-semibold text-white shadow-lg transition hover:scale-[1.02]">

    <i class="ri-add-line text-lg"></i>
    Add Payroll

</a>

            </div>

        </div>

        <!-- Table Card -->
        <div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm">

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

               <table class="min-w-full whitespace-nowrap">

                    <!-- Head -->
                    <thead class="bg-slate-50">

                        <tr class="border-b border-slate-200">

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                               S.L.
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Payroll Month
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Department
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Employee Type
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Net Payable
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Status
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Generated Date
                            </th>

                            <th
                                class="px-6 py-5 text-left text-xs font-bold uppercase tracking-wider text-slate-500">
                                Actions
                            </th>

                        </tr>

                    </thead>

                    <!-- Body -->
                    <tbody class="divide-y divide-slate-100 bg-white">

    <!-- Row 1 -->
    <tr class="transition hover:bg-slate-50">

        <td class="px-6 py-5 font-semibold text-slate-700">
            01
        </td>

        <td class="px-6 py-5 font-medium text-slate-700">
            May 2026
        </td>

        <td class="px-6 py-5 text-slate-600">
            HR Department
        </td>

        <td class="px-6 py-5 text-slate-600">
            Full Time
        </td>

        <td class="px-6 py-5 font-bold text-green-600">
            ₹4,50,000
        </td>

        <td class="px-6 py-5">
            <span class="rounded-full bg-green-100 px-3 py-1 text-xs font-semibold text-green-700">
                Generated
            </span>
        </td>

        <td class="px-6 py-5 text-slate-600">
            21 May 2026
        </td>

        <td class="px-6 py-5">
            <div class="flex items-center gap-2">

                <a href="veiw_payroll.php">
                <button class="flex h-9 w-9 items-center justify-center rounded-lg bg-blue-50 text-blue-600 transition hover:bg-blue-100">
                    <i class="ri-eye-line"></i>
                </button>
                </a>

                <button class="flex h-9 w-9 items-center justify-center rounded-lg bg-violet-50 text-violet-600 transition hover:bg-violet-100">
                    <i class="ri-download-line"></i>
                </button>

               <button
    onclick="deleteRow(this)"
    class="w-9 h-9 rounded-lg bg-red-50 text-red-600 hover:bg-red-100 transition flex items-center justify-center">

    <i class="ri-delete-bin-line"></i>

</button>

            </div>
        </td>

    </tr>

    <!-- Row 2 -->
    <tr class="transition hover:bg-slate-50">

        <td class="px-6 py-5 font-semibold text-slate-700">
            02
        </td>

        <td class="px-6 py-5 font-medium text-slate-700">
            May 2026
        </td>

        <td class="px-6 py-5 text-slate-600">
            Development
        </td>

        <td class="px-6 py-5 text-slate-600">
            Contract
        </td>


        <td class="px-6 py-5 font-bold text-green-600">
            ₹3,20,000
        </td>

        <td class="px-6 py-5">
            <span class="rounded-full bg-yellow-100 px-3 py-1 text-xs font-semibold text-yellow-700">
                Pending
            </span>
        </td>

        <td class="px-6 py-5 text-slate-600">
            20 May 2026
        </td>

        <td class="px-6 py-5">
            <div class="flex items-center gap-2">

                <a href="veiw_payroll.php">
                <button class="flex h-9 w-9 items-center justify-center rounded-lg bg-blue-50 text-blue-600 transition hover:bg-blue-100">
                    <i class="ri-eye-line"></i>
                </button>
                </a>

                <button class="flex h-9 w-9 items-center justify-center rounded-lg bg-violet-50 text-violet-600 transition hover:bg-violet-100">
                    <i class="ri-download-line"></i>
                </button>

                <button
    onclick="deleteRow(this)"
    class="w-9 h-9 rounded-lg bg-red-50 text-red-600 hover:bg-red-100 transition flex items-center justify-center">

    <i class="ri-delete-bin-line"></i>

</button>

            </div>
        </td>

    </tr>

    <!-- Row 3 -->
    <tr class="transition hover:bg-slate-50">

        <td class="px-6 py-5 font-semibold text-slate-700">
            03
        </td>

        <td class="px-6 py-5 font-medium text-slate-700">
            April 2026
        </td>

        <td class="px-6 py-5 text-slate-600">
            Finance
        </td>

        <td class="px-6 py-5 text-slate-600">
            Full Time
        </td>


        <td class="px-6 py-5 font-bold text-green-600">
            ₹2,15,000
        </td>

        <td class="px-6 py-5">
            <span class="rounded-full bg-blue-100 px-3 py-1 text-xs font-semibold text-blue-700">
                Processing
            </span>
        </td>

        <td class="px-6 py-5 text-slate-600">
            18 Apr 2026
        </td>

        <td class="px-6 py-5">
            <div class="flex items-center gap-2">

                <a href="veiw_payroll.php">
                <button class="flex h-9 w-9 items-center justify-center rounded-lg bg-blue-50 text-blue-600 transition hover:bg-blue-100">
                    <i class="ri-eye-line"></i>
                </button>
                </a>

                <button class="flex h-9 w-9 items-center justify-center rounded-lg bg-violet-50 text-violet-600 transition hover:bg-violet-100">
                    <i class="ri-download-line"></i>
                </button>

<button
    onclick="deleteRow(this)"
    class="w-9 h-9 rounded-lg bg-red-50 text-red-600 hover:bg-red-100 transition flex items-center justify-center">

    <i class="ri-delete-bin-line"></i>

</button>

            </div>
        </td>

    </tr>

</tbody>

                </table>

            </div>

            <!-- Footer -->
            <div
                class="flex flex-col gap-4 border-t border-slate-200 px-6 py-5 sm:flex-row sm:items-center sm:justify-between">

                <!-- Left -->
                <p class="text-sm font-medium text-slate-500">
                    Showing 1 to 4 of 62 tasks
                </p>

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

                    <!-- Prev -->
                    <button
                        class="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white text-slate-500 transition hover:bg-slate-100">

                        <i class="ri-arrow-left-s-line"></i>

                    </button>

                    <!-- Active -->
                    <button
                        class="flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-r from-indigo-500 to-blue-600 font-semibold text-white shadow-md">

                        1

                    </button>

                    <!-- Pages -->
                    <button
                        class="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white font-semibold text-slate-600 transition hover:bg-slate-100">

                        2

                    </button>

                    <button
                        class="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white font-semibold text-slate-600 transition hover:bg-slate-100">

                        3

                    </button>

                    <button
                        class="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white font-semibold text-slate-600 transition hover:bg-slate-100">

                        4

                    </button>

                    <!-- Next -->
                    <button
                        class="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white text-slate-500 transition hover:bg-slate-100">

                        <i class="ri-arrow-right-s-line"></i>

                    </button>

                </div>

            </div>

        </div>

    </div>

</div>

<!-- Filter Sidebar -->
<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">
    <!-- Header -->
    <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>
    <!-- Body -->
     <div class="p-5 space-y-5 pb-28 overflow-y-auto">
        <!-- From Date -->
        <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>
        <!-- To Date -->
        <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>
        
        <!-- Department -->
<div class="w-full">

    <label class="mb-1 block text-sm font-medium text-slate-700">
        Department
    </label>

    <div class="relative">

        <div class="pointer-events-none absolute left-3 top-1/2 z-10 -translate-y-1/2 text-slate-400">

            <i class="ri-building-2-line"></i>

        </div>

        <select id="departmentSelect">

            <option value="">Select Department</option>

            <option value="HR">
                HR
            </option>

            <option value="Development">
                Development
            </option>

            <option value="Design">
                Design
            </option>

            <option value="Marketing">
                Marketing
            </option>

            <option value="Sales">
                Sales
            </option>

        </select>

    </div>

</div>


<!-- Employee Type -->
<div class="w-full">

    <label class="mb-1 block text-sm font-medium text-slate-700">
        Employee Type
    </label>

    <div class="relative">

        <div class="pointer-events-none absolute left-3 top-1/2 z-10 -translate-y-1/2 text-slate-400">

            <i class="ri-user-settings-line"></i>

        </div>

        <select id="employeeTypeSelect">

            <option value="">Select Employee Type</option>

            <option value="Full Time">
                Full Time
            </option>

            <option value="Part Time">
                Part Time
            </option>

            <option value="Intern">
                Intern
            </option>

            <option value="Freelancer">
                Freelancer
            </option>

            <option value="Contract">
                Contract
            </option>

        </select>

    </div>

</div>

    </div>
    <!-- Bottom Fixed Buttons -->
    <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">
            <!-- Reset Button -->
            <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>
            <!-- Apply Filter 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>
    <!-- Reason Modal -->
<div id="reasonModal"
    class="fixed inset-0 z-[9999] hidden items-center justify-center bg-black/50 p-4">

    <div class="bg-white w-full max-w-md rounded-2xl shadow-2xl overflow-hidden">

        <!-- Header -->
        <div class="flex items-center justify-between px-5 py-4 border-b border-gray-200">

            <h3 class="text-lg font-bold text-gray-800">
                Leave Reason
            </h3>

            <button onclick="closeReasonModal()"
                class="w-9 h-9 rounded-lg hover:bg-gray-100 flex items-center justify-center">

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

            </button>

        </div>

        <!-- Body -->
        <div class="p-5">

            <p id="reasonText" class="text-sm text-gray-600 leading-6">
            </p>

        </div>

        <!-- Footer -->
        <div class="px-5 py-4 border-t border-gray-200 flex justify-end">

            <button onclick="closeReasonModal()"
                class="px-4 py-2 rounded-lg bg-gradient-to-r from-blue-500 to-indigo-600 text-white text-sm font-medium">
                Close
            </button>

        </div>

    </div>

</div>
</div>


<script>

const employeeTypeSelect = new TomSelect("#employeeTypeSelect", {

    create: false,
    maxOptions: 10,
    placeholder: "Search Employee Type...",

    openOnFocus: false,
    dropdownParent: "body",

    closeAfterSelect:true,

    onType:function(str){

        if(str.trim().length > 0){

            this.open();

        }else{

            this.close();

        }

    },

    onItemAdd:function(){

        this.control_input.value = "";

        this.control_input.setAttribute(
            "readonly",
            "readonly"
        );

        this.blur();
        this.close();

    },

    onDropdownOpen:function(){

        this.control_input.removeAttribute(
            "readonly"
        );

    }

});


/* CONTROL STYLE */
employeeTypeSelect.control.classList.add(
    "flex",
    "items-center",
    "h-11",
    "w-full",
    "rounded-lg",
    "border",
    "border-gray-200",
    "bg-white",
    "pl-10",
    "pr-4",
    "text-sm",
    "text-gray-700"
);


/* DROPDOWN STYLE */
employeeTypeSelect.dropdown.classList.add(
    "z-[99999]",
    "overflow-hidden",
    "rounded-xl",
    "border",
    "border-gray-200",
    "bg-white",
    "shadow-xl"
);


/* INPUT STYLE */
employeeTypeSelect.control_input.classList.add(
    "w-full",
    "bg-transparent",
    "text-sm",
    "text-gray-700",
    "placeholder:text-gray-400",
    "focus:outline-none",
    "ml-2"
);


/* DROPDOWN POSITION FIX */
employeeTypeSelect.on("dropdown_open", function(){

    const controlRect =
        employeeTypeSelect.control.getBoundingClientRect();

    employeeTypeSelect.dropdown.style.position = "absolute";

    employeeTypeSelect.dropdown.style.width =
        controlRect.width + "px";

    employeeTypeSelect.dropdown.style.top =
        (controlRect.bottom + window.scrollY + 5) + "px";

    employeeTypeSelect.dropdown.style.left =
        (controlRect.left + window.scrollX) + "px";

    employeeTypeSelect.dropdown.style.zIndex = "99999";

});

</script>

<script>

const departmentSelect = new TomSelect("#departmentSelect", {

    create: false,
    maxOptions: 10,
    placeholder: "Search Department...",

    openOnFocus: false,
    dropdownParent: "body",

    closeAfterSelect:true,

    onType:function(str){

        if(str.trim().length > 0){

            this.open();

        }else{

            this.close();

        }

    },

    onItemAdd:function(){

        this.control_input.value = "";

        this.control_input.setAttribute(
            "readonly",
            "readonly"
        );

        this.blur();
        this.close();

    },

    onDropdownOpen:function(){

        this.control_input.removeAttribute(
            "readonly"
        );

    }

});


/* CONTROL STYLE */
departmentSelect.control.classList.add(
    "flex",
    "items-center",
    "h-11",
    "w-full",
    "rounded-lg",
    "border",
    "border-gray-200",
    "bg-white",
    "pl-10",
    "pr-4",
    "text-sm",
    "text-gray-700"
);


/* DROPDOWN STYLE */
departmentSelect.dropdown.classList.add(
    "z-[99999]",
    "overflow-hidden",
    "rounded-xl",
    "border",
    "border-gray-200",
    "bg-white",
    "shadow-xl"
);


/* INPUT STYLE */
departmentSelect.control_input.classList.add(
    "w-full",
    "bg-transparent",
    "text-sm",
    "text-gray-700",
    "placeholder:text-gray-400",
    "focus:outline-none",
    "ml-2"
);


/* DROPDOWN POSITION FIX */
departmentSelect.on("dropdown_open", function(){

    const controlRect =
        departmentSelect.control.getBoundingClientRect();

    departmentSelect.dropdown.style.position = "absolute";

    departmentSelect.dropdown.style.width =
        controlRect.width + "px";

    departmentSelect.dropdown.style.top =
        (controlRect.bottom + window.scrollY + 5) + "px";

    departmentSelect.dropdown.style.left =
        (controlRect.left + window.scrollX) + "px";

    departmentSelect.dropdown.style.zIndex = "99999";

});

</script>

<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 userRole = new TomSelect("#userRole", {

        create: false,
        maxOptions: 10,
        placeholder: "Search Assign To...",

        // Click karta open nai thay
        openOnFocus: false,

        // Dropdown body par render thay
        dropdownParent: "body",

        onType: function (str) {

            // Search hoy to open
            if (str.length > 0) {

                this.open();

            } else {

                this.close();

            }

        }

    });


    // Control Style
    userRole.control.classList.add(
        "flex",
        "items-center",
        "h-11",
        "w-full",
        "rounded-md",
        "border",
        "border-slate-200",
        "bg-slate-50",
        "pl-10",
        "pr-4",
        "text-sm",
        "text-slate-700"
    );


    // Dropdown Style
    userRole.dropdown.classList.add(
        "z-[99999]",
        "overflow-hidden",
        "rounded-md",
        "border",
        "border-slate-200",
        "bg-white",
        "shadow-xl"
    );


    // Input Style
    userRole.control_input.classList.add(
        "w-full",
        "bg-transparent",
        "text-sm",
        "text-slate-700",
        "placeholder:text-slate-400",
        "focus:outline-none",
        "ml-2"
    );


    // Dropdown Position Fix
    userRole.on("dropdown_open", function () {

        const controlRect =
            userRole.control.getBoundingClientRect();

        userRole.dropdown.style.position = "absolute";

        userRole.dropdown.style.width =
            controlRect.width + "px";

        userRole.dropdown.style.top =
            (controlRect.bottom + window.scrollY + 5) + "px";

        userRole.dropdown.style.left =
            (controlRect.left + window.scrollX) + "px";

        userRole.dropdown.style.zIndex = "99999";

    });

</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) {

            button.closest("tr").remove();

            Swal.fire({

                icon: "success",
                title: "Deleted!",
                text: "Record removed successfully.",

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

                showConfirmButton: false,
                timer: 1400

            });

        }

    });

}

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