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

<div class="p-4 lg:p-6">

    <!-- Header -->
    <div class="max-w-7xl mx-auto mb-6">

        <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">

            <div>

                <h1 class="text-3xl font-bold tracking-tight text-slate-800">
                    Add Company
                </h1>

            </div>

            <a href="master.php"
                class="inline-flex items-center gap-2 h-10 px-5 rounded-2xl bg-white border border-slate-200 text-sm font-medium text-slate-700 hover:shadow-md transition-all">

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

                Back

            </a>

        </div>

    </div>

    <!-- Grid -->
    <div class="max-w-7xl mx-auto grid grid-cols-1 xl:grid-cols-12 gap-6">

        <!-- Left Form -->
        <div class="xl:col-span-4">

            <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden sticky top-5">

                <!-- Card Header -->
                <div class="px-6 py-5 border-b border-slate-100">

                    <h2 class="text-lg font-semibold text-slate-800">
                        Add Company 
                    </h2>

                </div>

                <!-- Form -->
                <form id="companyForm" class="p-6 space-y-5">

                    <!-- City -->
                    <div>

                        <label class="block text-sm font-medium text-slate-600 mb-2">
                           Company Name
                        </label>

                        <div class="relative">

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

                            <input
                                type="text"
                                id="company"
                                placeholder="Enter Company"
                                class="w-full h-11 rounded-2xl border border-slate-200 bg-slate-50 focus:bg-white focus:border-indigo-500 pl-11 pr-4 text-sm outline-none transition-all">

                        </div>

                    </div>


                    <!-- Submit -->
                    <div class="flex justify-end pt-2">

                        <button
                            type="submit"
                            class="inline-flex items-center gap-2 h-10 px-5 rounded-xl bg-gradient-to-r from-indigo-600 to-blue-500 text-white text-sm font-medium shadow-lg shadow-indigo-100 hover:opacity-95 transition-all">

                            <i class="ri-save-line"></i>

                            Save

                        </button>

                    </div>

                </form>

            </div>

        </div>

        <!-- Right Table -->
        <div class="xl:col-span-8">

            <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden">

                <!-- Table Header -->
                <div class="px-6 py-5 border-b border-slate-100">

                    <div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4">

                        <div>

                            <h2 class="text-lg font-semibold text-slate-800">
                                Company List
                            </h2>

                        </div>

                    </div>

                </div>

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

                    <table class="w-full min-w-[750px]">

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

                            <tr>

                                <th class="px-6 py-4 text-left text-xs font-semibold uppercase text-slate-500">
                                    Sr.no
                                </th>

                                <th class="px-6 py-4 text-left text-xs font-semibold uppercase text-slate-500">
                                    Company
                                </th>

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

                            </tr>

                        </thead>

                        <tbody class="divide-y divide-slate-100">

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

                                <td class="px-6 py-4 text-sm font-medium text-slate-700">
                                    01
                                </td>

                                <td class="px-6 py-4">
                                    Code champ
                                </td>


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

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

                                        <!-- Edit -->
                                        <button
                                            class="w-10 h-10 rounded-xl bg-blue-50 text-blue-600 hover:bg-blue-100 transition flex items-center justify-center">

                                            <i class="ri-edit-line"></i>

                                        </button>

                                        <button
                                            onclick="deleteRow(this)"
                                            class="w-10 h-10 rounded-xl bg-red-50 text-red-600 hover:bg-red-100 transition flex items-center justify-center">
                                        
                                            <i class="ri-delete-bin-6-line"></i>
                                        
                                        </button>

                                    </div>

                                </td>

                            </tr>

                        </tbody>

                    </table>

                </div>

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

                    <p class="text-sm text-slate-500">
                        Showing 1 to 10 of 24 entries
                    </p>

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

                        <button
                            class="w-9 h-9 rounded-xl border border-slate-200 hover:bg-slate-50 flex items-center justify-center">

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

                        </button>

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

                        <button
                            class="w-9 h-9 rounded-xl border border-slate-200 hover:bg-slate-50 text-sm">
                            2
                        </button>

                        <button
                            class="w-9 h-9 rounded-xl border border-slate-200 hover:bg-slate-50 flex items-center justify-center">

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

                        </button>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>



<script>

    function deleteRow(button) {

        Swal.fire({

            title: 'Delete ?',
            text: "This record will be deleted permanently.",
            icon: 'warning',

            showCancelButton: true,

            confirmButtonColor: '#ef4444',
            cancelButtonColor: '#64748b',

            confirmButtonText: 'Delete',
            cancelButtonText: 'Cancel',

            width: '320px',

            customClass: {

                popup: 'rounded-2xl',
                confirmButton: 'swal-btn',
                cancelButton: 'swal-btn'

            }

        }).then((result) => {

            if (result.isConfirmed) {

                const row =
                    button.closest('tr');

                row.remove();

                Swal.fire({

                    icon: 'success',
                    title: 'Deleted!',
                    text: 'Company deleted successfully.',

                    timer: 1500,
                    showConfirmButton: false,

                    width: '300px',

                    customClass: {
                        popup: 'rounded-2xl'
                    }

                });

            }

        });

    }

</script>


<script>

document.getElementById("companyForm").addEventListener("submit", function(e) {

    e.preventDefault();

    const company = document.getElementById("company");

    // RESET BORDER
    company.classList.remove(
        "border-red-500",
        "focus:border-red-500"
    );

    // EMPTY VALIDATION
    if (company.value.trim() === "") {

        company.classList.add(
            "border-red-500",
            "focus:border-red-500"
        );

        company.focus();

        Swal.fire({

            icon: 'warning',
            title: 'Company Required',
            text: 'Please enter company name',

            width: '320px',

            confirmButtonColor: '#4f46e5',

            didOpen: () => {

                document.querySelector('.swal2-popup').style.borderRadius = '10px';

                document.querySelector('.swal2-confirm').style.borderRadius = '8px';

            }

        });

        return;

    }

    // MIN LENGTH VALIDATION
    if (company.value.trim().length < 3) {

        company.classList.add(
            "border-red-500",
            "focus:border-red-500"
        );

        Swal.fire({

            icon: 'warning',
            title: 'Invalid Company',
            text: 'Company name must be at least 3 characters',

            width: '320px',

            confirmButtonColor: '#4f46e5'

        });

        return;

    }

    // SUCCESS
    Swal.fire({

        icon: 'success',
        title: 'Success!',
        text: 'Company saved successfully.',

        timer: 1500,
        showConfirmButton: false,

        width: '300px',

        didOpen: () => {

            document.querySelector('.swal2-popup').style.borderRadius = '10px';

        }

    });

    // RESET FORM
    document.getElementById("companyForm").reset();

});

</script>


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