@php
    use App\Models\Kriteria;
@endphp

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Laporan Sub Kriteria - Politeknik Negeri Jember</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            color: #333;
            padding: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
            border-bottom: 2px solid #007a99;
            padding-bottom: 10px;
        }
        .title {
            color: #007a99;
            font-size: 22px;
            font-weight: bold;
        }
        .subtitle {
            font-size: 16px;
            margin-top: 5px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            table-layout: fixed; 
            margin-top: 10px;
        }
        th, td {
            border: 1px solid #ccc;
            padding: 8px;
            text-align: left;
            word-wrap: break-word; 
        }
        th {
            background-color: #f8f9fa;
        }
        .badge-info {
            background-color: #17a2b8;
            color: white;
            padding: 3px 8px;
            border-radius: 10px;
            font-size: 12px;
        }
        .badge-value {
            background-color: rgba(0, 122, 153, 0.8);
            color: white;
            padding: 3px 10px;
            border-radius: 15px;
            font-size: 12px;
        }
        .footer {
            margin-top: 30px;
            text-align: right;
            font-size: 12px;
            color: #6c757d;
        }
    </style>
</head>
<body>

    <div class="header">
        <div class="title">POLITEKNIK NEGERI JEMBER</div>
        <div class="subtitle">LAPORAN DATA SUB KRITERIA</div>
    </div>

    @if($kriteria)
        <div style="margin-bottom: 10px;">
            <strong>Kriteria:</strong> {{ $kriteria->nama_kriteria }}
        </div>

        <table>
            <thead>
                <tr>
                    <th style="width: 5%;">#</th>
                    <th style="width: 70%;">Nama Sub Kriteria</th>
                    <th style="width: 25%;">Nilai</th>
                </tr>
            </thead>
            <tbody>
                @forelse($subkriterias as $sub)
                    <tr>
                        <td>{{ $loop->iteration }}</td>
                        <td>{{ $sub->nama_subkriteria }}</td>
                        <td><span class="badge-value">{{ number_format($sub->nilai) }}</span></td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" style="text-align: center;">Belum ada data sub kriteria</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    @else
        @foreach($grouped_subkriterias as $group)
            <div style="margin-top: 25px; margin-bottom: 10px;">
                <strong>Kriteria:</strong> {{ $group['kriteria']->nama_kriteria }}
                <span class="badge-info">({{ ucfirst($group['kriteria']->attribut) }})</span>
            </div>

            <table>
                <thead>
                    <tr>
                        <th style="width: 5%;">#</th>
                        <th style="width: 70%;">Nama Sub Kriteria</th>
                        <th style="width: 25%;">Nilai</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($group['subkriterias'] as $index => $sub)
                        <tr>
                            <td>{{ $index + 1 }}</td>
                            <td>{{ $sub->nama_subkriteria }}</td>
                            <td><span class="badge-value">{{ number_format($sub->nilai) }}</span></td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="3" style="text-align: center;">Belum ada data sub kriteria</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        @endforeach
    @endif

    <div class="footer">
        Dicetak pada: {{ date('d F Y H:i:s') }}
    </div>

</body>
</html>
