<div class="no-break">
    <table class="judul" style="width: 100%; ">
        <tr>
            <td style="width: 100%; border: 1px solid #000; text-align: center;">
                ANALISA FAKTA
            </td>
        </tr>
    </table>

    <table style="width: 100%">

        <tr>
            <td width="25%" style="vertical-align: top;">Faktor Positif</td>
            <td width="1%" style="vertical-align: top;">:</td>
            <td style="vertical-align: top;">
                @isset($forminspeksi['fakta']['fakta_positif'])
                    <table style="width: 100%; border-collapse: collapse;">
                        @foreach ($forminspeksi['fakta']['fakta_positif'] as $key => $item)
                            <tr>
                                <td>{!! nl2br(e($item)) !!}</td>
                            </tr>
                        @endforeach
                    </table>
                @endisset
            </td>
        </tr>

        {{-- Faktor Negatif --}}
        <tr>
            <td width="25%" style="vertical-align: top;">Faktor Negatif</td>
            <td width="1%" style="vertical-align: top;">:</td>
            <td style="vertical-align: top;">
                @php
                    $faktaNegatif = $forminspeksi['fakta']['fakta_negatif'] ?? [];
                    $faktaNegatifFiltered = is_array($faktaNegatif)
                        ? array_filter($faktaNegatif, function ($item) {
                            return !empty(trim($item));
                        })
                        : [];
                @endphp

                @if (!empty($faktaNegatifFiltered))
                    <table style="width: 100%; border-collapse: collapse;">
                        @foreach ($faktaNegatifFiltered as $key => $item)
                            <tr>
                                <td>{!! nl2br(e($item)) !!}</td>
                            </tr>
                        @endforeach
                    </table>
                @else
                    <p>Tidak ada faktor negatif yang teridentifikasi.</p>
                @endif
            </td>
        </tr>

        @if (!empty($forminspeksi['fakta']['rute_menuju']))
            <tr>
                <td width="25%" style="vertical-align: top;">Rute Menuju</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    {!! nl2br(e($forminspeksi['fakta']['rute_menuju'] ?? '')) !!}
                </td>
            </tr>
        @endif

        @if (!empty($forminspeksi['fakta']['batas_batas_input']))
            <tr>
                <td width="25%" style="vertical-align: top;">Batas batas</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    @foreach ($forminspeksi['fakta']['batas_batas_input'] ?? [] as $arah => $batas)
                        @if ($batas)
                            <p> - {{ $arah }} : {{ $batas }}</p>
                        @endif
                    @endforeach
                </td>
            </tr>
        @endif

        @if (!empty($forminspeksi['fakta']['kondisi_lingkungan']))
            <tr>
                <td width="25%" style="vertical-align: top;">Kondisi Lain Terkait Lingkungan</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    @foreach ($forminspeksi['fakta']['kondisi_lingkungan'] ?? [] as $kondisi)
                        {!! nl2br(e($kondisi)) !!}
                    @endforeach
                </td>
            </tr>
        @endif
        @if (!empty($forminspeksi['fakta']['kondisi_lingkungan']))
            <tr>
                <td width="25%" style="vertical-align: top;">Kondisi Lain Terkait Bangunan</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    @foreach ($forminspeksi['fakta']['kondisi_lain_bangunan'] ?? [] as $kondisi)
                        {!! nl2br(e($kondisi)) !!}
                    @endforeach
                </td>
            </tr>
        @endif
        @if (!empty($forminspeksi['fakta']['informasi_dokument']))
            <tr>
                <td width="25%" style="vertical-align: top;">Informasi Lain Terkait
                    Dokumen</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    @foreach ($forminspeksi['fakta']['informasi_dokument'] ?? [] as $informasi)
                        {!! nl2br(e($informasi)) !!}
                    @endforeach
                </td>
            </tr>
        @endif


    </table>
</div>
