<x-layout>
            <x-slot:title>{{ $title }}</x-slot>
            <!-- Tombol Tambah Data -->
            <button data-modal-target="tambahKriteriaModal" data-modal-toggle="tambahKriteriaModal" class="text-white bg-[#388E3C] hover:bg-green-900 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-5">
                Tambah Kriteria
            </button>
           {{-- Flex Container for the Table --}}
           <div class="flex items-center justify-center">
               {{-- Tabel Data Kriteria --}}
               

               <div class="overflow-x-auto w-full">
                
                   <table class="w-full text-sm text-left text-[#1B5E20] border border-[#C8E6C9]">
                        <thead class="text-xs text-white uppercase bg-[#388E3C]">
                           <tr>
                                <th class="px-6 py-3" scope="col">ID</th>
                                <th class="px-6 py-3" scope="col">Kode</th>
                                <th class="px-6 py-3" scope="col">Nama Kriteria</th>
                                <th class="px-6 py-3" scope="col">Jenis</th>
                                <th class="px-4 py-3" scope="col">Bobot</th>
                                <th class="px-10 py-3" scope="col">Aksi</th>
                           </tr>
                       </thead>
                       <tbody>
                        @forelse ($kriterias as $index => $item)
                        <tr class="bg-[#f9f9f9] border-b border-[#ddd] hover:bg-[#e2e2e2]">
                            <td class="px-6 py-4">{{ $index + 1 }}</td>
                            <td class="px-6 py-4">{{ $item->kode_kriteria }}</td>
                            <td class="px-6 py-4">{{ $item->nama_kriteria }}</td>
                            <td class="px-6 py-4">{{ $item->jenis }}</td>
                            <td class="px-6 py-4">{{ $item->bobot }}</td>
                            <td class="px-4 py-3">
                                <button type="button">
                                <a href="{{ route('admin.subkriteria.index', $item->id) }}"
                                class="bg-white border border-green-600 p-1 rounded cursor-pointer
                                        text-green-600 hover:bg-green-600 hover:text-white transition-colors inline-flex items-center justify-center">
                                    <svg class="w-6 h-6"
                                        xmlns="http://www.w3.org/2000/svg"
                                        fill="currentColor"
                                        viewBox="0 0 24 24">
                                        <path fill-rule="evenodd"
                                            d="M4.998 7.78C6.729 6.345 9.198 5 12 5c2.802 0 5.27 1.345 7.002 2.78a12.713 12.713 0 0 1 2.096 2.183c.253.344.465.682.618.997.14.286.284.658.284 1.04s-.145.754-.284 1.04a6.6 6.6 0 0 1-.618.997 12.712 12.712 0 0 1-2.096 2.183C17.271 17.655 14.802 19 12 19c-2.802 0-5.27-1.345-7.002-2.78a12.712 12.712 0 0 1-2.096-2.183 6.6 6.6 0 0 1-.618-.997C2.144 12.754 2 12.382 2 12s.145-.754.284-1.04c.153-.315.365-.653.618-.997A12.714 12.714 0 0 1 4.998 7.78ZM12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"
                                            clip-rule="evenodd"/>
                                    </svg>
                                </a>
                                </button>
                                <!-- Tombol Edit -->
                                <button type="button"
                                    data-modal-target="editKriteriaModal{{ $item->id }}"
                                    data-modal-toggle="editKriteriaModal{{ $item->id }}"
                                    class="bg-white border border-blue-600 p-1 rounded cursor-pointer 
                                        text-blue-600 hover:bg-blue-600 hover:text-white transition-colors 
                                        inline-flex items-center justify-center">
                                    <svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
                                        <path fill-rule="evenodd"
                                            d="M11.32 6.176H5c-1.105 0-2 .949-2 2.118v10.588C3 20.052 3.895 21 5 21h11c1.105 0 2-.948 2-2.118v-7.75l-3.914 4.144A2.46 2.46 0 0 1 12.81 16l-2.681.568c-1.75.37-3.292-1.263-2.942-3.115l.536-2.839c.097-.512.335-.983.684-1.352l2.914-3.086Z"
                                            clip-rule="evenodd" />
                                        <path fill-rule="evenodd"
                                            d="M19.846 4.318a2.148 2.148 0 0 0-.437-.692 2.014 2.014 0 0 0-.654-.463 1.92 1.92 0 0 0-1.544 0 2.014 2.014 0 0 0-.654.463l-.546.578 2.852 3.02.546-.579a2.14 2.14 0 0 0 .437-.692 2.244 2.244 0 0 0 0-1.635ZM17.45 8.721 14.597 5.7 9.82 10.76a.54.54 0 0 0-.137.27l-.536 2.84c-.07.37.239.696.588.622l2.682-.567a.492.492 0 0 0 .255-.145l4.778-5.06Z"
                                            clip-rule="evenodd" />
                                    </svg>
                                </button>
                                <!-- Trigger Button -->
                                <button type="button"
                                    data-modal-target="hapusModal{{ $item->id }}"
                                    data-modal-toggle="hapusModal{{ $item->id }}"
                                    class="bg-white border border-red-600 p-1 rounded cursor-pointer
                                        text-red-600 hover:bg-red-600 hover:text-white transition-colors"
                                >
                                    <svg class="w-6 h-6" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
                                        <path fill-rule="evenodd"
                                            d="M8.586 2.586A2 2 0 0 1 10 2h4a2 2 0 0 1 2 2v2h3a1 1 0 1 1 0 2v12a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V8a1 1 0 0 1 0-2h3V4a2 2 0 0 1 .586-1.414ZM10 6h4V4h-4v2Zm1 4a1 1 0 1 0-2 0v8a1 1 0 1 0 2 0v-8Zm4 0a1 1 0 1 0-2 0v8a1 1 0 1 0 2 0v-8Z"
                                            clip-rule="evenodd" />
                                    </svg>
                                </button>
                                
                          </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="5" class="text-center py-4 text-gray-500">Tidak ada data kriteria.</td>
                        </tr>
                    @endforelse
                       </tbody>
                   </table>
               </div>
               
           </div>
           @if(session('success'))
                <div id="success-alert" class="flex items-center p-4 mb-4 text-sm text-green-800 border border-green-300 rounded-lg bg-green-50 dark:bg-gray-800 dark:text-green-400 dark:border-green-800 mt-4" role="alert">
                    <svg class="shrink-0 inline w-4 h-4 me-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
                        <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
                    </svg>
                    <span class="sr-only">Info</span>
                    <div>
                        <span class="font-medium">{{ session('success') }}</span> 
                    </div>
                </div>

                <script>
                    setTimeout(function() {
                        // Fade out the success alert after 3 seconds
                        document.getElementById('success-alert').style.transition = 'opacity 1s';
                        document.getElementById('success-alert').style.opacity = '0';
                        
                        // After fade out, remove the alert from the DOM
                        setTimeout(function() {
                            document.getElementById('success-alert').remove();
                        }, 1000); // Wait for fade-out transition
                    }, 2000); // 3 seconds delay before fading out
                </script>
            @endif
            
            @if(session('error'))
                <div id="error-alert" class="flex items-center p-4 mb-4 text-sm text-red-800 border border-red-300 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400 dark:border-red-800 mt-4" role="alert">
                    <svg class="shrink-0 inline w-4 h-4 me-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
                        <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
                    </svg>
                    <span class="sr-only">Error</span>
                    <div>
                        <span class="font-medium">{{ session('error') }}</span> 
                    </div>
                </div>

                <script>
                    setTimeout(function() {
                        const alert = document.getElementById('error-alert');
                        alert.style.transition = 'opacity 1s';
                        alert.style.opacity = '0';
                        setTimeout(() => alert.remove(), 1000);
                    }, 2000);
                </script>
            @endif

      

   <!-- Modal Tambah Kriteria -->
