<div class="card border border-agi-100 rounded-lg shadow-md overflow-hidden">
    <div class="card-header bg-agi-50">
        <h3 class="card-title uppercase">
            Order Penilaian
        </h3>
        <div class="flex items-center gap-2">
            <a href="{{ url()->previous() }}" class="btn btn-xs btn-info">
                <i class="ki-filled ki-exit-left"></i> Back
            </a>
        </div>
    </div>
    <div class="card-body">
        <div class="grid gap-5 grid-cols-2">

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Tujuan Penilaian</label>
                <div class="flex flex-wrap items-baseline w-full">
                    @if (isset($permohonan->tujuanPenilaian))
                        <p class="text-2sm text-gray-700">{{ $permohonan->tujuanPenilaian->name }}</p>
                    @endif
                </div>
            </div>
            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Tanggal Survey</label>
                <div class="flex flex-wrap items-base line w-full">
                    <p class="text-2sm text-gray-700">{{ $permohonan->created_at->format('d/m/Y') }}</p>
                </div>
            </div>

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Cab/Direktorat</label>
                <div class="flex flex-wrap items-baseline w-full">
                    @if (isset($permohonan->branch))
                        <p class="text-2sm text-gray-700">{{ $permohonan->branch->name }}</p>
                    @endif
                </div>
            </div>

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">AO</label>
                <div class="flex flex-wrap items-baseline w-full">
                    @if (isset($permohonan->user))
                        <p class="text-2sm text-gray-700">{{ $permohonan->user->name }}</p>
                    @endif
                </div>
            </div>

        </div>
    </div>
</div>



<div class="card border border-agi-100 rounded-lg shadow-md overflow-hidden">
    <div class="card-header bg-agi-50">
        <h3 class="card-title uppercase">
            Identitas Debitur
        </h3>
    </div>
    <div class="card-body">
        <div class="grid gap-5">

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Nama Calon Debitur</label>
                <div class="flex flex-wrap items-baseline w-full">
                    @if (isset($permohonan->debiture->name))
                        <p class="text-2sm text-gray-700">{{ $permohonan->debiture->name }}</p>
                    @endif
                </div>
            </div>

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Nama Wakil Debitur</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <input type="text" name="nama_wakil" class="input"
                        placeholder="Masukkan Hubungan Calon Debitur" value="{{ $forminspeksi['nama_wakil'] ?? '' }}">
                    <em id="error-nama_wakil" class="alert text-danger text-sm"></em>
                </div>
            </div>
            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Hubungan Calon Debitur</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <input type="text" name="hub_calon_debitur" class="input"
                        placeholder="Masukkan Hubungan Calon Debitur" value="{{$forminspeksi['hub_calon_debitur'] ?? ''}}">

                    <em id="error-hub_calon_debitur" class="alert text-danger text-sm"></em>

                </div>
            </div>
        </div>
    </div>
</div>


{{-- lokasi jaminan --}}
<div class="card border border-agi-100 rounded-lg shadow-md">
        @include('lpj::surveyor.components.lokasi-jaminan')
</div>


<div class="card border border-agi-100 rounded-lg shadow-md overflow-hidden">
    <div class="card-header bg-agi-50">
        <h3 class="card-title uppercase">
            Data Data Jaminan
        </h3>
    </div>

    <div class="card-body">
        <div class="grid gap-5">
            <div class="flex items-stretch flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Model</label>
                <div class="flex-wrap items-stretch">
                    <div class="flex flex-col items-start gap-4">
                        @if (isset($basicData['modelAlatBerat']))
                            @foreach ($basicData['modelAlatBerat'] as $item)
                                <div class="flex items-center">
                                    <label class="form-label flex items-center gap-2.5 text-nowrap">
                                        <input class="checkbox" name="jenis_model[]" 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'
                                                   : '' }}
                                               onclick="toggleCheckboxVisibility('jenis_model', 'jenis_model_lainnya', ['lainnya'])"/>
                                        {{ $item->name }}
                                    </label>
                                    @if (strcasecmp($item->name, 'lainnya') == 0)
                                        <input id="jenis_model_lainnya" type="text"
                                               style="{{ isset($forminspeksi['jenis_model']['lainnya']) && $forminspeksi['jenis_model']['lainnya'] ? '' : 'display: none;' }}"
                                               name="jenis_model_lainnya" class="input w-full mt-2"
                                               placeholder="Masukkan bentuk tanah..."
                                               value="{{ old('jenis_model_lainnya', $forminspeksi['jenis_model']['lainnya'] ?? '') }}"/>
                                    @endif
                                </div>
                            @endforeach
                        @endif
                    </div>
                    <em id="error-jenis_model" class="alert text-danger text-sm"></em>
                </div>
            </div>

            @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

            @if (count($inputDataJaminan) > 0)
                @foreach ($inputDataJaminan as $item)
                    <!-- Nomor Lambung -->
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">{{ $item['label'] }}</label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="text" name="{{ $item['name'] }}" class="input"
                                placeholder="Masukkan {{ $item['label'] }}" value="{{$item['value'] ?? ''}}">
                                <em id="error-{{ $item['name'] }}" class="alert text-danger text-sm"></em>

                        </div>
                    </div>
                @endforeach
            @endif
        </div>
    </div>
</div>



