<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h3>Kehadiran Anggota Koperasi</h3>
            <div class="table-responsive">
                <table class="table table-striped table-condensed">
                    <thead>
                        <tr>
                            <th>Bil.</th>
                            <th>Nama Anggota</th>
                            <th>No. Kad Pengenalan</th>
                            <th>No. Anggota</th>
                            <th>Unit</th>
                            <th>Kehadiran</th>
                            <th>Tarikh/Masa</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($voters as $voter)
                            <tr>
                                {{-- <td>{{ $index + 1 }}</td> <!-- Display the serial number --> --}}
                                <td>{{ $loop->iteration }}</td>
                                <td>{{ $voter['name'] }}</td>
                                <td>{{ $voter['no_kp'] }}</td>
                                <td>{{ $voter['no_anggota'] }}</td>
                                <td>{{ $voter['unit'] }}</td>
                                <td> @php
                                    switch ($voter['kehadiran']) {
                                        case 1:
                                            echo 'Fizikal';
                                            break;
                                        case 2:
                                            echo 'Maya';
                                            break;
                                        default:
                                            echo '-';
                                    }
                                @endphp</td>
                                <td>{{ $voter['updated_at'] }}</td>
                            </tr>

                            {{-- @if ($result->position_id == $position->id) --}}

                            {{-- @endif --}}
                        @endforeach
                        <tr>
                            <td colspan="6" class="text-right"><b>Peratus Kehadiran</b></td>
                            <td>
                                <b>
                                    @php
                                        $percentage = $votes > 0 ? number_format(($totalkehadiranAll / $votes) * 100, 2) : '0.00';
                                        echo $percentage . '%';
                                    @endphp
                                </b>
                            </td>
                        </tr>
                        
                    </tbody>
                </table>
            </div>
            <hr />

        </div>
    </div>
</div>

<!-- Verified By column -->
<div class="container mt-4">
    <div class="signature-section row">
        <div class="col-md-12">
            <div class="table-responsive">
                <table>
                    <tbody>
                        <tr>
                            <td colspan="4"><b>Disahkan Oleh :</b></td>

                        </tr>
                        <tr>
                            <td><b>...................................</b></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<style>
    /* Style for table body */
    .signature-section{
        margin-top: 80px;
    }

    .table tbody td {
        border-bottom: 1px solid #ddd;
        padding: 8px;
    }

    /* Add space between specific columns */
    .table tbody td:nth-child(3),
    /* Unit column */
    .table tbody td:nth-child(4),
    /* Undian column */
    .table tbody td:nth-child(5) {
        /* Peratus (%) column */
        padding-right: 20px;
        /* Adjust this value as needed */
    }
</style>

@push('scripts')
    <script>
        // Define the getKehadiranString function here
        function getKehadiranString(kehadiran) {
            switch (kehadiran) {
                case 1:
                    return 'Fizikal';
                case 2:
                    return 'Maya';
                default:
                    return '-';
            }
        }
    </script>
@endpush
