<?php
    use Illuminate\Support\Facades\Auth;

    $statusAudit = strtolower(trim($audit->status ?? ''));
    $isRiwayat = isset($isRiwayat) ? $isRiwayat : ($statusAudit === 'close');
?>


<?php $__env->startSection('title', $isRiwayat ? 'Detail Riwayat Audit' : 'Detail Audit'); ?>

<?php $__env->startSection('content'); ?>
<div
    x-data="{
        showToast: <?php echo e(session('success') && !$isRiwayat ? 'true' : 'false'); ?>,
        showConfirm: false,
        showSaving: false,

        submitForm() {
            if (<?php echo e($isRiwayat ? 'true' : 'false'); ?>) {
                return;
            }

            const form = document.getElementById('verifikasiForm');

            if (!form.checkValidity()) {
                form.reportValidity();
                this.showConfirm = false;
                return;
            }

            this.showConfirm = false;
            this.showSaving = true;

            setTimeout(() => {
                form.submit();
            }, 900);
        }
    }"
    x-init="
        if(showToast){
            setTimeout(() => showToast = false, 3000);
        }

        <?php if(!$isRiwayat): ?>
            $nextTick(() => {
                setTimeout(() => {
                    if ($refs.keteranganSesudah) {
                        $refs.keteranganSesudah.scrollIntoView({
                            behavior: 'smooth',
                            block: 'center'
                        });

                        $refs.keteranganSesudah.focus({
                            preventScroll: true
                        });
                    }
                }, 300);
            });
        <?php else: ?>
            window.scrollTo(0, 0);
        <?php endif; ?>
    "
    class="min-h-screen bg-slate-50 p-3"
