@include('lpj::penilai.components.header')
@php
    $data = '';
    foreach ($permohonan->documents as $dokumen) {
        $data .= $dokumen->jenisJaminan->name . ', ';

        $penilai = $permohonan->penilaian->userPenilai->where('role', 'penilai')->first();
        $surveyor = $permohonan->penilaian->userPenilai->where('role', 'surveyor')->first();
        $teams = $permohonan->region->teams;

        if ($teams) {
            foreach ($teams as $team) {
                $team_users = $team->teamsUsers;
                // print_r($team_users);
                if ($team_users) {
                    foreach ($team_users as $team_user) {
                        $user = $team_user->user;

                        if ($user && $user->hasRole('senior-officer')) {
                            $senior_officer = $user;
                            break 3;
                        }
                    }
                }
            }
        }
    }
    $data = rtrim($data, ', ');
@endphp
<main class="content">
    <div style="text-align: center; margin-top: 5px;">
        <h4 style="text-transform: uppercase; font-size: 16px; margin: 0;">Report Analisa Property
            {{ $data }}</h4>
        <p style="font-size: 12px; margin: 5px 0;">NO: {{ $nomorLaporan }}</p>
    </div>
    <hr />

    <table style="width: 100%;">
        <tr>
            <td style="width: 25%; padding: 2px; vertical-align: top;">Kepada</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td style="width: 79%;  vertical-align: top;">{{ $rap['kepada'] ?? '' }}</td>
        </tr>
        <tr>
            <td style="width: 25%; padding: 2px;">Dari</td>
            <td style="width: 1%; padding: 2px;">:</td>
            <td style="width: 79%;  padding: 2px;">{{ $rap['dari'] ?? '' }}</td>
        </tr>
        <tr>
            <td style="width: 25%; padding: 2px;">Tanggal Survey</td>
            <td style="width: 1%;  padding: 2px;">:</td>
            <td style="width: 79%;  padding: 2px;">
                {{ formatTanggalIndonesia($permohonan->penilaian->waktu_penilaian) }}</td>
        </tr>
        <tr>
            <td style="width: 25%; padding: 2px; vertical-align: top;">Cabang/Pemohon</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td style="vertical-align: top;  vertical-align: top;">
                {{ $permohonan->debiture->branch->name ?? '' }}
            </td>
        </tr>
        <tr>
            <td style="width: 25%; padding: 2px;">Ao</td>
            <td style="width: 1%;  padding: 2px;">:</td>
            <td style="vertical-align: top;  padding: 2px;">{{ $permohonan->user->name ?? '' }}</td>
        </tr>
        <tr>
            <td style="width: 25%; padding: 2px; vertical-align: top;">Perwakilan Developer</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td style="vertical-align: top;">{{ $forminspeksi['asset']['pihak_bank'] ?? '' }}
            </td>
        </tr>
        <tr>
            <td style="width: 25%; padding: 2px;">Perihal</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td style="width: 79%;">{{ $rap['perihal'] ?? '' }}</td>
        </tr>
    </table>

    <div style="border-top: 1px solid black; width: 100%;"></div>
    <h2 style="text-transform: uppercase;">NAMA DEVELOPER</h2>
    <table style="width: 100%; ">
        <tr>
            <td style="width: 25%; padding: 2px;">Nama</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td style="width: 79%;">{{ $permohonan->debiture->name ?? '' }}</td>
        </tr>
    </table>

    <h2 style="text-transform: uppercase;">NAMA PROYEK</h2>
    <table style="width: 100%; ">
        <tr>
            <td style="width: 25%; padding: 2px;">Proyek</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td style="width: 79%;">{{ $data ?? '' }}</td>
        </tr>
    </table>
    <h2 style="text-transform: uppercase;">ALAMAT</h2>
    <table style="width: 100%; ">
        <tr>
            <td width="25%">Terletak di</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td> {{ $alamat['address'] ?? '' }}</td>
        </tr>
        <tr>
            <td>Desa/Kelurahan</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td>{{ $alamat['village_code'] ?? '' }}</td>
        </tr>
        <tr>
            <td>Kecamatan</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td>{{ $alamat['district_code'] ?? '' }}</td>
        </tr>
        <tr>
            <td>Kabupaten/Kota</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td> {{ $alamat['city_code'] ?? '' }}</td>
        </tr>
        <tr>
            <td>Provinsi</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td>{{ $alamat['province_code'] ?? '' }}</td>
        </tr>
    </table>
    <h2 style="text-transform: uppercase;">DOKUMEN TERLAMPIR</h2>
    <table style="width: 100%;">

        @include('lpj::component.print-out-dokument')


        @if (isset($forminspeksi['perizinan']) && is_array($forminspeksi['perizinan']) && count($forminspeksi['perizinan']) > 0)
            @foreach ($forminspeksi['perizinan'] as $perizinan)
                <tr>
                    <td style="width: 25%;  padding: 2px;">Perizinan</td>
                    <td style="width: 1%;  padding: 2px;">:</td>
                    <td style="width: 79%;  padding: 2px;">{{ $perizinan['perizinan'] }}</td>
                </tr>
            @endforeach
        @endif

        @if (isset($forminspeksi['brosur_price_list']) && count($forminspeksi['brosur_price_list']) > 0)
            @foreach ($forminspeksi['brosur_price_list'] as $perizinan)
                <tr>
                    <td style="width: 25%;  padding: 2px;">Brosur & Pricelist</td>
                    <td style="width: 1%;  padding: 2px;">:</td>
                    <td style="width: 79%;  padding: 2px;">{{ $perizinan['jenis'] }}</td>
                </tr>
            @endforeach
        @endif

    </table>

    <h2 style="text-transform: uppercase;">DESKRIPSI DEVELOPER</h2>
    <table style="width: 100%;">
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Pengalaman Developer & Proyek Yang Pernah
                Dibuat</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td style="width: 79%;">{!! nl2br(e($forminspeksi['pengalaman_developer'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Apakah Developer Anggota REI</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['developer_anggota'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>


        @isset($forminspeksi['lainnya_developer'])
            @foreach ($forminspeksi['lainnya_developer'] as $item)
                <tr>
                    <td style="vertical-align: top; width: 25%;  padding: 2px;">Lainnya</td>
                    <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        @endisset
    </table>
    <h2 style="text-transform: uppercase;">KONDISI, LINGKUNGAN DAN PROGRESS PEMBANGUNAN</h2>
    <table style="width: 100%;">
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Kapan Mulai Dibangun & Target Penyelesaian
            </td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['kapan_mulai_dibangun'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Kondisi Perumahan Saat Ini</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['kondisi_perumahan'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Progress Pembangunan</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['progres_pembangunan'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Kontraktor (internal/eksternal)</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['kontraktor'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Lingkungan Sekitar</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['lingkungan_sekitar'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Komplek Lain Disekitar Lokasi</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['komplek_disekitar'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Pusat Keramaian Dekat Lokasi</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['pusat_keramaian'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 25%;  padding: 2px;">Transportasi Umum Yang Tersedia</td>
            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
            <td>{!! nl2br(e($forminspeksi['transportasi_umum'] ?? 'Data tidak tersedia')) !!}</td>
        </tr>


        @isset($forminspeksi['lainnya_kondisi'])
            @foreach ($forminspeksi['lainnya_kondisi'] as $item)
                <tr>
                    <td style="vertical-align: top; width: 25%;  padding: 2px;">Lainnya</td>
                    <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        @endisset
    </table>

    @isset($forminspeksi['partisi'])
        <h2 style="text-transform: uppercase;">PARTISI BANGUNAN</h2>
        <table style="width: 100%;">
            @if (is_array($forminspeksi['partisi']))
                @foreach ($forminspeksi['partisi'] as $key => $item)
                    @if (is_array($item))
                        <tr>
                            <td style="vertical-align: top; width: 25%;  padding: 2px;">
                                {{ $item['nama'] ?? '' }}
                            </td>
                            <td style="vertical-align: top; width: 1%;  padding: 2px;">:</td>
                            <td>
                                {{ $item['value'] ?? '' }}
                            </td>
                        </tr>
                    @endif
                @endforeach
            @endif
        </table>
    @endisset

    @isset($forminspeksi['jumlah_unit'])
        <h2 style="text-transform: uppercase;">JUMLAH UNIT, BLOK, TYPE DAN LUAS BANGUNAN</h2>
        <table>
            @foreach ($forminspeksi['jumlah_unit'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['batas_batas_perumahan'])
        <h2 style="text-transform: uppercase;">BATAS-BATAS PERUMAHAN</h2>
        <table>
            @foreach ($forminspeksi['batas_batas_perumahan'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['fasus_fasum'])
        <h2 style="text-transform: uppercase;">FASOS/FASUM</h2>
        <table>
            @foreach ($forminspeksi['fasus_fasum'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['progres_penjualan'])
        <h2 style="text-transform: uppercase;">PROGRES PENJUALAN SAAT INI</h2>
        <table>
            @foreach ($forminspeksi['progres_penjualan'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['harga_unit'])
        <h2 style="text-transform: uppercase;">HARGA UNIT</h2>
        <table>
            @foreach ($forminspeksi['harga_unit'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['target_market'])
        <h2 style="text-transform: uppercase;">TARGET MARKET</h2>
        <table>
            @foreach ($forminspeksi['target_market'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['kerjasama_dengan_bank'])
        <h2 style="text-transform: uppercase;">KERJASAMA DENGAN BANK LAIN</h2>
        <table>
            @foreach ($forminspeksi['kerjasama_dengan_bank'] as $item)
                <tr>
                    <td>
                        {!! nl2br(e($item)) !!}
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    @isset($forminspeksi['rute_menuju_lokasi'])
        <h2 style="text-transform: uppercase;">RUTE MENUJU LOKASI</h2>
        <table>
            <tr>
                <td>
                    {{ $forminspeksi['rute_menuju_lokasi'] ?? '' }}
                </td>
            </tr>

        </table>
    @endisset
    @isset($forminspeksi['properti_sejenis'])
        <h2 style="text-transform: uppercase;">PROPERTI SEJENIS</h2>
        <table>
            <tr>
                <td>
                    {{ $forminspeksi['properti_sejenis'] ?? '' }}
                </td>
            </tr>

        </table>
    @endisset
    @if (isset($forminspeksi['fakta']) && is_array($forminspeksi['fakta']))
        <h2 style="text-transform: uppercase;">ATURAN TATA KOTA</h2>
        <table>
            @php
                $informasi = [
                    'peruntukan',
                    'kdb',
                    'kdh',
                    'gsb',
                    'max_lantai',
                    'klb',
                    'gss',
                    'pelebaran_jalan',
                    'nama_petugas',
                ];
            @endphp

            @if (isset($forminspeksi['fakta']) && is_array($forminspeksi['fakta']))
            @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
            @endif
        </table>
    @endif

    @isset($forminspeksi['fakta']['keterangan'])


        <h2 style="text-transform: uppercase;">CATATAN LAINNYA</h2>
        <table>
            @foreach ($forminspeksi['fakta']['keterangan'] ?? [] as $keterangan)
                <tr>
                    <td>
                        <p>{!! nl2br(e($keterangan)) !!}</p>
                    </td>
                </tr>
            @endforeach
        </table>
    @endisset
    <p>Demikian kami sampaikan, atas perhatiannya kami ucapkan terima kasih.</p>

   @include('lpj::penilai.components.signature-approval')
</main>
@include('lpj::penilai.components.footer')
