@extends('layouts/contentNavbarLayout')

@section('title', 'Tables - Kartu Kendali')

@section('content')
<h4 class="fw-bold py-3 mb-4">
    <span class="text-muted fw-light">Tables Kartu Kendali</span>
</h4>

<!-- Responsive Table -->
<div class="card">
    <h5 class="card-header">Kartu Kendali</h5>
    @if ($user->role == "Admin")
        <div class="mx-3 text-start">
            <a href="{{ route('kartukendali.create') }}">
                <button type="submit" class="btn btn-sm btn-primary">
                    <i class='bx bx-plus'></i>
                    Add
                </button>
            </a>
            <div class="btn-group">
                <button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-bs-toggle="dropdown"
                    aria-expanded="false">Export</button>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="{{route('kartukendali.export')}}?output=excel">Excel</a></li>
                    <li><a class="dropdown-item" href="{{route('kartukendali.export')}}?output=pdf">PDF</a></li>
                </ul>
            </div>
        </div>
    @endif
    <div class="card-datatable table-responsive text-nowrap p-3">
        @if ($user->role == "Admin")
            <table class="table" id="table">
                <thead>
                    <tr class="text-nowrap">
                        <th>No</th>
                        <th>Nama</th>
                        <th>Hadir</th>
                        <th>Keterangan</th>
                        <th>
                            Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($kartukendali as $record)
                        <tr>
                            <th scope="row">{{$loop->index + 1}}</th>
                            <td>{{$record->nama}}</td>
                            <td>{{$record->jumlah}}/40</td>
                            <td>
                                @if ($record->jumlah >= 40)
                                    Tuntas
                                @else
                                    Tidak Tuntas
                                @endif
                            </td>
                            <td>
                                <div class="btn-group" role="group" aria-label="Actions">
                                    @if ($record->jumlah >= 40)
                                        <a href="{{route('kartukendali.update.add', $record->kkid)}}"
                                            class="btn btn-blue disabled"><i class="bx bx-plus"></i> Tambah</a>
                                    @else
                                        <a href="{{route('kartukendali.update.add', $record->kkid)}}" class="btn btn-blue"><i
                                                class="bx bx-plus"></i> Tambah</a>
                                    @endif
                                    @if ($record->jumlah <= 0)
                                        <a href="{{route('kartukendali.update.sub', $record->kkid)}}"
                                            class="btn btn-blue disabled"><i class="bx bx-minus"></i> Kurang</a>
                                    @else
                                        <a href="{{route('kartukendali.update.sub', $record->kkid)}}" class="btn btn-blue"><i
                                                class="bx bx-minus"></i> Kurang</a>
                                    @endif
                                    <form action="{{route('kartukendali.delete', $record->kkid)}}" method="POST">
                                        @csrf
                                        @method("DELETE")
                                        <button type="submit" class="btn btn-white"
                                            onclick="return confirm('Apakah Kamu Yakin?')">
                                            <i class="bx bx-trash"></i> Hapus
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        @else
            <table class="table">
                <thead>
                    <tr class="text-nowrap">
                        <th>No</th>
                        <th>Nama</th>
                        <th>Hadir</th>
                        <th>Keterangan</th>
                    </tr>
                </thead>
                <tbody>
                    <?php    $i = 0; ?>
                    @foreach ($kartukendali as $record)
                        <?php        $i += 1; ?>
                        <tr>
                            <th scope="row">{{$i}}</th>
                            <td>{{$record->nama}}</td>
                            <td>{{$record->jumlah}}/40</td>
                            <td>
                                @if ($record->jumlah >= 40)
                                    Tuntas
                                @else
                                    Tidak Tuntas
                                @endif
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        @endif
    </div>
</div>
<!--/ Responsive Table -->
@endsection