<x-app-layout>

    @include('riwayat.create')
    @include('riwayat.edit')
    @include('riwayat.delete')

    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('DATA RIWAYAT PENGADUAN') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-4xlxl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900 flex justify-between items-center">

                    @hasanyrole('Admin|GuruBK')
                        <div class="mb-3">
                            <button type="button" class="btn btn-outline-warning" data-bs-toggle="modal"
                                data-bs-target="#tambahModal">BERIKAN TINDAKAN</button>

                            @if ($riwayat->where('pengaduan.jenis_pengaduan', 'Karier')->count() > 0)
                                <a class="btn btn-outline-primary" href="{{ route('riwayat.print') }}" target="_blank">
                                    CETAK
                                </a>
                            @endif
                        </div>
                    @endhasanyrole

                </div>

                <x-table :tableId="'myTable_' . uniqid()">
                    <x-slot name="header">
                        <tr class="bg-gray-400 text-center">
                            <th>NO.</th>
                            <th>NIS</th>
                            <th>NAMA SISWA</th>
                            <th>KELAS</th>
                            <th>TANGGAL</th>
                            <th>JUDUL PENGADUAN</th>
                            <th>JENIS PENGADUAN BK</th>
                            <th>ISI KELUHAN</th>
                            <th>DOKUMENTASI</th>
                            <th>TINDAKAN BK</th>
                            <th>AKSI</th>
                        </tr>
                    </x-slot>

                    @php $num = 1; @endphp
                    @foreach ($riwayat as $data)
                        <tr class="text-center">
                            <td>{{ $num++ }}</td>
                            <td>{{ $data->pengaduan->user->siswa->nis }}</td>
                            <td>{{ $data->pengaduan->user->siswa->nama_siswa }}</td>
                            <td>{{ $data->pengaduan->user->siswa->kelas }}</td>
                            <td>{{ $data->pengaduan->tanggal }}</td>
                            <td>{{ $data->pengaduan->judul_pengaduan }}</td>
                            <td>{{ $data->pengaduan->jenis_pengaduan }}</td>
                            <td>{{ $data->pengaduan->isi_keluhan }}</td>
                            <td>
                                @if ($data->pengaduan->dokumentasi)
                                    <a class="text-blue-600 underline"
                                        href="{{ asset('storage/dokumentasi/' . $data->pengaduan->dokumentasi) }}"
                                        target="_blank">
                                        Lihat Dokumentasi
                                    </a>
                                @else
                                    -
                                @endif
                            </td>
                            <td>{{ $data->tindakan_bk }}</td>
                            <td>
                                <button tag="a" type="button" class="btn btn-outline-warning"
                                    data-bs-toggle="modal"
                                    data-bs-target="#exampleModal_{{ $data->id_riwayat_bk }}"><i
                                        class="fa-solid fa-pen-to-square"></i></button>
                                <button type="button" class="btn btn-outline-danger" data-bs-toggle="modal"
                                    data-bs-target="#hapusModal_{{ $data->id_riwayat_bk }}"><i
                                        class="fa-solid fa-trash-can"></i></button>
                            </td>
                        </tr>
                    @endforeach
                </x-table>

            </div>
        </div>
    </div>

    <script>
        function submitFilterForm() {
            document.getElementById("filterForm").submit();
        }
    </script>
</x-app-layout>
