<x-app-layout>

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

    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('DATA PENANGANAN PSIKOLOG') }}
        </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">
                    @hasrole('Admin|Spesialis')
                        <button type="button" class="btn btn-outline-warning mb-4" data-bs-toggle="modal"
                            data-bs-target="#tambahModal">TAMBAH DATA</button>
                    @endhasrole
                </div>
                <x-table :tableId="'myTable_' . uniqid()">
                    <x-slot name="header">
                        <tr class="bg-gray-400 text-center">
                            <th>NO.</th>
                            <th>TANGGAL</th>
                            <th>NAMA SISWA</th>
                            <th>KESIMPULAN SEMENTARA</th>
                            <th>PENANGANAN</th>
                            <th>REKOMENDASI</th>
                            <th>STATUS</th>
                            <th>AKSI</th>
                        </tr>
                    </x-slot>

                    @php $num = 1; @endphp
                    @foreach ($psikolog as $data)
                        <tr class="text-center">
                            <td>{{ $num++ }}</td>
                            <td>{{ $data->tanggal }}</td>
                            <td>{{ $data->siswa->nama_siswa }}</td>
                            <td>{{ $data->kesimpulan_sementara }}</td>
                            <td>{{ $data->penanganan }}</td>
                            <td>
                                @if ($data->rekomendasi_lanjut)
                                    <a class="text-blue-600 underline"
                                        href="{{ asset('storage/rekomendasi_lanjut/' . $data->rekomendasi_lanjut) }}"
                                        target="_blank">
                                        Lihat Surat
                                    </a>
                                @else
                                    -
                                @endif
                            </td>
                            <td>
                                @if ($data->status == 0)
                                    <span class="badge rounded-pill text-bg-warning">Proses</span>
                                @elseif ($data->status == 1)
                                    <span class="badge rounded-pill text-bg-success">Selesai</span>
                                @endif
                            </td>
                            <td>
                                <button tag="a" type="button" class="btn btn-outline-warning"
                                    data-bs-toggle="modal" data-bs-target="#exampleModal_{{ $data->id_psikolog }}"><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_psikolog }}"><i
                                        class="fa-solid fa-trash-can"></i></button>
                                </a>
                                <div class="p-2">
                                    @if ($data->status == 0)
                                        <form action="{{ route('psikolog.verify', $data->id_psikolog) }}"
                                            method="POST">
                                            @csrf
                                            @method('PATCH')
                                            <button class="btn btn-outline-primary">
                                                Selesai Sesi
                                            </button>
                                        </form>
                                    @else
                                        <form action="{{ route('psikolog.unverify', $data->id_psikolog) }}"
                                            method="POST">
                                            @csrf
                                            @method('PATCH')
                                            <button class="btn btn-outline-danger">
                                                Mulai Sesi
                                            </button>
                                        </form>
                                    @endif
                                </div>
                            </td>
                        </tr>
                    @endforeach
                </x-table>
            </div>
        </div>
    </div>
</x-app-layout>
