@extends('layouts.auth')

@push('styles')
<style>
    @media print {
        body {
            font-size: 10pt;
            color: #000;
            background-color: #fff;
            line-height: 1.4;
        }
        .container {
            width: 100%;
            max-width: 100%;
            padding: 0;
            margin: 0;
        }
        .crd {
            border: none !important;
            box-shadow: none !important;
            margin-bottom: 15px;
        }
        .crd-header {
            background-color: #f1f1f1 !important;
            -webkit-print-color-adjust: exact;
            padding: 3px 8px !important; /* Mengubah padding menjadi lebih tipis */
            font-weight: bold;
            font-size: 11pt; /* Sedikit memperkecil ukuran font */
        }

        .crd-body {
            padding: 8px !important; /* Menyesuaikan padding body agar seimbang */
        }
        .no-print {
            display: none !important;
        }
        .page-break {
            page-break-before: always;
        }
        h1 {
            font-size: 16pt;
            margin-bottom: 15px;
        }
        h3 {
            font-size: 12pt;
            margin: 0;
        }
        h4 {
            font-size: 11pt;
            margin: 10px 0 5px;
        }
        p {
            margin: 0 0 5px;
        }
        .grid {
            display: flex;
            flex-wrap: wrap;
        }
        .col-1 {
            flex: 0 0 33.333%;
            max-width: 33.333%;
        }
        .col-2 {
            flex: 0 0 66.666%;
            max-width: 66.666%;
        }
    }
</style>
@endpush

@section('content')
<div class="container" id="printtable">

    <div class="crd">
        <div class="crd-body">
            <table style="width: 100%; border-collapse: collapse;">
                <tr>
                    <td style="width: 40%; vertical-align: top; padding-right: 10px;">
                        @include('lpj::component.logo-bag')
                    </td>
                    <td style="width: 60%; vertical-align: top; text-align: right;">
                        <h1 style="font-size: 12pt; margin: 0; font-weight: bold;">PT BANK ARTHA GRAHA INTERNASIONAL</h1>
                        <p style="font-size: 10pt; margin:0;">Sub Direktorat Appraisal</p>
                        <p style="font-size: 10pt; margin: 0;">Jl. Kwitang Raya No. 24-26,<br>Jakarta – 10420, Indonesia</p>
                        <p style="font-size: 10pt; margin: 0;">Telp. (021) 3903040</p>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div class="crd">
        <div class="crd-body">
            <div class="grid">
                <div class="col-1">
                    <p><strong>Nomor Register:</strong> {{ $permohonan->nomor_registrasi }}</p>
                    <p><strong>Pemohon:</strong> {{ $permohonan->user->nik }} | {{ $permohonan->user->name }}</p>
                    <p><strong>Tujuan Permohonan:</strong> {{ $permohonan->tujuanPenilaian->name }}</p>
                </div>
                <div class="col-1">
                    <p><strong>Status Permohonan:</strong> {{ ucwords($permohonan->status) }}</p>
                    <p><strong>Cabang Pemohon:</strong> {{ $permohonan->user->branch->name }}</p>
                    <p><strong>Tanggal Permohonan:</strong> {{ formatTanggalIndonesia($permohonan->created_at) }}</p>
                </div>
            </div>
        </div>
    </div>

    <div class="grid">
        <div class="col-1">
            <div class="crd">
                <div class="crd-header">1. Fasilitas Kredit</div>
                <div class="crd-body">
                    <p><strong>Jenis Fasilitas:</strong> {{ $permohonan->jenisFasilitasKredit->name }}</p>
                    <p><strong>Nilai Plafond:</strong> {{ $permohonan->nilaiPlafond->name }}</p>
                </div>
            </div>

            <div class="crd">
                <div class="crd-header">2. Identitas Debitur</div>
                <div class="crd-body">
                    <p><strong>Nama:</strong> {{ $permohonan->debiture->name ?? "" }}</p>
                    <p><strong>Cabang:</strong> {{ $permohonan->debiture->branch->name ?? "" }}</p>
                    <p><strong>CIF:</strong> {{ $permohonan->debiture->cif ?? "" }}</p>
                    <p><strong>Alamat:</strong> {{ $permohonan->debiture->address ?? "" }}</p>
                    <p>{{ $permohonan->debiture->village->name ?? "" }}, {{ $permohonan->debiture->district->name ?? "" }}, {{ $permohonan->debiture->city->name ?? "" }}, {{ $permohonan->debiture->province->name ?? "" }} - {{ $permohonan->debiture->village->postal_code ?? "" }}</p>
                </div>
            </div>
        </div>

        <div class="col-2">
            <div class="crd">
                <div class="crd-header">3. Data Jaminan</div>
                <div class="crd-body">
                    @foreach($permohonan->documents as $index => $dokumen)
                        <h4>Jaminan {{ $index + 1 }}</h4>
                        <p><strong>Pemilik Jaminan:</strong> {{ $dokumen->pemilik->name ?? "" }}</p>
                        <p><strong>Jenis Jaminan:</strong> {{ $dokumen->jenisJaminan->name ?? "" }}</p>
                        <p><strong>Hubungan Pemilik Jaminan:</strong> {{ $dokumen->pemilik->hubungan_pemilik->name ?? "" }}</p>
                        @if(!$loop->last)<hr style="margin: 10px 0;">@endif
                    @endforeach
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('scripts')
    <script type="module">
        window.onload = function() {
            window.print();
        }
    </script>
@endpush
