@extends('base.layout')
@section('content')
<style>
table {
    margin-bottom: 30px;
}
</style>
<div class="wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-6">
                <div class="card-box ribbon-box">
                    <div class="ribbon ribbon-primary">Mikroskopis BTA SP Laki-Laki Bulan {{$bulan}} Tahun {{$tahun}}</div>
                    <p></p>
                    <div class="table-responsive">
                        <button type="button" class="btn btn-primary" id="btnexport"><i class="fa fa-print"></i> Export</button>
                        <table cellpadding="0" cellspacing="0" id="btasptable" class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>Nilai</th>
                                    <th>Pagi</th>
                                    <th>Sewaktu</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($nilaiList as $nilai)
                                <tr>
                                    <td>{{ $nilai }}</td>
                                    <td>{{ $rekapLaki[$nilai]['pagi'] ?? 0 }}</td>
                                    <td>{{ $rekapLaki[$nilai]['sewaktu'] ?? 0 }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="card-footer">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="card-box ribbon-box">
                    <div class="ribbon ribbon-danger">Mikroskopis BTA SP Perempuan Bulan {{$bulan}} Tahun {{$tahun}}</div>
                    <p></p>
                    <div class="table-responsive">
                        <button type="button" class="btn btn-primary" id="btnexportperempuan"><i class="fa fa-print"></i> Export</button>
                        <table cellpadding="0" cellspacing="0" id="btasptableperempuan" class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <th>Nilai</th>
                                    <th>Pagi</th>
                                    <th>Sewaktu</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($nilaiList as $nilai)
                                <tr>
                                    <td>{{ $nilai }}</td>
                                    <td>{{ $rekapPerempuan[$nilai]['pagi'] ?? 0 }}</td>
                                    <td>{{ $rekapPerempuan[$nilai]['sewaktu'] ?? 0 }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="card-footer">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
@push('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function() {
        document.getElementById('btnexport').addEventListener('click', function() {
            var table = document.getElementById('btasptable');
            if (table) {
                var wb = XLSX.utils.table_to_book(table, { sheet: "Report" });
                XLSX.writeFile(wb, "mikroskopisbtasplakilaki_{{$bulan}}_Tahun{{$tahun}}.xlsx");
            } else {
                console.error('Tabel dengan ID "btasptable" tidak ditemukan.');
            }
        });
        document.getElementById('btnexportperempuan').addEventListener('click', function() {
            var table = document.getElementById('btasptableperempuan');
            if (table) {
                var wb = XLSX.utils.table_to_book(table, { sheet: "Report" });
                XLSX.writeFile(wb, "mikroskopisbtaspperempuan_{{$bulan}}_Tahun{{$tahun}}.xlsx");
            } else {
                console.error('Tabel dengan ID "btasptableperempuan" tidak ditemukan.');
            }
        });
    });
</script>
@endpush
