@extends('admin.layouts.app')

@section('content')
    <div class="bg-gray-100 min-h-full p-4">

        @if(session('success'))
            <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
                {{ session('success') }}
            </div>
        @endif

        <div class="bg-white p-4 shadow-sm border border-gray-200">
            <!-- Header -->
            <div class="bg-[#ff9800] text-white px-3 py-1.5 font-bold text-sm flex items-center shadow-sm mb-4">
                <i class="fa-solid fa-list mr-2"></i> List of Leave Type
            </div>

            <!-- Form for Bulk Actions -->
            <form action="#" method="POST" id="leaveListForm">
                @csrf

                <div class="overflow-x-auto">
                    <table class="w-full border-collapse border border-gray-300 text-xs">
                        <thead>
                            <tr class="bg-[#ff7043] text-white text-left">
                                <th class="border border-gray-300 px-3 py-2 w-16 text-center">Select</th>
                                <th class="border border-gray-300 px-3 py-2">Leave Code</th>
                                <th class="border border-gray-300 px-3 py-2">Leave Name</th>
                                <th class="border border-gray-300 px-3 py-2">Include Weekly off</th>
                                <th class="border border-gray-300 px-3 py-2">Include Holiday</th>
                                <th class="border border-gray-300 px-3 py-2">Leave Type</th>
                                <th class="border border-gray-300 px-3 py-2 w-20 text-center">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($leaveTypes as $leave)
                                <tr class="hover:bg-gray-50 border-b border-gray-200">
                                    <td class="border border-gray-300 px-3 py-2 text-center">
                                        <input type="checkbox" name="selected_leaves[]" value="{{ $leave->id }}"
                                            class="cursor-pointer">
                                    </td>
                                    <td class="border border-gray-300 px-3 py-2 font-bold text-[#007bff]">
                                        {{ $leave->leave_code }}
                                    </td>
                                    <td class="border border-gray-300 px-3 py-2">{{ $leave->leave_name }}</td>
                                    <td class="border border-gray-300 px-3 py-2 font-bold text-gray-700">
                                        {{ $leave->include_weekly_off ? 'Yes' : 'No' }}
                                    </td>
                                    <td class="border border-gray-300 px-3 py-2 font-bold text-gray-700">
                                        {{ $leave->include_holiday ? 'Yes' : 'No' }}
                                    </td>
                                    <td class="border border-gray-300 px-3 py-2 font-bold text-gray-700">
                                        {{ $leave->leave_type }}
                                    </td>
                                    <td class="border border-gray-300 px-3 py-2 text-center">
                                        <a href="{{ route('leave-types.edit', $leave->id) }}"
                                            class="text-blue-500 hover:text-blue-700 mr-2" title="Edit">
                                            <i class="fa-solid fa-pen-to-square"></i>
                                        </a>
                                        <form action="{{ route('leave-types.destroy', $leave->id) }}" method="POST"
                                            class="inline-block"
                                            onsubmit="return confirm('Are you sure you want to delete this Leave Type?');">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="text-red-500 hover:text-red-700" title="Delete">
                                                <i class="fa-solid fa-trash"></i>
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="7"
                                        class="border border-gray-300 px-3 py-4 text-center text-gray-500 font-bold">
                                        No leave types found.
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>

                <!-- Action Buttons -->
                <div class="mt-8 flex justify-center space-x-2">
                    <a href="{{ route('leave-types.create') }}"
                        class="bg-[#4caf50] hover:bg-[#43a047] text-white px-6 py-1.5 rounded shadow text-sm font-semibold transition">Add</a>
                    <button type="button"
                        class="bg-[#dc3545] hover:bg-[#c82333] text-white px-6 py-1.5 rounded shadow text-sm font-semibold transition">Delete</button>
                    <a href="{{ route('admin.dashboard') }}"
                        class="bg-[#dc3545] hover:bg-[#c82333] text-white px-6 py-1.5 rounded shadow text-sm font-semibold transition">Close</a>
                </div>

            </form>
        </div>
    </div>
@endsection