@extends('layout.app')

@section('content')
<div class="container mt-4">
    <div class="text-center mb-4">
        <h2 class="fw-bold">📊 Hasil Rekomendasi Makanan</h2>
        <p class="text-muted">Berikut adalah peringkat makanan berdasarkan hasil perhitungan AHP.</p>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show mt-3" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    <div class="row justify-content-center">
        <div class="col-lg-10">

            <div class="card shadow rounded">
                <div class="card-header bg-success text-white text-center">
                    <h5 class="mb-0">Daftar Rekomendasi</h5>
                </div>

                <div class="card-body p-0">
                    <table class="table table-hover mb-0 text-center">
                        <thead class="table-light">
                            <tr>
                                <th scope="col">🏅 Peringkat</th>
                                <th scope="col">🍽️ Nama Makanan</th>
                                <th scope="col">📈 Nilai Akhir</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($rekomendasi as $index => $item)
                                <tr>
                                    <td><span class="badge bg-primary fs-6">{{ $index + 1 }}</span></td>
                                    <td class="fw-semibold">{{ $item->makanan->nama }}</td>
                                    <td>{{ number_format($item->nilai_akhir, 4) }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="3" class="text-muted">Tidak ada data rekomendasi.</td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="mt-4 text-end">
                <form action="{{ route('rekomendasi.kirim', ['user' => 2]) }}" method="POST" onsubmit="return confirm('Yakin ingin mengirim hasil ini ke user?')">
                    @csrf
                    <button type="submit" class="btn btn-success">📤 Kirim Hasil ke User</button>
                </form>
            </div>

            <div class="mt-3 text-end">
    <form action="{{ route('rekomendasi.hapusSemua') }}" method="POST" class="mb-4">
        @csrf
        <label for="tanggal_rekomendasi">Pilih Tanggal Rekomendasi:</label>
        <select name="tanggal_rekomendasi" required>
            <option value="">-- Pilih Tanggal --</option>
            @foreach ($tanggalList as $tgl)
                <option value="{{ $tgl }}">{{ \Carbon\Carbon::parse($tgl)->format('d M Y') }}</option>
            @endforeach
        </select>
        <button type="submit" class="btn btn-danger">Hapus Data</button>
    </form>
</div>



            <div class="text-end mt-4">
                <a href="{{ route('alternatif.pilih') }}" class="btn btn-outline-secondary">🔙 Kembali ke Pemilihan Alternatif</a>
            </div>
        </div>
    </div>
</div>
@endsection