>

    <style>
        [x-cloak] {
            display: none !important;
        }

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

        .input-clean {
            height: 36px;
            width: 100%;
            border-radius: 10px;
            border: 1px solid #e2e8f0;
            background: #f8fafc;
            padding: 0 12px;
            font-size: 12px;
            color: #334155;
            outline: none;
            transition: all .2s ease;
        }

        .input-clean:focus {
            border-color: #3b82f6;
            background: #ffffff;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
        }

        .textarea-clean {
            min-height: 92px;
            width: 100%;
            border-radius: 12px;
            border: 1px solid #e2e8f0;
            background: #f8fafc;
            padding: 10px 12px;
            font-size: 12px;
            line-height: 1.6;
            color: #334155;
            outline: none;
            transition: all .2s ease;
        }

        .textarea-clean:focus {
            border-color: #3b82f6;
            background: #ffffff;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
        }

        .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-primary {
            color: #ffffff;
            background: #3b82f6;
        }

        .btn-primary:hover {
            background: #2563eb;
            box-shadow: 0 8px 18px rgba(37, 99, 235, .22);
        }

        .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);
        }

        .file-clean {
            width: 100%;
            border-radius: 12px;
            border: 1px solid #e2e8f0;
            background: #f8fafc;
            padding: 8px 10px;
            font-size: 12px;
            color: #475569;
            outline: none;
            transition: all .2s ease;
        }

        .file-clean:focus {
            border-color: #3b82f6;
            background: #ffffff;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
        }

        .file-clean::file-selector-button {
            margin-right: 10px;
            border: none;
            border-radius: 9px;
            background: #dbeafe;
            color: #2563eb;
            padding: 6px 10px;
            font-size: 12px;
            font-weight: 700;
            cursor: pointer;
        }

        .file-clean::file-selector-button:hover {
            background: #bfdbfe;
        }

        @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">

        <?php if(!$isRiwayat): ?>
            
            <template x-if="showToast">
                <div x-show="showToast"
                    x-transition.opacity
                    class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/20 px-4">
                    <div class="w-full max-w-xs rounded-xl bg-white px-4 py-4 text-center shadow-2xl">
                        <div class="mx-auto mb-3 flex h-10 w-10 items-center justify-center rounded-full bg-green-100 text-green-600">
                            <i class="fas fa-check text-sm"></i>
                        </div>

                        <p class="text-sm font-bold text-slate-800">
                            Data berhasil diperbarui!
                        </p>

                        <p class="mt-1 text-xs text-slate-500">
                            Perubahan data audit telah tersimpan.
                        </p>
                    </div>
                </div>
            </template>
        <?php endif; ?>

        
        <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 <?php echo e($isRiwayat ? 'fa-clock-rotate-left' : 'fa-clipboard-list'); ?> text-[18px]"
                            style="color:#2f435b;"
                        ></i>
                    </div>

                    <div>
                        <h2 class="text-base font-semibold tracking-tight text-slate-800">
                            <?php echo e($isRiwayat ? 'Detail Riwayat Audit' : 'Detail Audit'); ?>

                        </h2>
                        <p class="mt-0.5 text-xs text-slate-500">
                            <?php echo e($isRiwayat ? 'Data audit yang sudah close hanya dapat dilihat.' : 'Detail audit yang sudah diverifikasi oleh auditor.'); ?>

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

                <div class="flex flex-wrap items-center justify-end gap-2">
                    <?php if($isRiwayat): ?>
                        <span class="inline-flex h-9 items-center justify-center gap-1.5 rounded-lg border border-emerald-100 bg-emerald-50 px-3 text-xs font-semibold text-emerald-700">
                            <i class="fas fa-lock text-[11px]"></i>
                            Read Only
                        </span>
                    <?php endif; ?>

                    <a
                        href="<?php echo e(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>

        <?php if(!$isRiwayat): ?>
            <form
                action="<?php echo e(route('audit.updateSesudah', $audit->id)); ?>"
                method="POST"
                enctype="multipart/form-data"
                id="verifikasiForm"
            >
                <?php echo csrf_field(); ?>
                <?php echo method_field('PATCH'); ?>
        <?php endif; ?>

            
            <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 audit yang 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">

                        <?php $__currentLoopData = [
                            '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'),
                        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $label => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div>
                                <label class="label-clean"><?php echo e($label); ?></label>
                                <div class="readonly-clean">
                                    <?php echo e($value); ?>

                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                        <div>
                            <label class="label-clean">Tanggal Verifikasi</label>

                            <?php if($audit->tanggal_verifikasi || $isRiwayat): ?>
                                <div class="readonly-clean">
                                    <?php echo e($audit->tanggal_verifikasi ? \Carbon\Carbon::parse($audit->tanggal_verifikasi)->translatedFormat('d F Y') : '-'); ?>

                                </div>
                            <?php else: ?>
                                <input
                                    type="date"
                                    name="tanggal_verifikasi"
                                    min="<?php echo e(\Carbon\Carbon::parse($audit->tanggal_audit)->format('Y-m-d')); ?>"
                                    class="input-clean"
                                    required
                                >
                            <?php endif; ?>
                        </div>

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

            
            <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">
                    <?php if(Auth::user()->role === 'superadmin' && !$isRiwayat): ?>
                        <input
                            type="text"
                            name="pic_perbaikan"
                            class="input-clean"
                            value="<?php echo e(old('pic_perbaikan', $audit->pic_perbaikan)); ?>"
                            placeholder="Masukkan PIC Perbaikan">
                    <?php else: ?>
                        <div class="readonly-clean">
                            <?php echo e($audit->pic_perbaikan ?? '-'); ?>

                        </div>
                    <?php endif; ?>
                </div>
            </div>

            
            <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">
                        <?php echo e($audit->lokasi ?? '-'); ?>

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

            
            <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 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">
                            <?php echo e($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
                                    <?php if(!$isRiwayat): ?>
                                        <span class="text-red-600">*</span>
                                    <?php endif; ?>
                                </h3>
                                <p class="mt-0.5 text-[11px] text-slate-500">
                                    Catatan hasil perbaikan/verifikasi.
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="px-4 py-4">
                        <?php if($isRiwayat): ?>
                            <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">
                                <?php echo e($audit->keterangan_sesudah ?? '-'); ?>

                            </div>
                        <?php else: ?>
                            <textarea
                                name="keterangan_sesudah"
                                id="keterangan_sesudah"
                                x-ref="keteranganSesudah"
                                class="textarea-clean"
                                required><?php echo e(old('keterangan_sesudah', $audit->keterangan_sesudah)); ?></textarea>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            
            <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.
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="p-4">
                        <?php if($audit->foto_sebelum && file_exists(public_path('storage/' . $audit->foto_sebelum))): ?>
                            <a href="<?php echo e(asset('storage/' . $audit->foto_sebelum)); ?>"
                                target="_blank"
                                rel="noopener"
                                class="block overflow-hidden rounded-xl border border-slate-200 bg-slate-50">
                                <img
                                    src="<?php echo e(asset('storage/' . $audit->foto_sebelum)); ?>"
                                    alt="Foto Sebelum"
                                    class="h-56 w-full object-contain transition hover:scale-[1.01]">
                            </a>
                        <?php 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>
                        <?php 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
                                    <?php if(!$isRiwayat): ?>
                                        <span class="text-red-600">*</span>
                                    <?php endif; ?>
                                </h3>
                                <p class="mt-0.5 text-[11px] text-slate-500">
                                    Dokumentasi setelah perbaikan.
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="p-4">
                        <?php if($audit->foto_sesudah && file_exists(public_path('storage/' . $audit->foto_sesudah))): ?>
                            <a href="<?php echo e(asset('storage/' . $audit->foto_sesudah)); ?>"
                                target="_blank"
                                rel="noopener"
                                class="mb-3 block overflow-hidden rounded-xl border border-slate-200 bg-slate-50">
                                <img
                                    src="<?php echo e(asset('storage/' . $audit->foto_sesudah)); ?>"
                                    alt="Foto Sesudah"
                                    class="h-56 w-full object-contain transition hover:scale-[1.01]">
                            </a>
                        <?php 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>
                        <?php endif; ?>

                        <?php if(!$isRiwayat): ?>
                            <input
                                type="file"
                                name="foto_sesudah"
                                accept="image/*"
                                class="file-clean"
                                <?php echo e($audit->foto_sesudah ? '' : 'required'); ?>>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            
            <div class="mt-4 flex flex-col gap-3 rounded-xl border border-slate-200 bg-white px-4 py-3 shadow-sm sm:flex-row sm:items-center sm:justify-between print:hidden">
                <a
                    href="<?php echo e($isRiwayat ? route('audit.riwayat') : url()->previous()); ?>"
                    class="btn-modern btn-gray"
                >
                    <i class="fas fa-arrow-left text-[12px]"></i>
                    Kembali
                </a>

                <?php if(!$isRiwayat): ?>
                    <button
                        type="button"
                        @click="showConfirm = true"
                        class="btn-modern btn-primary"
                    >
                        <i class="fas fa-save text-[12px]"></i>
                        Simpan Perubahan
                    </button>
                <?php else: ?>
                    <div class="inline-flex h-9 items-center justify-center gap-1.5 rounded-lg bg-slate-100 px-3 text-xs font-semibold text-slate-500">
                        <i class="fas fa-lock text-[11px]"></i>
                        Data tidak dapat diedit
                    </div>
                <?php endif; ?>
            </div>

        <?php if(!$isRiwayat): ?>
            </form>

            
            <template x-if="showConfirm">
                <div x-show="showConfirm"
                    x-transition.opacity
                    class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/50 px-4 backdrop-blur-sm">
                    <div class="w-full max-w-sm overflow-hidden rounded-xl bg-white shadow-2xl">
                        <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 bg-blue-500 shadow-sm">
                                    <i class="fas fa-clipboard-check text-[18px] text-white"></i>
                                </div>

                                <div>
                                    <h3 class="text-sm font-semibold text-slate-800">
                                        Konfirmasi Perubahan
                                    </h3>
                                    <p class="mt-0.5 text-[11px] text-slate-500">
                                        Pastikan data yang dimasukkan sudah sesuai.
                                    </p>
                                </div>
                            </div>
                        </div>

                        <div class="px-4 py-4">
                            <p class="text-xs leading-relaxed text-slate-600">
                                Apakah Anda yakin ingin simpan perubahan data ini?
                            </p>
                        </div>

                        <div class="flex justify-end gap-2 border-t border-slate-100 bg-slate-50 px-4 py-3">
                            <button
                                type="button"
                                @click="showConfirm = false"
                                class="btn-modern btn-gray"
                            >
                                Batal
                            </button>

                            <button
                                type="button"
                                @click="submitForm()"
                                class="btn-modern btn-primary"
                            >
                                Iya
                            </button>
                        </div>
                    </div>
                </div>
            </template>

            
            <template x-if="showSaving">
                <div x-show="showSaving"
                    x-transition.opacity
                    class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/50 px-4 backdrop-blur-sm">
                    <div class="w-full max-w-xs rounded-xl bg-white px-4 py-5 text-center shadow-2xl">
                        <div class="mx-auto mb-3 flex h-10 w-10 items-center justify-center rounded-full bg-green-100 text-green-600">
                            <i class="fas fa-check text-sm"></i>
                        </div>

                        <p class="text-sm font-bold text-slate-800">
                            Berhasil!
                        </p>

                        <p class="mt-1 text-xs text-slate-500">
                            Verifikasi berhasil, data sedang disimpan...
                        </p>
                    </div>
                </div>
            </template>
        <?php endif; ?>

    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('web_user.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\ea-systems\resources\views/web_user/detail-audit.blade.php ENDPATH**/ ?>