@extends('admin.layout')

@section('title', '')

@section('content')
    <div class="card">
        <div class="card-header bg-success text-white d-flex justify-content-between align-items-center">
            <div>
                <h5 class="mb-0"><i class="bi bi-star me-1"></i> Ektrakulikuler</h5>
                <p class="mb-0 small text-white-50">Halaman deskripsi capaian ekstrakulikuler (daftar kegiatan ekstrakurikuler).</p>
            </div>
        </div>
        @php
            $activePeriode = \App\Models\Periode::where('status', \App\Models\Periode::STATUS_AKTIF)->first();
            $tahunPel = $activePeriode->tahun_pelajaran ?? '-';
            $semester = $activePeriode->semester ?? '-';
        @endphp

        <div class="card-body">
            <div class="mb-3 d-flex justify-content-between align-items-start">
                <div>
                    <h5 class="mb-1">Daftar Ektrakulikuler Non-Akademis</h5>
                    <div class="small text-muted">Tahun Pelajaran: <strong>{{ $tahunPel }}</strong> &nbsp;|&nbsp; Semester: <strong>{{ $semester }}</strong></div>
                </div>
                <div>
                    <a href="{{ url('admin/data-umum/ekstrakulikuler/create') }}" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i> Tambah</a>
                </div>
            </div>
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead class="table-light">
                        <tr>
                            <th>Ekstrakulikuler</th>
                            <th style="width:140px">Kategori</th>
                            <th class="text-start">Deskripsi Ekstrakulikuler</th>
                            <th style="width:140px">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($items ?? [] as $it)
                            <tr>
                                <td>{{ $it->nama ?? ($it['nama'] ?? ($it->name ?? '-')) }}</td>
                                <td>{{ $it->kategori ?? ($it['kategori'] ?? '-') }}</td>
                                <td class="text-start">{{ $it->keterangan ?? ($it['keterangan'] ?? ($it->description ?? '-')) }}</td>
                                <td class="text-center">
                                    <a href="{{ url('admin/data-umum/ekstrakulikuler/'.$it->id.'/edit') }}" class="btn btn-sm btn-primary me-1" title="Edit">
                                        <i class="bi bi-pencil" aria-hidden="true"></i>
                                    </a>
                                    <form action="{{ url('admin/data-umum/ekstrakulikuler/'.$it->id) }}" method="POST" style="display:inline-block" onsubmit="return confirm('Hapus data ini?');">
                                        @csrf
                                        @method('DELETE')
                                        <button class="btn btn-sm btn-danger" title="Hapus">
                                            <i class="bi bi-trash" aria-hidden="true"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="4" class="text-center text-muted">Belum ada data ekstrakulikuler.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            @if(method_exists($items, 'links'))
                <div class="mt-3">{{ $items->links() }}</div>
            @endif
        </div>
    </div>
@endsection
