@extends('layouts.main')

@section('breadcrumbs')
    {{ Breadcrumbs::render('laporan-admin-kredit-edit', $laporanAdminKredit) }}
@endsection

@section('content')
    <div class="grid gap-5 mx-auto w-full lg:gap-7.5">
        <div class="border card border-agi-100">
            <div class="py-5 card-header bg-agi-50">
                <h3 class="card-title">
                    Edit Laporan Admin Kredit
                </h3>
            </div>
            <div class="card-body">
                <form action="{{ route('admin-kredit.laporan.update', $laporanAdminKredit->id) }}" method="POST"
                    class="grid gap-5">
                    @csrf
                    @method('PUT')

                    <div class="grid grid-cols-1 gap-5 md:grid-cols-2">
                        <!-- Editable Fields -->
                        <div class="form-group">
                            <label for="kode_register_t24" class="form-label">Kode Register T24</label>
                            <input type="text" name="kode_register_t24" id="kode_register_t24" class="input"
                                value="{{ $laporanAdminKredit->kode_register_t24 }}" required>
                        </div>

                        <div class="form-group">
                            <label for="cif" class="form-label">CIF</label>
                            <input type="text" name="cif" id="cif" class="input"
                                value="{{ $laporanAdminKredit->debiture ? $laporanAdminKredit->debiture->cif : '' }}"
                                required>
                        </div>

                        <!-- Read-only Information Fields -->
                        <div class="form-group">
                            <label class="form-label">Nama Debitur</label>
                            <div class="bg-gray-100 input">
                                {{ $laporanAdminKredit->debiture ? $laporanAdminKredit->debiture->name : '' }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Cabang</label>
                            <div class="bg-gray-100 input">
                                {{ $laporanAdminKredit->debiture ? $laporanAdminKredit->debiture->branch->name : '' }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Jenis Agunan</label>
                            <div class="bg-gray-100 input">{{ $laporanAdminKredit->jenis_agunan }}</div>
                        </div>
                        <div class="form-group">
                            <label class="form-label">Nama Pemilik</label>
                            <div class="bg-gray-100 input">{{ $laporanAdminKredit->nama_pemilik }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Bukti Kepemilikan</label>
                            <div class="textarea bg-gray-100 h-auto min-h-[100px] p-3">
                                {{ $laporanAdminKredit->bukti_kepemilikan }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Alamat Agunan</label>
                            <div class="textarea bg-gray-100 h-auto min-h-[100px] p-3">
                                {{ $laporanAdminKredit->alamat_agunan }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Tanggal Kunjungan</label>
                            <div class="bg-gray-100 input">
                                {{ \Carbon\Carbon::parse($laporanAdminKredit->tanggal_kunjungan)->format('d-m-Y') }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Nilai Pasar Wajar</label>
                            <div class="bg-gray-100 input">
                                {{ number_format($laporanAdminKredit->nilai_pasar_wajar, 0, ',', '.') }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Nilai Likuidasi</label>
                            <div class="bg-gray-100 input">
                                {{ number_format($laporanAdminKredit->nilai_likuidasi, 0, ',', '.') }}</div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Nama Penilai</label>
                            <div class="bg-gray-100 input">{{ $laporanAdminKredit->nama_penilai }}</div>
                        </div>

                        <div class="form-group">
                            <label for="kolektibilitas" class="form-label">Kolektibilitas</label>
                            <select class="input" id="kolektibilitas" name="kolektibilitas">
                                <option value="">Pilih Kolektibilitas</option>
                                <option value="1"
                                    {{ old('kolektibilitas', $laporanAdminKredit->kolektibilitas ?? '') == '1' ? 'selected' : '' }}>
                                    Kolektibilitas 1 - Lancar</option>
                                <option value="2"
                                    {{ old('kolektibilitas', $laporanAdminKredit->kolektibilitas ?? '') == '2' ? 'selected' : '' }}>
                                    Kolektibilitas 2 - Dalam Perhatian Khusus</option>
                                <option value="3"
                                    {{ old('kolektibilitas', $laporanAdminKredit->kolektibilitas ?? '') == '3' ? 'selected' : '' }}>
                                    Kolektibilitas 3 - Kurang Lancar</option>
                                <option value="4"
                                    {{ old('kolektibilitas', $laporanAdminKredit->kolektibilitas ?? '') == '4' ? 'selected' : '' }}>
                                    Kolektibilitas 4 - Diragukan</option>
                                <option value="5"
                                    {{ old('kolektibilitas', $laporanAdminKredit->kolektibilitas ?? '') == '5' ? 'selected' : '' }}>
                                    Kolektibilitas 5 - Macet</option>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="keterangan" class="form-label">Keterangan</label>
                            <input class="textarea" id="input" name="keterangan"
                                placeholder="Masukkan keterangan tambahan..."
                                value={{ old('keterangan', $laporanAdminKredit->keterangan ?? '') }}>
                        </div>
                    </div>

                    <div class="flex gap-3 justify-end">
                        <a href="{{ route('admin-kredit.laporan.index') }}" class="btn btn-light">Cancel</a>
                        <button type="submit" class="btn btn-primary">Update</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
