@include('lpj::surveyor.components.print-out.header')

<div style="border: 1px solid #000;">
    <table
        style="width: 100%; border-top: none; border-bottom: 1px solid #000; border-collapse: collapse; border-left: none; border-right: none;">

        <tr>
            <td style="text-align: center; margin-top: 5px; ">
                <h2 style=" text-transform: uppercase; text-align: center; margin: 0;">
                    Tujuan Penilaian
                </h2>
            </td>
        </tr>
    </table>
    <table style="width: 100%;">
        <tr>
            <td style="vertical-align: top;">
                <table>
                    <tr>

                        <td style="width: 25%; padding: 2px;">Tujuan Penilai</td>
                        <td style="width: 1%; padding: 2px;">:</td>
                        <td style="vertical-align: top;  padding: 2px;">
                            {{ $permohonan->tujuanPenilaian->name ?? '' }}</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 ?? '' }} / {{ $permohonan->user->name ?? '' }}
                        </td>
                    </tr>
                </table>
            </td>

            <td style="vertical-align: top;">
                <table>
                    <tr>
                        <td style="width: 25%; padding: 2px; vertical-align: top;">Tanggal Dibuat</td>
                        <td style="width: 1%; vertical-align: top;">:</td>
                        <td style="vertical-align: top;  vertical-align: top;">
                            {{ formatTanggalIndonesia($permohonan->created_at) }}
                        </td>
                    </tr>
                    <tr>

                        <td style="width: 25%; padding: 2px;">
                            Tanggal Survey</td>
                        <td style="width: 1%; padding: 2px;">:</td>
                        <td style="vertical-align: top;  padding: 2px;">
                            {{ formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan) }}</td>
                    </tr>

                </table>
            </td>
        </tr>
    </table>

    <table
        style="width: 100%; border-top: 1px solid #000; border-bottom: 1px solid #000; border-collapse: collapse; border-left: none; border-right: none;">

        <tr>
            <td style="text-align: center; margin-top: 5px; ">
                <h2 style=" text-transform: uppercase; text-align: center; margin: 0;">
                    Identitas Debitur
                </h2>
            </td>
        </tr>
    </table>
    <table style="width: 100%">
        <tr>
            <td style="width: 20%; padding: 2px; vertical-align: top;">Nama</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td style="vertical-align: top; width: 79%;">{{ $permohonan->debiture->name ?? '' }}</td>
        </tr>
        <tr>
            <td style="width: 20%; padding: 2px; vertical-align: top;">Nama Wakil</td>
            <td style="width: 1%;  padding: 2px; vertical-align: top;">:</td>
            <td style="vertical-align: top;  padding: 2px;">
               {{ $forminspeksi['nama_wakil'] ?? '' }}
            </td>
        </tr>
        <tr>
            <td style="width: 20%; padding: 2px; vertical-align: top;">Hubungan Calon debitur</td>
            <td style="width: 1%;  padding: 2px; vertical-align: top;">:</td>
            <td style="vertical-align: top;  padding: 2px;">
               {{ $forminspeksi['hub_calon_debitur'] ?? '' }}
            </td>
        </tr>
    </table>

    <table
        style="width: 100%; border-top: 1px solid #000; border-bottom: 1px solid #000; border-collapse: collapse; border-left: none; border-right: none;">

        <tr>
            <td style="text-align: center; margin-top: 5px; ">
                <h2 style=" text-transform: uppercase; text-align: center; margin: 0;">
                    Lokasi Jaminan
                </h2>
            </td>
        </tr>
    </table>
    <table style="width: 100%">


        <tr>
            <td width="20%">Nama Jalan</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td> {{ $forminspeksi['nama_jalan'] ?? '' }}</td>
        </tr>
        <tr>
            <td width="20%">Perumahan/Gang</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td> {{ $forminspeksi['perumahan_gang'] ?? '' }}</td>
        </tr>
        <tr>
            <td width="20%">Blok/Nomor</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td> {{ $forminspeksi['blok_nomor'] ?? '' }}</td>
        </tr>
        <tr>
            <td>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>Kotamadya</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td> {{ $alamat['city_code'] ?? '' }}</td>
        </tr>
        <tr>
            <td>Propinsi</td>
            <td style="width: 1%; vertical-align: top;">:</td>
            <td>{{ $alamat['province_code'] ?? '' }}</td>
        </tr>

    </table>

    <div>
        <table
            style="width: 100%; border-top: 1px solid #000; border-bottom: 1px solid #000; border-collapse: collapse; border-left: none; border-right: none;">
            <tr>
                <td style="text-align: center; margin-top: 5px; ">
                    <h2 style=" text-transform: uppercase; text-align: center; margin: 0;">
                        Data data jaminan
                    </h2>
                </td>
            </tr>
        </table>

        <table style="width: 100%;">
            <tr>
                <td style="vertical-align: top; width: 25%;">Model</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td width="100%" style="vertical-align: top;">
                    <table style="width: 100%;">
                        @if (isset($basicData['modelAlatBerat']))
                            @foreach ($basicData['modelAlatBerat'] as $item)
                                <tr>
                                    <td width="40%">
                                        <label class="form-label max-w-56 gap-2.5">
                                            <input class="checkbox" name="kendaraan[]" type="checkbox"
                                                value="{{ $item->name }}"
                                                {{ in_array($item->name, old('jenis_model', [])) ||
                                                (isset($forminspeksi['jenis_model']) &&
                                                    is_array($forminspeksi['jenis_model']) &&
                                                    in_array($item->name, $forminspeksi['jenis_model']))
                                                    ? 'checked'
                                                    : '' }} />
                                            {{ $item->name }}
                                        </label>
                                    </td>
                                    <td width="1%"></td>
                                    <td width="100%">
                                        <p>{{ old('kendaraan_input.' . $loop->index, $forminspeksi['kendaraan_input'][$loop->index] ?? '') }}
                                        </p>
                                    </td>
                                </tr>
                            @endforeach
                        @endif
                    </table>
                </td>
            </tr>

            @php
                $inputDataJaminan = [
                    [
                        'label' => 'Nomor Lambung',
                        'name' => 'nomor_lambung',
                        'index' => 0,
                        'value' => old('nomor_lambung', $forminspeksi['nomor_lambung'] ?? ''),
                    ],
                    [
                        'label' => 'Model Unit',
                        'name' => 'model_unit',
                        'index' => 1,
                        'value' => old('model_unit', $forminspeksi['model_unit'] ?? ''),
                    ],
                    [
                        'label' => 'Tahun Pembuatan',
                        'name' => 'tahun_pembuatan',
                        'index' => 2,
                        'value' => old('tahun_pembuatan', $forminspeksi['tahun_pembuatan'] ?? ''),
                    ],
                    [
                        'label' => 'Merk',
                        'name' => 'merk',
                        'index' => 3,
                        'value' => old('merk', $forminspeksi['merk'] ?? ''),
                    ],
                    [
                        'label' => 'Negara Pembuat',
                        'name' => 'negara_pembuat',
                        'index' => 4,
                        'value' => old('negara_pembuat', $forminspeksi['negara_pembuat'] ?? ''),
                    ],
                    [
                        'label' => 'Tahun Pembelian',
                        'name' => 'tahun_pembelian',
                        'index' => 5,
                        'value' => old('tahun_pembelian', $forminspeksi['tahun_pembelian'] ?? ''),
                    ],
                    [
                        'label' => 'Nomor Faktur/Invoice',
                        'name' => 'nomor_faktur',
                        'index' => 6,
                        'value' => old('nomor_faktur', $forminspeksi['nomor_faktur'] ?? ''),
                    ],
                    [
                        'label' => 'Nomor Kontrak Pembelian',
                        'name' => 'nomor_kontrak',
                        'index' => 7,
                        'value' => old('nomor_kontrak', $forminspeksi['nomor_kontrak'] ?? ''),
                    ],
                    [
                        'label' => 'Nama Pemilik',
                        'name' => 'nama_pemilik',
                        'index' => 8,
                        'value' => old('nama_pemilik', $forminspeksi['nama_pemilik'] ?? ''),
                    ],
                    [
                        'label' => 'Alamaat Pemilik',
                        'name' => 'alamat_pemilik',
                        'index' => 9,
                        'value' => old('alamat_pemilik', $forminspeksi['alamat_pemilik'] ?? ''),
                    ],
                    [
                        'label' => 'Nomor Asuransi',
                        'name' => 'nomor_asuransi',
                        'index' => 10,
                        'value' => old('nomor_asuransi', $forminspeksi['nomor_asuransi'] ?? ''),
                    ],
                    [
                        'label' => 'Nomor Rangka',
                        'name' => 'nomor_rangka',
                        'index' => 11,
                        'value' => old('nomor_rangka', $forminspeksi['nomor_rangka'] ?? ''),
                    ],
                    [
                        'label' => 'Nomor Mesin',
                        'name' => 'nomor_mesin',
                        'index' => 12,
                        'value' => old('nomor_mesin', $forminspeksi['nomor_mesin'] ?? ''),
                    ],
                    [
                        'label' => 'Hour Meters',
                        'name' => 'hour_mesters',
                        'index' => 13,
                        'value' => old('hour_mesters', $forminspeksi['hour_mesters'] ?? ''),
                    ],
                    [
                        'label' => 'Overhaul Mesin',
                        'name' => 'overhaul_mesin',
                        'index' => 14,
                        'value' => old('overhaul_mesin', $forminspeksi['overhaul_mesin'] ?? ''),
                    ],
                ];

            @endphp

            @foreach ($inputDataJaminan as $item)
                <tr>
                    <td width="20%" style="vertical-align: top;">{{ $item['label'] }}</td>
                    <td width="1%" style="vertical-align: top;">:</td>
                    <td width="100%" style="vertical-align: top;">
                        {{ $item['value'] ?? '' }}
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
    <div>
        <table
            style="width: 100%; border-top: 1px solid #000; border-bottom: 1px solid #000; border-collapse: collapse; border-left: none; border-right: none;">
            <tr>
                <td style="text-align: center; margin-top: 5px; ">
                    <h2 style=" text-transform: uppercase; text-align: center; margin: 0;">
                        Kondisi Fisik Objek
                    </h2>
                </td>
            </tr>
        </table>

        <table style="width: 100%;">


            @php
                $kondisiObjeck = [
                    [
                        'label' => 'Mesin dan Panel Instrument',
                        'value' => ['Terawat', 'Cukup Terawat', 'Tidak Terawat'],
                        'name' => 'mesin_panel',
                        'index' => 0,
                    ],
                    [
                        'label' => 'Fungsi mesin dan panel instrument',
                        'value' => ['Berfungsi', 'Rusak'],
                        'name' => 'fungsi_panel',
                        'index' => 1,
                    ],
                    [
                        'label' => 'Interior (jok, dll)',
                        'value' => ['Terawat', 'Cukup Terawat', 'Tidak Terawat'],
                        'name' => 'interior',
                        'index' => 2,
                    ],
                    [
                        'label' => 'Rangka dan Karoseri',
                        'value' => ['Terawat', 'Cukup Terawat', 'Tidak Terawat'],
                        'name' => 'rangka_Karoseri',
                        'index' => 3,
                    ],
                    [
                        'label' => 'Ban',
                        'value' => ['Standard', 'Tidak Standard'],
                        'name' => 'ban',
                        'index' => 4,
                    ],
                    [
                        'label' => 'Velg',
                        'value' => ['Standard', 'Tidak Standard'],
                        'name' => 'velg',
                        'index' => 5,
                    ],
                    [
                        'label' => 'Air Conditioner',
                        'value' => ['Ada', 'Tidak Ada'],
                        'name' => 'air_conditioner',
                        'index' => 6,
                    ],
                    [
                        'label' => 'Aksesoris Tambahan lainnya',
                        'value' => ['Ada', 'Tidak Ada'],
                        'name' => 'aksesoris',
                        'index' => 7,
                    ],
                    [
                        'label' => 'LCD',
                        'value' => ['Ada', 'Tidak Ada'],
                        'name' => 'lcd',
                        'index' => 8,
                    ],
                    [
                        'label' => 'Perlengkapan Keamanan',
                        'value' => ['Ada', 'Tidak Ada'],
                        'name' => 'perlengkapan',
                        'index' => 9,
                    ],
                    [
                        'label' => 'Asuransi',
                        'value' => ['Ada', 'Tidak Ada'],
                        'name' => 'asuransi',
                        'index' => 10,
                    ],
                ];

            @endphp


            @foreach ($kondisiObjeck as $item)
                <tr>
                    <td style="vertical-align: top; width: 25%;">{{ $item['label'] }}</td>
                    <td width="1%" style="vertical-align: top;">:</td>
                    <td style="vertical-align: top;">
                        <table style="width: 100%; border-collapse: collapse;">
                            @foreach ($item['value'] as $value)
                                <tr>
                                    <td>
                                        <label class="form-label max-w-56 gap-2.5" style="width: 500px">
                                            <input class="checkbox" name="{{ $item['name'] }}[]" type="checkbox"
                                                value="{{ $value }}"
                                                {{ in_array($value, old($item['name'], $forminspeksi[$item['name']] ?? [])) ? 'checked' : '' }} />
                                            {{ $value }}
                                            @if ($forminspeksi[$item['name'] . '_input'][$loop->index] != null)
                                                -
                                                {{ old($item['name'] . '_input' . $loop->index, $forminspeksi[$item['name'] . '_input'][$loop->index] ?? '') }}
                                            @endif
                                        </label>
                                    </td>

                                </tr>
                            @endforeach
                        </table>
                    </td>
                </tr>
            @endforeach

            <tr>
                <td style="vertical-align: top;">Perusahaan Asuransi</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td width="100%" style="vertical-align: top;">{{ $forminspeksi['perusahaan_asuransi'] ?? '' }}</td>
            </tr>

            <tr>
                <td style="vertical-align: top;">Tahun Berakhir</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td width="100%" style="vertical-align: top;">
                    {{ isset($forminspeksi['tahun_berakhir']) ? formatTanggalIndonesia($forminspeksi['tahun_berakhir']) : '' }}
                </td>
            </tr>
        </table>
    </div>


    <div>
        <table
            style="width: 100%; border-top: 1px solid #000; border-bottom: 1px solid #000; border-collapse: collapse; border-left: none; border-right: none;">


            <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 style="width: 100%">
            <tr>
                <td width="25%" 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_positif'])
                        <table style="width: 100%; border-collapse: collapse;">
                            @foreach ($forminspeksi['fakta_positif'] as $key => $item)
                                <tr>
                                    <td>{!! nl2br(e($item)) !!}</td>
                                </tr>
                            @endforeach
                        </table>
                    @endisset
                </td>
            </tr>
            <tr>
                <td width="25%" 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_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>



            <tr>
                <td width="20%" style="vertical-align: top;">Catatan yang perlu di perhatikan</td>
                <td width="1%" style="vertical-align: top;">:</td>
                <td width="100%" style="vertical-align: top;">
                    @php
                        $faktaNegatif = $forminspeksi['catatan'] ?? [];
                        $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>
        </table>
    </div>



</div>


@include('lpj::surveyor.components.print-out.footer')
