<div class="card border border-agi-100 bg-white 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 bg-white 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">

                    <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">


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

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

<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 bg-white 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-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Model</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <select
                        class="input tomselect w-full @error('hadapMataAngin') border-danger bg-danger-light  @enderror"
                        name="hadapMataAngin">
                        <option value="">Select Model Kendaraan </option>
                        @if (isset($arahMataAngin))
                            @foreach ($arahMataAngin as $item)
                                <option value="{{ $item->name }}"
                                    {{ old('hadapMataAngin') == $item->name ? 'selected' : '' }}>{{ $item->name }}
                                </option>
                            @endforeach
                        @endif
                    </select>

                    @error('hadapMataAngin')
                        <em class="alert text-danger text-sm">{{ $message }}</em>
                    @enderror
                </div>
            </div>

            @php
                $inputDataJaminan = [];

                $inputDataJaminan = [
                    [
                        'label' => 'Tipe/Model',
                        'name' => 'tipe_model',
                        'index' => 0,
                    ],
                    [
                        'label' => 'Merek',
                        'name' => 'merek',
                        'index' => 1,
                    ],
                    [
                        'label' => 'Tahun Pembuatan',
                        'name' => 'tahun_pembuatan',
                        'index' => 2,
                    ],
                    [
                        'label' => 'Negara Pembuat',
                        'name' => 'negara_pembuat',
                        'index' => 3,
                    ],
                    [
                        'label' => 'Kondisi Mesin',
                        'name' => 'kondisi_mesin',
                        'index' => 4,
                    ],
                ];
            @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'] }}">


                                <em id="error-{{ $item['name'] }}" class="alert text-danger text-sm"></em>

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

            <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                <label class="form-label max-w-56">Deskripsi/Keterangan Lain Lain </label>
                <div class="flex flex-wrap items-baseline w-full">
                    <textarea name="deskripsi" id="" class="textarea"></textarea>
                    @error('deskripsi')
                        <em class="alert text-danger text-sm">{{ $message }}</em>
                    @enderror
                </div>
            </div>
        </div>

        <div class="flex justify-end" style="margin-top: 10px">
            <button class="btn  btn-xs btn-primary" type="button" id="addBagunan">
                tambah mesin
                <i class="ki-filled ki-plus"></i>
            </button>
        </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>
