<table border="1">
    <tr>
        <th colspan="{{ 2 + $jumlahHari + 4 }}">
            REKAP ABSENSI KELAS {{ $kelas->nama_kelas }}
        </th>
    </tr>

    <tr>
        <td colspan="{{ 2 + $jumlahHari + 4 }}">
            Bulan: {{ $bulan }} / {{ $tahun }}
        </td>
    </tr>

    <tr>
        <th>No</th>
        <th>Nama</th>

        @for ($i = 1; $i <= $jumlahHari; $i++)
            <th>{{ $i }}</th>
        @endfor

        {{-- TOTAL DI KANAN --}}
        <th style="background:#d1d5db">H</th>
        <th style="background:#d1d5db">S</th>
        <th style="background:#d1d5db">I</th>
        <th style="background:#d1d5db">A</th>
    </tr>

    @foreach ($siswas as $i => $siswa)
        @php
            $totalH = $totalPerSiswa[$siswa->siswa_id]['H'] ?? 0;
            $totalS = $totalPerSiswa[$siswa->siswa_id]['S'] ?? 0;
            $totalI = $totalPerSiswa[$siswa->siswa_id]['I'] ?? 0;
            $totalA = $totalPerSiswa[$siswa->siswa_id]['A'] ?? 0;
        @endphp

        <tr>
            <td>{{ $i + 1 }}</td>
            <td>{{ $siswa->nama_siswa }}</td>

            {{-- DATA HARIAN --}}
            @for ($d = 1; $d <= $jumlahHari; $d++)
                <td>{{ $dataAbsen[$siswa->siswa_id][$d] ?? '' }}</td>
            @endfor

            {{-- TOTAL --}}
            <td><b>{{ $totalH }}</b></td>
            <td><b>{{ $totalS }}</b></td>
            <td><b>{{ $totalI }}</b></td>
            <td><b>{{ $totalA }}</b></td>
        </tr>
    @endforeach
</table>