
<div class="page-break"></div>
    <div class="section">
        <table style="width: 100%; border-collapse: collapse; border: 1px solid #000;">
            <tr>
                <td style="width:20%; padding: 2px; border: 1px solid #000">Nama Debitur</td>
                <td style=" width: 1%; padding: 2px; border: 1px solid #000">:</td>
                <td style="padding: 2px; border: 1px solid #000">{{ $permohonan->debiture->name ?? '' }}</td>
            </tr>
            <tr>
                <td style="padding: 2px; border: 1px solid #000">Nomor Laporan</td>
                <td style="padding: 2px; border: 1px solid #000">:</td>
                <td style="padding: 2px; border: 1px solid #000">{{ $nomorLaporan }}</td>
            </tr>
            <tr>
                <td style="padding: 2px; border: 1px solid #000">Tanggal Laporan</td>
                <td style="padding: 2px; border: 1px solid #000">:</td>
                <td style="padding: 2px; border: 1px solid #000">{{ formatTanggalIndonesia($tanggalLaporan) ?? '' }}
                </td>
            </tr>
        </table>
        @if ($inspeksi->is_mig != 1)
        <table style="width: 100%; ">
            <tr>
                <td style="border: 1px solid #000; text-align: center;">
                    GS, PETA DAN BLAD TATA RUANG
                </td>
            </tr>
        </table>
        <div>
            @php
                $fotoTypes = [
                    'upload_gs',
                    'foto_sentuh_tanahku',
                    'foto_gistaru',
                    'foto_bhumi',
                    'foto_argis_region',
                    'foto_tempat',
                ];

                $customLabels = [
                    'upload_gs' => 'Gambar Situasi',
                    'foto_sentuh_tanahku' => 'Sentuh Tanahku',
                    'foto_gistaru' => 'Gistaru',
                    'foto_bhumi' => 'Bhumi',
                    'foto_argis_region' => 'Blad Tata Ruang ',
                    'foto_tempat' => 'Peta Lokasi',
                ];

            // Memindahkan foto_tempat ke depan jika ada
            if (($key = array_search('upload_gs', $fotoTypes)) !== false) {
                unset($fotoTypes[$key]);
                array_unshift($fotoTypes, 'upload_gs');
            }

        // Filter fotoTypes untuk memastikan hanya yang memiliki imagePath valid
        $validPhotoTypes = array_filter($fotoTypes, function ($type) use ($forminspeksi) {
            // Check if value is a string (not an array) and file exists
            return isset($forminspeksi[$type]) &&
                   is_string($forminspeksi[$type]) &&
                   file_exists(storage_path('app/public/' . $forminspeksi[$type]));
        });
            @endphp

            <table width="100%" border="0">
                @foreach ($validPhotoTypes as $type)
                    @php
                        $imagePath = $forminspeksi[$type] ?? null;
                    @endphp
                    @if ($imagePath && file_exists(storage_path('app/public/' . $imagePath)))
                        <tr>
                            <td style="width: 100%; vertical-align: top; text-align: center" class="border photo-item">
                                <p style="margin: 0; font-size: 10px; text-align: center;">
                                    {{ $customLabels[$type] ?? '' }}
                                </p>
                                <img src="{{ storage_path('app/public/' . $imagePath) }}" alt="{{ $imagePath }}"
                                style="max-height: 400px; height: auto; max-width: 100%;">
                            </td>
                        </tr>
                    @endif
                @endforeach
            </table>
        </div>
        <div class="page-break"></div>
        @endif
        <table style="width: 100%; ">
            <tr>
                <td style="border: 1px solid #000; text-align: center;">
                    FOTO JAMINAN
                </td>
            </tr>
        </table>
        @include('lpj::penilai.components.foto-jaminan')
    </div>
    </div>

<footer id="footer">
    {{-- Cabang : {{ $permohonan->debiture->branch->name ?? '' }} --}}
</footer>
<script type="text/php">
    if (isset($pdf)) {
        $pdf->page_script('
            $font = $fontMetrics->get_font("Arial, Helvetica, sans-serif", "normal");
            $size = 10;
            $pageText = $PAGE_NUM;
            $y = 800;
            $x = 550;
            $pdf->text($x, $y, $pageText, $font, $size);
        ');
    }
</script>
<script>
    const datas = @json($forminspeksi);
    console.log(datas);
    const lpjData = @json($lpjData);
    console.log(lpjData);


    document.addEventListener('DOMContentLoaded', function() {
        const checkboxes = document.querySelectorAll('.checkbox-lainnya');

        checkboxes.forEach(checkbox => {
            checkbox.addEventListener('change', function() {
                const textLainnya = this.closest('label').querySelector('.text-lainnya');

                if (this.checked && this.value === 'Lainnya') {
                    textLainnya.style.display = 'inline';
                } else if (this.value === 'Lainnya') {
                    textLainnya.style.display = 'none';
                }
            });

            // Atur visibilitas awal
            if (checkbox.checked && checkbox.value === 'Lainnya') {
                const textLainnya = checkbox.closest('label').querySelector('.text-lainnya');
                textLainnya.style.display = 'inline';
            }
        });
    });
</script>
</body>
</html>
