<!doctype html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Form Pemeriksaan {{ $digitalForm->order->invoice_no }}</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-white text-slate-900">
<main class="mx-auto max-w-4xl p-5 md:p-8">
    <div class="flex flex-col gap-4 border-b pb-5 md:flex-row md:items-start md:justify-between">
        <div>
            <div class="text-sm text-slate-500">Form pemeriksaan barang</div>
            <h1 class="text-2xl font-semibold">{{ $digitalForm->order->invoice_no }}</h1>
            <div class="mt-2 text-sm text-slate-600">{{ $digitalForm->customer?->name ?? $digitalForm->order->customer?->name ?? 'Walk-in' }} - {{ $digitalForm->created_at->format('d/m/Y H:i') }}</div>
        </div>
        <div class="flex gap-2 print:hidden">
            <a href="{{ route('orders.show', $digitalForm->order) }}" class="rounded-md border px-4 py-2 text-sm">Order</a>
            <button onclick="print()" class="rounded-md bg-slate-900 px-4 py-2 text-sm text-white">Print</button>
        </div>
    </div>

    <section class="mt-6">
        <h2 class="font-semibold">Checklist Kondisi</h2>
        <div class="mt-3 grid gap-2 text-sm md:grid-cols-2">
            @forelse (($digitalForm->checklist ?? []) as $key => $value)
                <div class="rounded-md border px-3 py-2">
                    <span class="font-medium">{{ str_replace('_', ' ', $key) }}</span>
                    <span class="float-right">{{ $value ? 'Ya' : 'Tidak' }}</span>
                </div>
            @empty
                <div class="text-slate-500">Tidak ada checklist.</div>
            @endforelse
        </div>
    </section>

    <section class="mt-6">
        <h2 class="font-semibold">Keterangan Kondisi</h2>
        <div class="mt-3 min-h-24 rounded-md border bg-slate-50 p-4 text-sm leading-6">{{ $digitalForm->general_note ?: 'Tidak ada catatan.' }}</div>
    </section>

    <section class="mt-6">
        <h2 class="font-semibold">Foto Evidence</h2>
        <div class="mt-3 grid gap-3 md:grid-cols-3">
            @forelse (($digitalForm->evidence_paths ?? []) as $path)
                <a href="{{ Storage::disk('public')->url($path) }}" target="_blank" class="block overflow-hidden rounded-lg border">
                    <img src="{{ Storage::disk('public')->url($path) }}" alt="Evidence" class="aspect-square w-full object-cover">
                </a>
            @empty
                <div class="text-sm text-slate-500">Belum ada foto evidence.</div>
            @endforelse
        </div>
    </section>

    <section class="mt-6">
        <h2 class="font-semibold">Tanda Tangan Pelanggan</h2>
        <div class="mt-3 rounded-md border p-4">
            @if ($digitalForm->signature_path)
                <img src="{{ Storage::disk('public')->url($digitalForm->signature_path) }}" alt="Tanda tangan pelanggan" class="h-40 max-w-full object-contain">
            @else
                <div class="text-sm text-slate-500">Belum ada tanda tangan.</div>
            @endif
        </div>
    </section>

    @if ($digitalForm->items->isNotEmpty())
        <section class="mt-6">
            <h2 class="font-semibold">Detail Item Lama</h2>
            <div class="mt-3 divide-y rounded-md border text-sm">
                @foreach ($digitalForm->items as $item)
                    <div class="p-3">
                        <strong>{{ $item->item_name }}</strong>
                        <p class="mt-1 text-slate-600">{{ $item->note }}</p>
                    </div>
                @endforeach
            </div>
        </section>
    @endif
</main>
</body>
</html>
