<div class="no-break" >
    <table
        style="width: 100%; border: 1px solid #000; border-collapse: collapse; ">
        <tr>
            <td style="text-align: center; margin-top: 5px;">
                <h2 style="text-transform: uppercase; text-align: center; margin: 0;">Informasi Dinas Tata Ruang</h2>
            </td>
        </tr>
    </table>
    <table>


        <tr>
            <td width="20%" style="vertical-align: top;">Informasi Dinas Tata Ruang </td>
            <td width="1%" style="vertical-align: top;">:</td>
            <td style="vertical-align: top;">
                @php
                    $informasi = [
                        'peruntukan',
                        'kdb',
                        'kdh',
                        'gsb',
                        'max_lantai',
                        'klb',
                        'gss',
                        'pelebaran_jalan',
                        'nama_petugas',
                    ];
                @endphp

                @foreach ($informasi as $key)
                    @if (isset($forminspeksi['fakta'][$key]) && $forminspeksi['fakta'][$key] !== '-')
                        @php
                            $displayKey = ucfirst(str_replace('_', ' ', $key));
                            if (strlen($key) == 3) {
                                $displayKey = strtoupper($key);
                            }
                        @endphp
                        <p> - {{ $displayKey }}: {{ $forminspeksi['fakta'][$key] }}</p>
                    @endif
                @endforeach
            </td>
        </tr>

        @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) {
                return isset($forminspeksi[$type]) && file_exists(storage_path('app/public/' . $forminspeksi[$type]));
            });
        @endphp
        @foreach ($validPhotoTypes as $type)
            @php
                $imagePath = $forminspeksi[$type] ?? null;
            @endphp
            @if ($imagePath && file_exists(storage_path('app/public/' . $imagePath)))
                <tr>
                    <td style="20%"> {{ $customLabels[$type] ?? '' }}</td>
                    <td width="1%" style="vertical-align: top;"></td>
                    <td style="width: 79%">
                        <img src="{{ storage_path('app/public/' . $imagePath) }}" alt="{{ $imagePath }}"
                            style="max-height: 400px; height: auto; max-width: 100%;">
                    </td>
                </tr>
            @endif
        @endforeach
        <tr>
            <td width="20%" style="vertical-align: top;">Catatan yang Perlu Diperhatikan </td>
            <td width="1%" style="vertical-align: top;">:</td>
            <td style="vertical-align: top;">

                @foreach ($forminspeksi['fakta']['keterangan'] ?? [] as $informasi)
                    <p>{!! nl2br(e($informasi)) !!}</p>
                @endforeach

            </td>
        </tr>

    </table>
</div>
