@extends('web_user.layouts.app')
@section('title', 'Detail Hasil Audit')

@section('content')
<div class="min-h-screen bg-slate-50 p-3">

    <style>
        .label-clean {
            display: block;
            margin-bottom: 4px;
            font-size: 11px;
            font-weight: 700;
            color: #64748b;
        }

        .readonly-clean {
            min-height: 36px;
            border-radius: 10px;
            border: 1px solid #e2e8f0;
            background: #f8fafc;
            padding: 9px 12px;
            font-size: 12px;
            font-weight: 500;
            color: #334155;
        }

        .btn-modern {
            height: 36px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 7px;
            border-radius: 12px;
            padding: 0 16px;
            font-size: 12px;
            font-weight: 600;
            line-height: 1;
            border: none !important;
            outline: none;
            white-space: nowrap;
            transition: all .2s ease;
            box-shadow: 0 6px 14px rgba(15, 23, 42, .08);
        }

        .btn-modern svg,
        .btn-modern i {
            width: 14px;
            height: 14px;
            font-size: 12px;
        }

        .btn-modern:hover {
            transform: translateY(-1px);
        }

        .btn-modern:active {
            transform: translateY(0);
        }

        .btn-red {
            color: #ffffff;
            background: #dc2626;
        }

        .btn-red:hover {
            background: #b91c1c;
            box-shadow: 0 8px 18px rgba(220, 38, 38, .20);
        }

        .btn-gray {
            color: #475569;
            background: #e5e7eb;
        }

        .btn-gray:hover {
            color: #334155;
            background: #d1d5db;
            box-shadow: 0 8px 16px rgba(15, 23, 42, .10);
        }

        @media print {
            .print-hidden {
                display: none !important;
            }

            .print-card {
                box-shadow: none !important;
                border: 1px solid #e5e7eb !important;
            }
        }
    </style>

    <div class="mx-auto max-w-6xl">

        {{-- Header dan Aksi --}}
        <div class="mb-4 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm print-hidden">
            <div class="flex flex-col gap-3 px-4 py-3 lg:flex-row lg:items-center lg:justify-between">

                <div class="flex items-center gap-3">
                    <div
                        class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                        style="background-color: rgba(47, 67, 91, 0.10); border: 1px solid rgba(47, 67, 91, 0.12);"
                    >
                        <i
                            class="fas fa-clipboard-list text-[18px]"
                            style="color:#2f435b;"
                        ></i>
                    </div>

                    <div>
                        <h2 class="text-base font-semibold tracking-tight text-slate-800">
                            Detail Hasil Audit pada Divisi Anda
                        </h2>
                        <p class="mt-0.5 text-xs text-slate-500">
                            Ringkasan hasil audit berdasarkan data temuan dan verifikasi oleh auditor lain terhadap divisi anda.
                        </p>
                    </div>
                </div>

                <div class="flex flex-wrap items-center justify-end gap-2">
                    <a
                        href="{{ route('audit.export.pdf', $audit->id) }}"
                        class="btn-modern btn-red"
                    >
                        <i class="fas fa-file-pdf text-[12px]"></i>
                        PDF
                    </a>
                </div>

            </div>
        </div>

        {{-- Informasi Utama --}}
        <div class="mb-4 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm print-card">
            <div class="border-b border-slate-100 px-4 py-3">
                <div class="flex items-center gap-3">
                    <div
                        class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                        style="background-color:#eef4fa; border: 1px solid rgba(47, 67, 91, 0.10);"
                    >
                        <i
                            class="fas fa-info-circle text-[18px]"
                            style="color:#2f435b;"
                        ></i>
                    </div>

                    <div>
                        <h3 class="text-sm font-semibold text-slate-800">
                            Informasi Utama
                        </h3>
                        <p class="mt-0.5 text-[11px] text-slate-500">
                            Data utama hasil audit yang sudah tercatat pada sistem.
                        </p>
                    </div>
                </div>
            </div>

            <div class="bg-white px-4 py-4">
                <div class="grid grid-cols-1 gap-3 md:grid-cols-2">

                    @foreach([
                        'Nama Auditor'        => $audit->auditor,
                        'Nama Auditee'        => $audit->auditi,
                        'Divisi Auditor'      => $audit->user->bagian->nama_bagian ?? '-',
                        'Divisi yang Diaudit' => $audit->bagian->nama_bagian ?? '-',
                        'Tema Audit'          => $audit->tema->nama ?? '-',
                        'Kategori Audit'      => $audit->kategori,
                        'Tanggal Audit'       => \Carbon\Carbon::parse($audit->tanggal_audit)->translatedFormat('d F Y'),
                        'Tanggal Verifikasi'  => $audit->tanggal_verifikasi
                            ? \Carbon\Carbon::parse($audit->tanggal_verifikasi)->translatedFormat('d F Y')
                            : '-',
                    ] as $label => $value)
                        <div>
                            <label class="label-clean">{{ $label }}</label>
                            <div class="readonly-clean">
                                {{ $value }}
                            </div>
                        </div>
                    @endforeach

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

        {{-- PIC Perbaikan --}}
        <div class="mb-4 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm print-card">
            <div class="border-b border-slate-100 px-4 py-3">
                <div class="flex items-center gap-3">
                    <div
                        class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                        style="background-color:#ecfdf5; border: 1px solid #bbf7d0;"
                    >
                        <i
                            class="fas fa-user-check text-[18px]"
                            style="color:#16a34a;"
                        ></i>
                    </div>

                    <div>
                        <h3 class="text-sm font-semibold text-slate-800">
                            PIC Perbaikan
                        </h3>
                        <p class="mt-0.5 text-[11px] text-slate-500">
                            Penanggung jawab perbaikan temuan audit.
                        </p>
                    </div>
                </div>
            </div>

            <div class="px-4 py-4">
                <div class="readonly-clean">
                    {{ $audit->pic_perbaikan ?? '-' }}
                </div>
            </div>
        </div>

        {{-- Area Temuan --}}
        <div class="mb-4 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm print-card">
            <div class="border-b border-slate-100 px-4 py-3">
                <div class="flex items-center gap-3">
                    <div
                        class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                        style="background-color:#f8fafc; border: 1px solid #e2e8f0;"
                    >
                        <i
                            class="fas fa-map-marker-alt text-[18px]"
                            style="color:#64748b;"
                        ></i>
                    </div>

                    <div>
                        <h3 class="text-sm font-semibold text-slate-800">
                            Area Temuan
                        </h3>
                        <p class="mt-0.5 text-[11px] text-slate-500">
                            Lokasi atau area temuan audit.
                        </p>
                    </div>
                </div>
            </div>

            <div class="px-4 py-4">
                <div class="readonly-clean">
                    {{ $audit->lokasi ?? '-' }}
                </div>
            </div>
        </div>

        {{-- Keterangan --}}
        <div class="mb-4 grid grid-cols-1 gap-4 md:grid-cols-2">
            <div class="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm print-card">
                <div class="border-b border-slate-100 px-4 py-3">
                    <div class="flex items-center gap-3">
                        <div
                            class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                            style="background-color:#fff7ed; border: 1px solid #fed7aa;"
                        >
                            <i
                                class="fas fa-exclamation-triangle text-[18px]"
                                style="color:#f97316;"
                            ></i>
                        </div>

                        <div>
                            <h3 class="text-sm font-semibold text-slate-800">
                                Keterangan Sebelum
                            </h3>
                            <p class="mt-0.5 text-[11px] text-slate-500">
                                Catatan temuan sebelum dilakukan perbaikan.
                            </p>
                        </div>
                    </div>
                </div>

                <div class="px-4 py-4">
                    <div class="min-h-[92px] rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-xs leading-relaxed text-slate-700">
                        {{ $audit->keterangan }}
                    </div>
                </div>
            </div>

            <div class="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm print-card">
                <div class="border-b border-slate-100 px-4 py-3">
                    <div class="flex items-center gap-3">
                        <div
                            class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                            style="background-color:#ecfdf5; border: 1px solid #bbf7d0;"
                        >
                            <i
                                class="fas fa-clipboard-check text-[18px]"
                                style="color:#16a34a;"
                            ></i>
                        </div>

                        <div>
                            <h3 class="text-sm font-semibold text-slate-800">
                                Keterangan Sesudah
                            </h3>
                            <p class="mt-0.5 text-[11px] text-slate-500">
                                Catatan tindak lanjut setelah dilakukan perbaikan.
                            </p>
                        </div>
                    </div>
                </div>

                <div class="px-4 py-4">
                    <div class="min-h-[92px] rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-xs leading-relaxed text-slate-700">
                        {{ $audit->keterangan_sesudah ?? '-' }}
                    </div>
                </div>
            </div>
        </div>

        {{-- Foto --}}
        <div class="mb-4 grid grid-cols-1 gap-4 md:grid-cols-2 print:hidden">
            <div class="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
                <div class="border-b border-slate-100 px-4 py-3">
                    <div class="flex items-center gap-3">
                        <div
                            class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                            style="background-color:#fff1f2; border: 1px solid #fecdd3;"
                        >
                            <i
                                class="fas fa-image text-[18px]"
                                style="color:#e11d48;"
                            ></i>
                        </div>

                        <div>
                            <h3 class="text-sm font-semibold text-slate-800">
                                Foto Sebelum
                            </h3>
                            <p class="mt-0.5 text-[11px] text-slate-500">
                                Dokumentasi kondisi awal temuan audit.
                            </p>
                        </div>
                    </div>
                </div>

                <div class="p-4">
                    @if ($audit->foto_sebelum && file_exists(public_path('storage/' . $audit->foto_sebelum)))
                        <a href="{{ asset('storage/' . $audit->foto_sebelum) }}"
                            target="_blank"
                            rel="noopener"
                            class="block overflow-hidden rounded-xl border border-slate-200 bg-slate-50">
                            <img
                                src="{{ asset('storage/' . $audit->foto_sebelum) }}"
                                alt="Foto Sebelum"
                                class="h-56 w-full object-contain transition hover:scale-[1.01]">
                        </a>
                    @else
                        <div class="flex h-56 items-center justify-center rounded-xl border border-dashed border-red-200 bg-red-50 text-xs font-medium text-red-500">
                            Foto sebelum tidak ditemukan.
                        </div>
                    @endif
                </div>
            </div>

            <div class="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
                <div class="border-b border-slate-100 px-4 py-3">
                    <div class="flex items-center gap-3">
                        <div
                            class="flex h-10 w-10 items-center justify-center rounded-xl shadow-sm"
                            style="background-color:#ecfdf5; border: 1px solid #bbf7d0;"
                        >
                            <i
                                class="fas fa-image text-[18px]"
                                style="color:#16a34a;"
                            ></i>
                        </div>

                        <div>
                            <h3 class="text-sm font-semibold text-slate-800">
                                Foto Sesudah
                            </h3>
                            <p class="mt-0.5 text-[11px] text-slate-500">
                                Dokumentasi kondisi setelah perbaikan.
                            </p>
                        </div>
                    </div>
                </div>

                <div class="p-4">
                    @if ($audit->foto_sesudah && file_exists(public_path('storage/' . $audit->foto_sesudah)))
                        <a href="{{ asset('storage/' . $audit->foto_sesudah) }}"
                            target="_blank"
                            rel="noopener"
                            class="block overflow-hidden rounded-xl border border-slate-200 bg-slate-50">
                            <img
                                src="{{ asset('storage/' . $audit->foto_sesudah) }}"
                                alt="Foto Sesudah"
                                class="h-56 w-full object-contain transition hover:scale-[1.01]">
                        </a>
                    @else
                        <div class="flex h-56 items-center justify-center rounded-xl border border-dashed border-slate-200 bg-slate-50 text-xs font-medium italic text-slate-500">
                            Belum ada foto sesudah.
                        </div>
                    @endif
                </div>
            </div>
        </div>

        {{-- Tombol --}}
        <div class="mt-4 flex justify-start rounded-xl border border-slate-200 bg-white px-4 py-3 shadow-sm print:hidden">
            <a
                href="{{ url()->previous() }}"
                class="btn-modern btn-gray"
            >
                <i class="fas fa-arrow-left text-[12px]"></i>
                Kembali
            </a>
        </div>

    </div>
</div>
@endsection