<div class="card border border-agi-100 rounded-lg shadow-md overflow-hidden">
    <div class="card-header bg-agi-50">
        <h3 class="card-title uppercase">
            Kondisi Objek Jaminan
        </h3>
    </div>
    <div class="card-body">

        <div class="grid gap-5">
            @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

            @if (count($kondisiObjeck) > 0)
                @foreach ($kondisiObjeck as $item)
                    <!-- Nomor Lambung -->
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">{{ $item['label'] }}</label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <div class="flex flex-col items-start gap-4">
                                @if (isset($item['value']))
                                    @foreach ($item['value'] as $value)
                                        <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                                            <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 }}
                                            </label>
                                            <input type="text" name="{{ $item['name'] }}_input[]"
                                                class="input w-full"
                                                id="bentukTanahInput-{{ $loop->parent->index }}-{{ $loop->index }}"
                                                placeholder="Masukkan {{ $value }}..."
                                                value="{{ old($item['name'] . '_input.' . $loop->index, $forminspeksi[$item['name'] . '_input'][$loop->index] ?? '') }}">
                                        </div>
                                    @endforeach
                                @endif
                            </div>
                            <div class="w-full">
                                <em id="error-{{ $item['name'] }}" class="alert text-danger text-sm"></em>
                                <em id="error-{{ $item['name'] }}-input-{{ $loop->index }}"
                                    class="alert text-danger text-sm"></em>
                            </div>
                        </div>
                    </div>
                @endforeach
            @endif

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Perusahaan Asuransi</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <input type="text" name="perusahaan_asuransi" class="input"
                        placeholder="Pesurahaan Asuransi" value={{$forminspeksi['perusahaan_asuransi'] ?? ''}}>
                    <em class="alert text-danger text-sm"></em>

                </div>
            </div>

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Tahun Berakhir</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <input type="date" name="tahun_berakhir" class="input" placeholder="Tahun berakhir" value={{$forminspeksi['tahun_berakhir'] ?? ''}}>
                    <em class="alert text-danger text-sm"></em>

                </div>
            </div>
        </div>
    </div>
</div>


<div class="card border border-agi-100 rounded-lg  overflow-hidden">
    <div class="card-header bg-agi-50">
        <h3 class="card-title uppercase">
            Analisis Fakta
        </h3>
    </div>
    <div class="card-body">
        <div class="grid gap-5">
            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Faktor Positif</label>
                <div id="fakta-positif-container" class="flex flex-wrap items-baseline w-full">
                    @if (!empty($forminspeksi['fakta_positif']))
                        @foreach ($forminspeksi['fakta_positif'] as $index => $positif)
                            <div class="fakta_positif flex items-center gap-2 mt-2 textarea-group w-full">
                                <textarea class="textarea mt-2" name="fakta_positif[]" rows="10">{{ old("fakta_positif.$index", $positif) }}</textarea>
                                <button class="btn btn-danger btn-sm remove-btn" type="button"
                                    style="display: none;">
                                    <i class="ki-outline ki-trash"></i>
                                </button>
                            </div>
                        @endforeach
                    @else
                        <div class="fakta_positif flex items-center gap-2 mt-2 textarea-group w-full">
                            <textarea class="textarea mt-2" name="fakta_positif[]" rows="10">{{ old('fakta_positif.0', '') }}</textarea>
                            <button class="btn btn-danger btn-sm remove-btn" type="button" style="display: none;">
                                <i class="ki-outline ki-trash"></i>
                            </button>
                        </div>
                    @endif
                    <button type="button" class="btn btn-primary btn-sm mt-5"
                        onclick="addClonableItem('fakta-positif-container', 'fakta_positif')">
                        <i class="ki-outline ki-plus"></i>
                    </button>
                </div>
            </div>

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Faktor Negatif</label>
                <div id="fakta-negatif-container" class="flex flex-wrap items-baseline w-full">

                    @if (!empty($forminspeksi['fakta_negatif']))
                        @foreach ($forminspeksi['fakta_negatif'] as $index => $negatif)
                            <div class="fakta_negatif flex items-center gap-2 mt-2 textarea-group w-full">
                                <textarea class="textarea mt-2" name="fakta_negatif[]" rows="10">{{ old("fakta_negatif.$index", $negatif) }}</textarea>
                                <button class="btn btn-danger btn-sm remove-btn" type="button"
                                    style="display: none;">
                                    <i class="ki-outline ki-trash"></i>
                                </button>
                            </div>
                        @endforeach
                    @else
                        <div class="fakta_negatif flex items-center gap-2 mt-2 textarea-group w-full">
                            <textarea class="textarea mt-2" name="fakta_negatif[]" rows="10">{{ old('fakta_negatif.0', $forminspeksi['fakta_negatif'][0] ?? '') }}</textarea>
                            <button class="btn btn-danger btn-sm remove-btn" type="button" style="display: none;">
                                <i class="ki-outline ki-trash"></i>
                            </button>
                            <em id="error-fakta_negatif" class="alert text-danger text-sm"></em>
                        </div>
                    @endif
                    <button type="button" class="btn btn-primary btn-sm mt-5"
                        onclick="addClonableItem('fakta-negatif-container', 'fakta_negatif')">
                        <i class="ki-outline ki-plus"></i>
                    </button>
                </div>
            </div>

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Catatan Yang Perlu Diperhatikan</label>
                <div id="catatan-container" class="flex flex-wrap items-baseline w-full">
                    <div class="catatan flex items-center gap-2 mt-2 textarea-group w-full">
                        <textarea class="textarea mt-2" name="catatan[]" rows="10">{{ old('catatan.0', $forminspeksi['catatan'][0] ?? '') }}</textarea>
                        <button class="btn btn-danger btn-sm remove-btn" type="button" style="display: none;">
                            <i class="ki-outline ki-trash"></i>
                        </button>
                        <em id="error-catatan" class="alert text-danger text-sm"></em>
                    </div>
                    <button type="button"
                        onclick="addClonableItem('catatan-container', 'catatan')"
                        class="btn btn-primary btn-sm mt-5 ">
                        <i class="ki-outline ki-plus"></i>
                    </button>
                </div>

            </div>

        </div>
    </div>
</div>