<div id="tambahKriteriaModal" tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 w-full inset-0 h-[calc(100%-1rem)] max-h-full  items-center justify-center ">
    <div class="relative p-4 w-full max-w-2xl max-h-full">
        <!-- Modal content -->
        <div class="relative bg-[#388E3C] rounded-lg shadow">
            <!-- Header -->
            <div class="flex items-center justify-between p-4 border-b rounded-t border-gray-600">
                <h3 class="text-xl font-semibold text-white">
                    Tambah Kriteria
                </h3>
                <button type="button" class="text-gray-400 bg-transparent hover:text-white" data-modal-hide="tambahKriteriaModal">
                    <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
                    </svg>
                </button>
            </div>

                <!-- Form -->
                <form action="{{ route('kriteria.store') }}" method="POST" class="p-6 space-y-6">
                    @csrf
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label for="kode_kriteria" class="block mb-2 text-sm font-medium text-white">Kode Kriteria</label>
                            <input type="text" id="kode_kriteria" name="kode_kriteria" required class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5" placeholder="C1">
                        </div>
                        <div>
                            <label for="nama_kriteria" class="block mb-2 text-sm font-medium text-white">Nama Kriteria</label>
                            <input type="text" id="nama_kriteria" name="nama_kriteria" required class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5" placeholder="Contoh: Curah Hujan">
                        </div>
                        <div>
                            <label for="jenis" class="block mb-2 text-sm font-medium text-white">Jenis</label>
                            <select id="jenis" name="jenis" required class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5">
                                <option value="">-- Pilih Jenis --</option>
                                <option value="benefit">Benefit</option>
                                <option value="cost">Cost</option>
                            </select>
                        </div>
                        <div>
                            <label for="bobot" class="block mb-2 text-sm font-medium text-white">Bobot</label>
                            <input type="number" step="0.01" id="bobot" name="bobot" required class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5" placeholder="Contoh: 0.25">
                        </div>
                    </div>
                    <button type="submit" class="text-white bg-green-900 hover:bg-green-950 font-medium rounded-lg text-sm px-5 py-2.5 text-center">
                        Simpan
                    </button>
                </form>
            </div>
        </div>
    </div>
        @foreach ($kriterias as $item)
        <div id="hapusModal{{ $item->id }}" tabindex="-1" aria-hidden="true"
            class="hidden fixed top-0 left-0 right-0 z-50 w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-modal md:h-full">
            <div class="relative w-full max-w-md h-full md:h-auto">
                <div class="relative bg-[#388E3C] rounded-lg shadow">
                    <div class="p-6 text-center">
                        <svg class="mx-auto mb-4 w-12 h-12 text-gray-200"
                            fill="none" stroke="currentColor" viewBox="0 0 24 24"
                            xmlns="http://www.w3.org/2000/svg">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M6 18L18 6M6 6l12 12"></path>
                        </svg>
                        <h3 class="mb-5 text-lg font-normal text-white">
                            Yakin ingin menghapus <strong>{{ $item->nama_kriteria }}</strong>?
                        </h3>
                        <form action="{{ route('kriteria.destroy', $item->id) }}" method="POST">
                            @csrf
                            @method('DELETE')
                            <button type="submit"
                                class="text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300
                                    dark:focus:ring-red-800 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center mr-2">
                                Ya, Hapus
                            </button>
                            <button type="button"
                                class="text-gray-900 bg-white hover:bg-gray-300 focus:ring-4 focus:outline-none focus:ring-gray-200
                                    rounded-lg border border-gray-200 text-sm font-medium px-5 py-2.5 hover:text-gray-900
                                    focus:z-10"
                                data-modal-hide="hapusModal{{ $item->id }}">
                                Batal
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        @endforeach
        @foreach ($kriterias as $item)
            <div id="editKriteriaModal{{ $item->id }}" tabindex="-1" aria-hidden="true"
                class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 w-full inset-0 h-[calc(100%-1rem)] max-h-full  items-center justify-center bg-black/30">
                <div class="relative p-4 w-full max-w-2xl max-h-full">
                    <div class="relative bg-[#388E3C] rounded-lg shadow">
                        <!-- Header -->
                        <div class="flex items-center justify-between p-4 border-b rounded-t border-gray-600">
                            <h3 class="text-xl font-semibold text-white">
                                Edit Kriteria
                            </h3>
                            <button type="button" class="text-gray-400 bg-transparent hover:text-white"
                                data-modal-hide="editKriteriaModal{{ $item->id }}">
                                <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd"
                                        d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
                                        clip-rule="evenodd" />
                                </svg>
                            </button>
                        </div>
                        <!-- Form Edit -->
                        <form action="{{ route('kriteria.update', $item->id) }}" method="POST" class="p-6 space-y-6">
                            @csrf
                            @method('PUT')
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                                <div>
                                    <label for="kode_kriteria{{ $item->id }}" class="block mb-2 text-sm font-medium text-white">Kode Kriteria</label>
                                    <input type="text" id="kode_kriteria{{ $item->id }}" name="kode_kriteria" value="{{ $item->kode_kriteria }}" required
                                        class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5 ">
                                </div>
                                <div>
                                    <label for="nama_kriteria{{ $item->id }}" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Nama Kriteria</label>
                                    <input type="text" id="nama_kriteria{{ $item->id }}" name="nama_kriteria" value="{{ $item->nama_kriteria }}" required
                                        class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5 ">
                                </div>
                                <div>
                                    <label for="jenis{{ $item->id }}" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Jenis</label>
                                    <select id="jenis{{ $item->id }}" name="jenis" required
                                        class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5 ">
                                        <option value="benefit" {{ $item->jenis == 'Benefit' ? 'selected' : '' }}>Benefit</option>
                                        <option value="cost" {{ $item->jenis == 'Cost' ? 'selected' : '' }}>Cost</option>
                                    </select>
                                </div>
                                <div>
                                    <label for="bobot{{ $item->id }}" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Bobot</label>
                                    <input type="number" step="0.01" id="bobot{{ $item->id }}" name="bobot" value="{{ $item->bobot }}" required
                                        class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5 ">
                                </div>
                            </div>
                            <button type="submit" class="text-white bg-green-900 hover:bg-blue-950 font-medium rounded-lg text-sm px-5 py-2.5 text-center">
                                Simpan Perubahan
                            </button>
                        </form>
                    </div>
                </div>
            </div>
            @endforeach

</x-layout>