<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;">
                    Analisa Fakta
                </h2>
            </td>
        </tr>
    </table>

    <table>
        <tr>
            <td width="20%" style="vertical-align: top;">Faktor Positif</td>
            <td width="1%" style="vertical-align: top;">:</td>
            <td width="100%" 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>

        <tr>
            <td width="20%" style="vertical-align: top;">Faktor Negatif</td>
            <td width="1%" style="vertical-align: top;">:</td>
            <td width="100%" 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="20%" style="vertical-align: top;">Rute Munuju</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    <p>{{ $forminspeksi['fakta']['rute_menuju'] ?? '' }}</p>
                </td>
            </tr>
        @endif


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

        @if (!empty($forminspeksi['fakta']['kondisi_lingkungan']))
            <tr>
                <td width="20%" 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)
                        <p>{!! nl2br(e($kondisi)) !!}</p>
                    @endforeach
                </td>
            </tr>
        @endif

        @if (!empty($forminspeksi['fakta']['kondisi_lain_bangunan']))
            <tr>
                <td width="20%" 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 $kondisiLain)
                        <p>{!! nl2br(e($kondisiLain)) !!}</p>
                    @endforeach
                </td>
            </tr>
        @endif

        @if (!empty($forminspeksi['fakta']['informasi_dokument']))
            <tr>
                <td width="20%" style="vertical-align: top;">Informasi Terkait Dokumen </td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td style="vertical-align: top;">
                    @foreach ($forminspeksi['fakta']['informasi_dokument'] ?? [] as $informasi)
                        <p>{!! nl2br(e($informasi)) !!}</p>
                    @endforeach
                </td>
            </tr>
        @endif
    </table>
</div>
