@extends('layout.main')
@section('body')
    @php
        $menu = 'Data Perhitungan';
        $pageTitle = 'Perhitungan Nilai Akhir';
    @endphp

    @include('layout.navbar')
    @include('layout.sidebar')

    {{-- Main Content --}}
    <div class="main-container">
        <div class="pd-ltr-20 xs-pd-20-10">
            <div class="min-height-200px">
                <div class="page-header">
                    <div class="row">
                        <div class="col-md-6 col-sm-12">
                            <div class="title">
                                <h4>{{ $menu }}</h4>
                            </div>
                            <nav aria-label="breadcrumb" role="navigation">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="{{ route('penilaian.input-nilai') }}">Input Penilaian</a></li>
                                    @if (isset($pageTitle))
                                        <li class="breadcrumb-item active" aria-current="page">{{ $pageTitle }}</li>
                                    @else
                                        <li class="breadcrumb-item active" aria-current="page"></li>
                                    @endif
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
                <div class="card-box mb-30">
                    <div class="pd-20">
                        <h4 class="text-blue h4 mb-0">Perhitungan Nilai Akhir</h4>
                    </div>
                    <form method="POST" action="{{ route('perangkingan') }}">
                        @csrf
                        <div class="pb-10">
                            <div class="table-responsive">
                                <table class="data-table table stripe hover nowrap">
                                    <thead>
                                        <tr>
                                            <th>No</th>
                                            <th>Ekstrakurikuler</th>
                                            @foreach ($criterias as $criteria)
                                                <th>{{ $criteria->nama }}</th>
                                            @endforeach
                                            <th>Nilai Akhir</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse ($extracuricullars as $extracuricullar)
                                            <tr>
                                                <td>{{ $loop->iteration }}</td>
                                                <td>{{ $extracuricullar->nama }}</td>
                                                @foreach ($criterias as $criteria)
                                                <td>
                                                    @php
                                                        $akhir = $nilaiAkhir[$extracuricullar->id][$criteria->id] ?? null;
                                                    @endphp
                                                    {{ $akhir }}
                                                </td>
                                                @endforeach
                                                <td>{{ $totalNilaiAkhir[$extracuricullar->id] }}</td>
                                        @empty
                                            <tr>
                                                <td colspan="5" class="text-center">Tidak ada data.</td>
                                            </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                                <div class="col-sm-12">
                                    <div class="input-group mb-3 mx-auto">
                                        <button type="submit" class="btn btn-primary btn-lg btn-block">Hasil Perangkingan</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="footer-wrap pd-20 mb-20 card-box">
                <strong>Sistem Pendukung Keputusan Pemilihan Ekstrakurikuler Metode SMARTER</strong>
            </div>
        </div>
    </div>
@endsection
