@{
    Layout = "~/Views/Admin/Transport/SpjDriverUpst/Shared/_Layout.cshtml";
    ViewData["Title"] = "Detail Batal Penjemputan";
}

<div class="w-full lg:max-w-sm mx-auto bg-gray-50 min-h-screen pb-20">

    <div class="bg-upst text-white px-6 pt-8 pb-16 rounded-b-[40px] shadow-lg relative">
        <div class="flex items-center justify-between relative z-10">
            <a href="@Url.Action("Index", "Home")" class="w-10 h-10 flex items-center justify-center bg-white/10 rounded-xl backdrop-blur-md hover:bg-white/20 transition-all">
                <i class="w-5 h-5" data-lucide="chevron-left"></i>
            </a>
            <h1 class="text-lg font-black uppercase tracking-tight">Detail Batal</h1>
            <div class="w-10"></div>
        </div>
    </div>


    <div class="px-4 pb-6 relative -mt-10 z-20">
        <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100">
            
            <div class="flex items-center justify-between border-b border-gray-100 pb-4 mb-4">
                <div class="flex items-center gap-3">
                    <div>
                        <div class="flex items-center gap-2 mb-2">
                            <div class="bg-red-100 text-red-600 px-3 py-1 rounded-full text-xs font-bold border border-red-200" id="status-badge">-</div>
                            <div class="text-xs text-gray-500" id="tanggal-batal">-</div>
                        </div>
                        <h3 class="font-bold text-gray-900" id="nama-perusahaan">-</h3>
                         <p class="text-sm text-gray-700 leading-relaxed items-center flex" id="alamat-perusahaan">
                            -
                        </p>
                       
                    </div>
                </div>
            </div>

            <div class="space-y-5">
                <div>
                    <label class="block text-sm font-semibold text-gray-700 mb-2">Alasan Pembatalan</label>
                    <div class="w-full rounded-xl text-sm border border-gray-200 bg-gray-50 p-4 text-gray-700 leading-relaxed" id="alasan-pembatalan">
                        -
                    </div>
                </div>

                <div>
                    <label class="block text-sm font-semibold text-gray-700 mb-2">Foto Bukti Pembatalan</label>
                    <div class="grid grid-cols-1 gap-3" id="foto-bukti-container">
                    </div>
                </div>

                <div class="pt-4">
                    <a href="@Url.Action("Index", "Home")"
                       class="block w-full bg-gray-100 text-gray-700 font-bold py-3.5 rounded-xl text-center hover:bg-gray-200 transition-colors">
                        Kembali ke Beranda
                    </a>
                </div>
            </div>
        </div>
    </div>

    <partial name="~/Views/Admin/Transport/SpjDriverUpst/Shared/Components/_Navigation.cshtml" />
</div>

@section Scripts {
    <script>
        document.addEventListener('DOMContentLoaded', async function() {
            try {
                const response = await fetch('/driver/json/pembatalan-data.json');
                const data = await response.json();
                const pembatalan = data.pembatalan;

                document.getElementById('nama-perusahaan').textContent = pembatalan.namaPerusahaan;
                document.getElementById('alamat-perusahaan').textContent = pembatalan.alamat;
                document.getElementById('alasan-pembatalan').textContent = pembatalan.alasanPembatalan;
                document.getElementById('status-badge').textContent = pembatalan.status;

                const tanggal = new Date(pembatalan.tanggalBatal);
                const formatter = new Intl.DateTimeFormat('id-ID', {
                    day: '2-digit',
                    month: 'short',
                    year: 'numeric',
                    hour: '2-digit',
                    minute: '2-digit',
                    timeZone: 'Asia/Jakarta'
                });
                document.getElementById('tanggal-batal').textContent = formatter.format(tanggal) + ' WIB';

                const fotoBuktiContainer = document.getElementById('foto-bukti-container');
                if (pembatalan.fotoBukti && pembatalan.fotoBukti.length > 0) {
                    pembatalan.fotoBukti.forEach(foto => {
                        const fotoDivEl = document.createElement('div');
                        fotoDivEl.className = 'relative group cursor-pointer aspect-square rounded-xl overflow-hidden border border-gray-200';
                        fotoDivEl.innerHTML = `
                            <img src="${foto.url}" alt="Bukti ${foto.id}" class="w-full h-full object-cover transition-transform duration-300 group-hover:scale-110" />
                        `;
                        fotoBuktiContainer.appendChild(fotoDivEl);
                    });
                }
            } catch (error) {
                console.error('Error loading pembatalan data:', error);
            }
        });
    </script>
}

