<x-app-layout>

    @include('pelanggaran.create')
    @include('pelanggaran.edit')
    @include('pelanggaran.delete')
    @include('pelanggaran.detail')

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

    <div class="py-12">
        <div class="max-w-7xl 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">

                    @hasanyrole('Admin|GuruBK')
                    <button type="button" class="btn btn-outline-warning mb-4" data-bs-toggle="modal"
                        data-bs-target="#tambahModal">
                        TAMBAH DATA
                    </button>
                    @endhasanyrole

                    @hasanyrole('Siswa')
                    <center>
                        <b>POINT PELANGGARAN TATA TERTIB SISWA<br>SMKN 1 BOJONGPICUNG</b>
                    </center>
                    @endhasanyrole

                    <x-table :tableId="'myTable_' . uniqid()">
                        <x-slot name="header">
                            <tr class="bg-gray-400 text-center">
                                <th>NO</th>
                                <th>NAMA SISWA</th>
                                <th>KELAS</th>
                                <th>TANGGAL</th>
                                <th>KETERANGAN</th>
                                <th>AKSI</th>
                            </tr>
                        </x-slot>

                        @php $num = 1; @endphp
                        @foreach ($pelanggarans as $data)
                        <tr class="text-center">
                            <td>{{ $num++ }}</td>
                            <td>{{ $data->siswa->nama_siswa }}</td>
                            <td>{{ $data->siswa->kelas }}</td>
                            <td>{{ $data->tanggal }}</td>
                            <td>
                                @php
                                $ket = '';

                                if ($data->saldo_pelanggaran >= 90 && $data->saldo_pelanggaran <= 100) {
                                    $ket='Dikembalikan kepada Orang Tua' ;
                                    } elseif ($data->saldo_pelanggaran >= 30 && $data->saldo_pelanggaran < 90) {
                                        $ket='Pemanggilan Orang Tua / Wali' ;
                                        } elseif ($data->saldo_pelanggaran < 30) {
                                            $ket='-' ;
                                            }
                                            @endphp
                                            {{ $ket }}
                                            </td>
                            <td>
                                @hasanyrole('Admin|GuruBK')
                                <button type="button" class="btn btn-outline-warning" data-bs-toggle="modal"
                                    data-bs-target="#editModal_{{ $data->id_pelanggaran }}">
                                    <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_pelanggaran }}">
                                    <i class="fa-solid fa-trash-can"></i>
                                </button>
                                @endhasanyrole
                                <button type="button" class="btn btn-outline-success" data-bs-toggle="modal"
                                    data-bs-target="#openModel_{{ $data->id_pelanggaran }}">
                                    <i class="fa-solid fa-folder"></i>
                                </button>
                            </td>
                        </tr>
                        @endforeach

                    </x-table>

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

</x-app-layout>
