<!-- #RIWAYAT SECTION -->
<section class="section riwayat" id="riwayat" aria-label="riwayat">
<div class="container">
    <p class="section-subtitle has-before text-center">Histori Perhitungan</p>
    <div class="riwayat-header">
        <h2 class="h2 section-title text-center">Riwayat <span class="has-before">Perhitungan</span></h2>
        <p class="section-subtitle text-center">Daftar perhitungan yang telah Anda lakukan sebelumnya.</p>
    </div>
    <div class="riwayat-content">
    <!-- Tabel Riwayat -->
    @if($sesikuis->isNotEmpty())
    <div class="riwayat-table-container">
    <div class="card">
    <div class="card-body">
        <h3 class="quiz-subtitle">Daftar Riwayat Perhitungan</h3>                
    <div class="table-responsive">
    <table class="table table-striped">
    <thead>
        <tr>
            <th>No</th>
            <th>Tanggal</th>
            <th>Kurikulum</th>
            <th>Rekomendasi Teratas</th>
            <th>Skor</th>
            <th>Aksi</th>
        </tr>
    </thead>
    <tbody>
    @foreach($sesikuis as $index => $sesi)
    <tr>
        <td>{{ $index + 1 }}</td>
        <td>{{ $sesi->created_at->format('d/m/Y H:i') }}</td>
        <td>{{ $sesi->kurikulum->nama ?? 'Tidak ada data' }}</td>
        @php
            $topHasil = $sesi->hasilsaw->where('peringkat', 1)->first();
        @endphp
        <td>
            @if($topHasil && $topHasil->alternatif)
            {{ $topHasil->alternatif->nama }}
            @else
            Tidak ada data
            @endif
        </td>
        <td>
        @if($topHasil)
            {{ number_format($topHasil->skor_normalisasi, 3) }}
        @else                                    
        @endif
        </td>
        <td>
        <a href="{{ route('lihatHasil', $sesi->id) }}" class="btn btn-sm btn-info" title="Lihat Detail"><i class="fas fa-eye"></i></a>
        <form action="{{ route('hapusRiwayat', $sesi->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Apakah Anda yakin ingin menghapus data ini?')">
        @csrf
        @method('DELETE')
        <button type="submit" class="btn btn-sm btn-danger" title="Hapus"><i class="fas fa-trash"></i></button>
        </form>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        @else
        <div class="alert alert-info">
            <i class="fas fa-info-circle"></i> Belum ada riwayat perhitungan.
        </div>
        @endif
    </div>
</div>
</section>