@extends('layouts.main')

@section('breadcrumbs')
    {{ Breadcrumbs::render('memo.show') }}
@endsection

@section('content')
    <div class="grid gap-5 mx-auto w-full lg:gap-7.5">
        <!-- Header -->
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">
                    Detail Memo Penyelesaian
                </h3>
                <div class="flex gap-2 items-center">
                    <a href="{{ route('memo.index') }}" class="btn btn-sm btn-light">
                        <i class="ki-filled ki-black-left"></i>
                        Kembali
                    </a>
                    <button onclick="window.print()" class="btn btn-sm btn-primary">
                        <i class="ki-filled ki-printer"></i>
                        Cetak
                    </button>
                </div>
            </div>
        </div>

        <!-- Detail Memo -->
        <div class="card">
            <div class="bg-gray-50 card-header">
                <h4 class="text-lg card-title">
                    Informasi Memo Penyelesaian
                </h4>
            </div>

            <div class="card-body">
                <div class="grid grid-cols-1 gap-6 mb-8 lg:grid-cols-2">
                    <div class="space-y-4">
                        <div>
                            <label class="text-sm font-medium text-gray-600">Judul Memo:</label>
                            <p class="mt-1 font-semibold text-gray-900">
                                {{ $permohonan->memo_penyelesaian_title ?? 'Belum ada memo' }}
                            </p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Tanggal Memo:</label>
                            <p class="mt-1 text-gray-900">
                                @if ($permohonan->memo_penyelesaian_date)
                                    {{ \Carbon\Carbon::parse($permohonan->memo_penyelesaian_date)->format('d F Y') }}
                                @else
                                    -
                                @endif
                            </p>
                        </div>
                    </div>

                    <div class="space-y-4">
                        <div>
                            <label class="text-sm font-medium text-gray-600">Status:</label>
                            <p class="mt-1">
                                @if ($permohonan->status === 'memo-penyelesaian')
                                    <span class="uppercase badge badge-success">{{ $permohonan->status }}</span>
                                @else
                                    <span class="uppercase badge badge-warning">{{ $permohonan->status }}</span>
                                @endif
                            </p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Dibuat Pada:</label>
                            <p class="mt-1 text-gray-900">
                                @if ($permohonan->memo_penyelesaian_created_at)
                                    {{ \Carbon\Carbon::parse($permohonan->memo_penyelesaian_created_at)->format('d F Y H:i') }}
                                @else
                                    -
                                @endif
                            </p>
                        </div>
                    </div>
                </div>

                @if ($permohonan->memo_penyelesaian_content)
                    <div class="mb-8">
                        <label class="block mb-3 text-sm font-medium text-gray-600">Isi Memo:</label>
                        <div class="p-4 bg-gray-50 rounded-lg border">
                            <div class="max-w-none prose">
                                {!! nl2br(e($permohonan->memo_penyelesaian_content)) !!}
                            </div>
                        </div>
                    </div>
                @endif
            </div>
        </div>

        <!-- Detail Permohonan -->
        <div class="card">
            <div class="bg-blue-50 card-header">
                <h4 class="text-lg card-title">
                    Detail Permohonan
                </h4>
            </div>

            <div class="card-body">
                <div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
                    <div class="space-y-4">
                        <div>
                            <label class="text-sm font-medium text-gray-600">Nomor Registrasi:</label>
                            <p class="mt-1 font-semibold text-gray-900">{{ $permohonan->nomor_registrasi }}</p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Debitur:</label>
                            <p class="mt-1 text-gray-900">{{ $permohonan->debiture->name ?? '-' }}</p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Cabang/Direktorat:</label>
                            <p class="mt-1 text-gray-900">{{ $permohonan->branch->name ?? '-' }}</p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Account Officer:</label>
                            <p class="mt-1 text-gray-900">{{ $permohonan->user->name ?? '-' }}</p>
                        </div>
                    </div>

                    <div class="space-y-4">
                        <div>
                            <label class="text-sm font-medium text-gray-600">Tujuan Penilaian:</label>
                            <p class="mt-1">
                                @if ($permohonan->tujuanPenilaian)
                                    <span class="badge badge-primary">{{ $permohonan->tujuanPenilaian->name }}</span>
                                @else
                                    -
                                @endif
                            </p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Fasilitas Kredit:</label>
                            <p class="mt-1 text-gray-900">{{ $permohonan->jenisFasilitasKredit->name ?? '-' }}</p>
                        </div>

                        <div>
                            <label class="text-sm font-medium text-gray-600">Tanggal Permohonan:</label>
                            <p class="mt-1 text-gray-900">
                                @if ($permohonan->tanggal_permohonan)
                                    {{ \Carbon\Carbon::parse($permohonan->tanggal_permohonan)->format('d F Y') }}
                                @else
                                    -
                                @endif
                            </p>
                        </div>

                        @if ($permohonan->nilai_liquidasi)
                            <div>
                                <label class="text-sm font-medium text-gray-600">Nilai Liquidasi:</label>
                                <p class="mt-1 font-semibold text-gray-900">
                                    Rp {{ number_format($permohonan->nilai_liquidasi, 0, ',', '.') }}
                                </p>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <!-- Informasi Penilaian -->
        @if ($permohonan->penilaian)
            <div class="card">
                <div class="bg-green-50 card-header">
                    <h4 class="text-lg card-title">
                        Informasi Penilaian
                    </h4>
                </div>

                <div class="card-body">
                    <div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
                        <div class="space-y-4">
                            @if ($permohonan->penilaian->waktu_penilaian)
                                <div>
                                    <label class="text-sm font-medium text-gray-600">Waktu Penilaian:</label>
                                    <p class="mt-1 text-gray-900">
                                        {{ \Carbon\Carbon::parse($permohonan->penilaian->waktu_penilaian)->format('d F Y H:i') }}
                                    </p>
                                </div>
                            @endif

                            @if ($permohonan->penilai)
                                <div>
                                    <label class="text-sm font-medium text-gray-600">Tipe Penilai:</label>
                                    <p class="mt-1">
                                        <span
                                            class="uppercase badge badge-info">{{ $permohonan->penilai->type_penilai ?? '-' }}</span>
                                    </p>
                                </div>
                            @endif
                        </div>

                        <div class="space-y-4">
                            @if ($permohonan->penilaian->created_at)
                                <div>
                                    <label class="text-sm font-medium text-gray-600">Dibuat Pada:</label>
                                    <p class="mt-1 text-gray-900">
                                        {{ \Carbon\Carbon::parse($permohonan->penilaian->created_at)->format('d F Y H:i') }}
                                    </p>
                                </div>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        @endif

        <!-- Informasi Approval -->
        <div class="card">
            <div class="bg-yellow-50 card-header">
                <h4 class="text-lg card-title">
                    Status Approval
                </h4>
            </div>

            <div class="card-body">
                <div class="grid grid-cols-1 gap-6 lg:grid-cols-3">
                    <div class="p-4 text-center rounded-lg border">
                        <div class="mb-2">
                            @if ($permohonan->approval_so_at)
                                <i class="text-3xl text-green-500 ki-filled ki-check-circle"></i>
                            @else
                                <i class="text-3xl text-gray-400 ki-filled ki-time"></i>
                            @endif
                        </div>
                        <h5 class="font-semibold text-gray-900">Senior Officer</h5>
                        <p class="mt-1 text-sm text-gray-600">
                            @if ($permohonan->approval_so_at)
                                Disetujui pada<br>
                                {{ \Carbon\Carbon::parse($permohonan->approval_so_at)->format('d F Y H:i') }}
                            @else
                                Menunggu Persetujuan
                            @endif
                        </p>
                    </div>

                    <div class="p-4 text-center rounded-lg border">
                        <div class="mb-2">
                            @if ($permohonan->approval_eo_at)
                                <i class="text-3xl text-green-500 ki-filled ki-check-circle"></i>
                            @else
                                <i class="text-3xl text-gray-400 ki-filled ki-time"></i>
                            @endif
                        </div>
                        <h5 class="font-semibold text-gray-900">Executive Officer</h5>
                        <p class="mt-1 text-sm text-gray-600">
                            @if ($permohonan->approval_eo_at)
                                Disetujui pada<br>
                                {{ \Carbon\Carbon::parse($permohonan->approval_eo_at)->format('d F Y H:i') }}
                            @else
                                Menunggu Persetujuan
                            @endif
                        </p>
                    </div>

                    <div class="p-4 text-center rounded-lg border">
                        <div class="mb-2">
                            @if ($permohonan->approval_dd_at)
                                <i class="text-3xl text-green-500 ki-filled ki-check-circle"></i>
                            @else
                                <i class="text-3xl text-gray-400 ki-filled ki-time"></i>
                            @endif
                        </div>
                        <h5 class="font-semibold text-gray-900">Deputy Director</h5>
                        <p class="mt-1 text-sm text-gray-600">
                            @if ($permohonan->approval_dd_at)
                                Disetujui pada<br>
                                {{ \Carbon\Carbon::parse($permohonan->approval_dd_at)->format('d F Y H:i') }}
                            @else
                                Menunggu Persetujuan
                            @endif
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('styles')
    <style>
        @media print {

            .btn,
            .card-header .flex {
                display: none !important;
            }

            .card {
                box-shadow: none !important;
                border: 1px solid #e5e7eb !important;
                margin-bottom: 1rem !important;
            }

            body {
                font-size: 12px !important;
            }

            .card-title {
                font-size: 16px !important;
                font-weight: bold !important;
            }
        }
    </style>
@endpush
