@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">
        <table style="width: 100%">
            <tr>
                <td style="text-align: center; margin-top: 5px;">
                    <h2 style="text-decoration: underline; text-transform: uppercase; text-align: center; margin: 0;">
                        CALL Report</h2>
                        <p style="font-size: 12px;  margin: 0;">NO: {{ $nomorLaporan ?? '' }}</p>
                </td>
            </tr>
        </table>
        <hr />
        <table style="width: 100%">
            <tr>
                <td style="width: 25%; padding: 2px;">Kepada</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $report['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;">{{ $report['dari'] ?? '' }}</td>
            </tr>

            <tr>
                <td style="width: 25%; padding: 2px;">Tanggal</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ formatTanggalIndonesia($report['tanggal']) }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">Perihal</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $report['perihal'] ?? '' }}</td>
            </tr>
        </table>

        <table>
            <tr>
                <td>
                    Menindak lanjuti permintan penilaian Tujuan Lelang, BAG Cab
                    {{ $permohonan->debiture->branch->name ?? '' }}
                    tanggal {{ formatTanggalIndonesia($report['tanggal']) ?? '' }}, dapat di sampaikan sebagai berikut:
                </td>
            </tr>
        </table>
        <table style="width: 100%">

            <tr>
                <td style="width: 25%; padding: 2px;">Nama Debitur</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $permohonan->debiture->name ?? '' }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">KJPP</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ preg_replace('/^K\\d+ - /', '', $permohonan->penawaran->nama_kjpp_sebelumnya ?? '-') }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">Jenis Aset</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $data ?? '' }}</td>
            </tr>

            @if (!empty($report['lokasi']['address']))
                <tr>
                    <td style="width: 25%; padding: 2px;">Lokasi Objek Penilaian</td>
                    <td style="width: 1%;  padding: 2px;">:</td>
                    <td style="width: 79%;  padding: 2px;">{{ $report['lokasi']['address'] ?? '' }},
                        {{ $alamat['village_code'] ?? '' }} {{ $alamat['district_code'] ?? '' }},
                        {{ $alamat['city_code'] ?? '' }}, {{ $alamat['province_code'] ?? '' }} </td>
                </tr>
            @endif

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

            <tr>
                <td style="width: 25%; padding: 2px;">Tanggal Penilaian</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ isset($permohonan->penilaian->tanggal_kunjungan) ? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan) : '' }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">Lelang ke</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $report['lelang_kjpp'] ?? '' }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">Nilai Pasar Wajar (NPW)</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ isset($report['nilai_pasar_kjpp']) ? formatRupiah($report['nilai_pasar_kjpp']) : '-' }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">
                    Nilai Likuidasi
                    {{ isset($report['persentase_likuidasi_kjpp']) ? '(' . $report['persentase_likuidasi_kjpp'] . '%)' : '-' }}
                </td>
                <td style="width: 1%; padding: 2px;">:</td>
                <td style="width: 79%; padding: 2px;">
                    {{ isset($report['hasil_nilai_likuidasi_kjpp']) ? formatRupiah($report['hasil_nilai_likuidasi_kjpp']) : '-' }}
                </td>
            </tr>


        </table>

        <table style="margin: 5px 0; border-collapse: collapse; width: 100%;">
            <tr>
                <td style="">
                    <h6 style="text-transform: uppercase; margin: 0; ">Penilaian ke lokasi objek telah dilakukan oleh :
                    </h6>
                </td>
            </tr>
        </table>

        <table style="width: 100%">
            <tr>
                <td style="width: 25%; padding: 2px;">Staf Subdit Appraisal </td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">
                    {{ formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan) }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">Pihak KJPP</td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $forminspeksi['signature']['kjjp']['name'] ?? $report['pihak_kjjpp'] ?? '' }}</td>
            </tr>
            <tr>
                <td style="width: 25%; padding: 2px;">Pihak BAGI Cab </td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $permohonan->user->name ?? '' }} -
                    {{ $permohonan->debiture->branch->name ?? '' }}</td>
            </tr>

            <tr>
                <td style="width: 25%; padding: 2px;">Debitur/perwakilan debitur </td>
                <td style="width: 1%;  padding: 2px;">:</td>
                <td style="width: 79%;  padding: 2px;">{{ $permohonan->debiture->name ?? '' }}</td>
            </tr>

        </table>

        <table style="margin: 5px 0; border-collapse: collapse; width: 100%;">
            <tr>
                <td style="">
                    <h6 style="text-transform: uppercase; margin: 0; ">Informasi yang didapatkan sebagai berikut : </h6>
                </td>
            </tr>
        </table>
        <table style="margin: 5px 0; border-collapse: collapse; width: 100%;">
            <tr>
                <td style="">
                    <h6 style="text-transform: uppercase; margin: 0; ">Faktor Positif</h2>
                </td>
            </tr>
            <tr>
                @isset($forminspeksi['fakta']['fakta_positif'])
                    @foreach ($forminspeksi['fakta']['fakta_positif'] as $key => $item)
                <tr>
                    <td>{!! nl2br(e($item)) !!}</td>
                </tr>
                @endforeach
            @endisset
            </tr>
        </table>
            <table style="margin: 5px 0; border-collapse: collapse; width: 100%;">
                <tr>
                    <td style="">
                        <h6 style="text-transform: uppercase; margin: 0; ">Faktor negatif</h2>
                    </td>
                </tr>
                <tr>
                    @isset($forminspeksi['fakta']['fakta_negatif'])
                        @foreach ($forminspeksi['fakta']['fakta_negatif'] as $key => $item)
                    <tr>
                        <td>{!! nl2br(e($item)) !!}</td>
                    </tr>
                    @endforeach
                @endisset
                </tr>
            </table>
        <table style="margin: 5px 0; border-collapse: collapse; width: 100%;">
            <tr>
                <td style="">
                    <h6 style="text-transform: uppercase; margin: 0; ">Catatan Yang Perlu Diperhatikan</h6>
                </td>
            </tr>
            <tr>
                @isset($forminspeksi['fakta']['keterangan'])
            @foreach ($forminspeksi['fakta']['keterangan'] as $key => $item)
                <tr>
                    <td>{!! nl2br(e($item)) !!}</td>
                </tr>
            @endforeach
        @endisset
            </tr>
        </table>

        <table style="width: 100%">
            <tr>
                <td>Demikian Kami Sampaikan, atas perhatiannya kami ucapkan terimakasih</td>
            </tr>
            <tr>
               @include('lpj::penilai.components.signature-approval')
            </tr>
        </table>

    </main>

    @include('lpj::penilai.components.footer')
