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

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

    <!-- Header -->
    <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">

        <!-- Title -->
        <div>

            <h1 class="text-2xl font-bold text-gray-800">
                Attendance
            </h1>

            <p class="text-sm text-gray-500">
                Manage employee attendance records
            </p>

        </div>

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

            <!-- Date -->
            <div class="relative w-full sm:w-auto">

                <input type="date"
                    class="h-11 w-full rounded-xl border border-gray-200 px-4 text-sm text-gray-600 outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">

            </div>

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

    <!-- Hidden File Input -->
    <input type="file" id="attendanceUpload" class="hidden">

    <!-- Upload Button -->
    <button id="uploadBtn"
        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-upload-2-line"></i>
        Upload

    </button>

    <!-- Export -->
    <button
        class="px-4 py-2.5 rounded-xl border border-gray-200 bg-white hover:bg-gray-50 transition-all duration-300 text-sm text-gray-700 flex items-center gap-2">

        <i class="ri-download-2-line"></i>
        Export

    </button>

</div>

        </div>

    </div>

    <!-- Stats Cards -->
    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-5">

        <!-- Present -->
        <div class="bg-green-50 border border-green-100 rounded-xl p-5">

            <p class="text-sm font-medium text-green-600">
                Present
            </p>

            <h2 class="text-3xl font-bold text-gray-800 mt-2">
                28
            </h2>

        </div>

        <!-- Absent -->
        <div class="bg-red-50 border border-red-100 rounded-xl p-5">

            <p class="text-sm font-medium text-red-500">
                Absent
            </p>

            <h2 class="text-3xl font-bold text-gray-800 mt-2">
                4
            </h2>

        </div>

        <!-- Half Day -->
        <div class="bg-yellow-50 border border-yellow-100 rounded-xl p-5">

            <p class="text-sm font-medium text-yellow-600">
                Half Day
            </p>

            <h2 class="text-3xl font-bold text-gray-800 mt-2">
                2
            </h2>

        </div>

        <!-- On Leave -->
        <div class="bg-orange-50 border border-orange-100 rounded-xl p-5">

            <p class="text-sm font-medium text-orange-500">
                On Leave
            </p>

            <h2 class="text-3xl font-bold text-gray-800 mt-2">
                3
            </h2>

        </div>

    </div>

    <!-- Table Card -->
<div class="bg-white rounded-lg border border-gray-200 shadow-sm overflow-hidden max-w-full">

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

            <table class="w-full">

                <!-- Table Head -->
                <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">
                            SR.No
                        </th>

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

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

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

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

                    </tr>

                </thead>

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

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

                        <td class="px-6 py-4 align-middle">
                            01
                        </td>

                        <td class="px-6 py-4 text-sm text-gray-600">
                           04Summary.xls
                        </td>

                        <td class="px-6 py-4 text-sm text-gray-600">
                           April 1, 2026
                        </td>


                        <td class="px-6 py-4 align-middle">

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

                                Uploaded

                            </span>

                        </td>

                        <td class="px-6 py-4 align-middle">

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

                                <!-- Delete -->
                                <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="px-4 py-4 border-t border-gray-100 flex flex-col md:flex-row items-center justify-between gap-4">

            <!-- Left -->
            <p class="text-sm text-gray-500">
                Showing 1 to 4 of 37 attendance records
            </p>

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

                <button
                    class="w-9 h-9 rounded-xl border border-blue-100 text-blue-500 hover:bg-gradient-to-r hover:from-blue-500 hover:to-indigo-600 hover:text-white transition-all duration-300">

                    <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-xl border border-blue-100 text-blue-600 hover:bg-gradient-to-r hover:from-blue-500 hover:to-indigo-600 hover:text-white transition-all duration-300">
                    2
                </button>

                <button
                    class="w-9 h-9 rounded-xl border border-blue-100 text-blue-600 hover:bg-gradient-to-r hover:from-blue-500 hover:to-indigo-600 hover:text-white transition-all duration-300">
                    3
                </button>

                <button
                    class="w-9 h-9 rounded-xl border border-blue-100 text-blue-500 hover:bg-gradient-to-r hover:from-blue-500 hover:to-indigo-600 hover:text-white transition-all duration-300">

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

                </button>

            </div>

        </div>

    </div>

</div>

<script>

function deleteRow(button) {

    Swal.fire({

        title: "Delete Record?",
        text: "This attendance record 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>
<script>

    // Open File Picker
    document.getElementById("uploadBtn").addEventListener("click", () => {

        document.getElementById("attendanceUpload").click();

    });

    // File Upload Event
    document.getElementById("attendanceUpload").addEventListener("change", function () {

        const file = this.files[0];

        if (file) {

            Swal.fire({

                icon: "success",
                title: "Uploaded!",
                text: file.name + " uploaded successfully.",

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

                showConfirmButton: false,
                timer: 1800

            });

            console.log("Uploaded File:", file);

            // You can add AJAX / API upload here

        }

    });

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