<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <style>
        [x-cloak] { display: none !important; }
        .no-scrollbar::-webkit-scrollbar { display: none; }
        .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
    </style>

    <div class="bg-[#FAF7F2] min-h-screen py-8 sm:py-12">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <?php if(Auth::user()->role === 'customer'): ?>
                <?php
                    $unreviewedOrder = Auth::user()->orders()
                        ->where('status', 'completed')
                        ->whereDoesntHave('review')
                        ->first();
                ?>

                <?php if($unreviewedOrder): ?>
                    <div class="mb-8 animate-slide-in">
                        <div class="bg-[#2c1a0e] rounded-[2rem] p-6 border border-[#f59e0b]/30 shadow-xl flex flex-col md:flex-row items-center justify-between gap-6">
                            <div class="flex items-center gap-5 flex-col md:flex-row text-center md:text-left">
                                <div class="w-14 h-14 bg-[#f59e0b] rounded-2xl flex items-center justify-center shadow-lg transform -rotate-3">
                                    <i class="fas fa-star text-white text-2xl animate-pulse"></i>
                                </div>
                                <div>
                                    <h3 class="text-white font-bold text-lg">Pesanan telah diterima!</h3>
                                    <p class="text-[#c9b59b] text-sm">Mohon bantu kami dengan memberikan rating bintang agar kami bisa terus meningkatkan layanan.</p>
                                </div>
                            </div>
                            <a href="<?php echo e(route('orders.show', $unreviewedOrder->id)); ?>" 
                               class="shrink-0 px-8 py-3.5 bg-[#f59e0b] text-white text-[11px] font-black uppercase tracking-widest rounded-xl hover:bg-white hover:text-black transition-all shadow-lg">
                                Beri Rating Sekarang
                            </a>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endif; ?>
            
            <div class="flex flex-col md:flex-row md:items-center md:justify-between mb-8 gap-4">
                <div>
                    <h1 class="text-2xl sm:text-3xl font-extrabold text-[#2c1a0e] tracking-tight">
                        <?php if(Auth::user()->role === 'admin'): ?> 
                            Management <span class="text-[#f59e0b]">Orders</span>
                        <?php elseif(Auth::user()->role === 'kurir'): ?> 
                            Delivery <span class="text-[#f59e0b]">Tasks</span>
                        <?php else: ?> 
                            Riwayat <span class="text-[#f59e0b]">Pesanan</span>
                        <?php endif; ?>
                    </h1>
                    <p class="text-[#8c6a4a] mt-1">Pantau dan kelola semua transaksi dalam satu tempat.</p>
                </div>
                
                <div class="flex flex-wrap items-center gap-3">
                    
                    <?php if(Auth::user()->role === 'admin' && request('status') === 'proccessing'): ?>
                        <a href="<?php echo e(route('orders.download_all', ['status' => 'proccessing'])); ?>" 
                        class="bg-[#f59e0b] hover:bg-[#d97706] text-white px-4 py-2 rounded-xl shadow-md text-xs font-black uppercase transition-all flex items-center gap-2">
                            <i class="fas fa-print text-sm"></i>
                            Cetak Daftar Kemas
                        </a>
                    <?php endif; ?>

                    
                    <div class="bg-white border border-[#e0d3c2] px-4 py-2 rounded-xl shadow-sm text-sm font-medium text-[#2c1a0e] flex items-center gap-2">
                        <span class="w-2 h-2 bg-[#f59e0b] rounded-full animate-pulse"></span>
                        Total: <?php echo e($orders->total()); ?> Pesanan
                    </div>
                </div>
            </div>

           
            <div class="mb-8 flex overflow-x-auto pb-2 gap-2 no-scrollbar">
                <?php
                    $currentStatus = request('status');
                    $userRole = Auth::user()->role;

                    // Tentukan tab berdasarkan role
                    if ($userRole === 'kurir') {
                        // Kurir hanya butuh melihat status yang relevan dengan tugas mereka
                        $tabs = [
                            ['label' => 'Semua', 'value' => null],
                            ['label' => 'Menunggu Kurir', 'value' => 'confirmed'],
                            ['label' => 'Diantar', 'value' => 'shipping'],
                            ['label' => 'Selesai', 'value' => 'completed'],
                        ];
                    } else {
                        // Tampilan untuk Admin atau Customer (seperti semula)
                        $tabs = [
                            ['label' => 'Semua', 'value' => null],
                            ['label' => 'Pending', 'value' => 'pending'],
                            ['label' => 'Sudah Bayar', 'value' => 'paid'],
                            ['label' => 'Dikemas', 'value' => 'proccessing'],
                            ['label' => 'Menunggu Kurir', 'value' => 'confirmed'],
                            ['label' => 'Diantar', 'value' => 'shipping'],
                            ['label' => 'Selesai', 'value' => 'completed'],
                        ];
                    }
                ?>

                <?php $__currentLoopData = $tabs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tab): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <a href="<?php echo e(route('orders.index', ['status' => $tab['value']])); ?>" 
                    class="flex-shrink-0 px-6 py-2.5 rounded-xl text-xs font-bold transition-all border-2 uppercase tracking-wider
                    <?php echo e($currentStatus == $tab['value'] 
                        ? 'bg-gradient-to-r from-[#f59e0b] to-[#d97706] border-[#d97706] text-white shadow-md shadow-[#f59e0b]/20' 
                        : 'bg-white border-[#e0d3c2] text-[#8c6a4a] hover:bg-[#fef3c7] hover:text-[#d97706] hover:border-[#f59e0b]'); ?>">
                        <?php echo e($tab['label']); ?>

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

            
            <?php if(session('success')): ?>
                <div class="mb-6 p-4 bg-[#f0fdf4] border-l-4 border-[#f59e0b] text-[#2c1a0e] rounded-r-xl shadow-sm flex items-center gap-3">
                    <svg class="w-5 h-5 text-[#f59e0b]" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"></path></svg>
                    <span class="font-medium text-sm"><?php echo e(session('success')); ?></span>
                </div>
            <?php endif; ?>

            <?php if(session('error')): ?>
                <div class="mb-6 p-4 bg-red-50 border-l-4 border-red-500 text-red-700 rounded-r-xl shadow-sm flex items-center gap-3">
                    <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path></svg>
                    <span class="font-medium text-sm"><?php echo e(session('error')); ?></span>
                </div>
            <?php endif; ?>

            <?php if($orders->count() == 0): ?>
                <div class="bg-white rounded-2xl shadow-sm border border-[#e0d3c2] p-12 sm:p-16 text-center">
                    <div class="flex justify-center mb-6">
                        <div class="p-4 bg-[#fef3c7] rounded-full">
                            <svg class="w-12 h-12 text-[#d97706]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z"></path>
                            </svg>
                        </div>
                    </div>
                    <h3 class="text-xl font-bold text-[#2c1a0e]">Tidak Ada Pesanan</h3>
                    <p class="text-[#8c6a4a] mt-2 max-w-xs mx-auto">Tidak ditemukan data pesanan untuk kategori ini.</p>
                </div>
            <?php else: ?>
                
                <div class="hidden md:block overflow-hidden bg-white shadow-sm border border-[#e0d3c2] rounded-2xl">
                    <table class="w-full text-left border-collapse">
                        <thead>
                            <tr class="bg-[#fef9f0] border-b border-[#e0d3c2]">
                                <th class="px-6 py-4 text-xs font-semibold uppercase tracking-wider text-[#8c6a4a]">ID Pesanan</th>
                                <?php if(Auth::user()->role === 'admin'): ?>
                                    <th class="px-6 py-4 text-xs font-semibold uppercase tracking-wider text-[#8c6a4a]">Pelanggan</th>
                                    <th class="px-6 py-4 text-xs font-semibold uppercase tracking-wider text-[#8c6a4a]">Catatan</th>
                                <?php endif; ?>
                                <th class="px-6 py-4 text-xs font-semibold uppercase tracking-wider text-[#8c6a4a]">Total Tagihan</th>
                                <th class="px-6 py-4 text-xs font-semibold uppercase tracking-wider text-[#8c6a4a]">Status</th>
                                <th class="px-6 py-4 text-xs font-semibold uppercase tracking-wider text-[#8c6a4a] text-right">Aksi</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-[#f0e7dc]">
                            <?php $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $statusMap = [
                                        'pending'    => ['label' => 'PENDING', 'class' => 'bg-amber-50 text-amber-700 border-amber-200'],
                                        'paid'       => ['label' => 'SUDAH DIBAYAR', 'class' => 'bg-emerald-50 text-emerald-700 border-emerald-200'],
                                        'proccessing'=> ['label' => 'DIKEMAS', 'class' => 'bg-blue-50 text-blue-700 border-blue-200'],
                                        'confirmed'  => ['label' => 'MENUNGGU KURIR', 'class' => 'bg-cyan-50 text-cyan-700 border-cyan-200'],
                                        'shipping'   => ['label' => 'DIANTAR', 'class' => 'bg-purple-50 text-purple-700 border-purple-200'],
                                        'completed'  => ['label' => 'PESANAN SAMPAI', 'class' => 'bg-emerald-50 text-emerald-700 border-emerald-200'],
                                        'cancelled'  => ['label' => 'DIBATALKAN', 'class' => 'bg-rose-50 text-rose-700 border-rose-200'],
                                    ];
                                    $current = $statusMap[$order->status] ?? ['label' => $order->status, 'class' => 'bg-gray-50 text-gray-700 border-gray-200'];
                                ?>
                                <tr class="hover:bg-[#fef9f0] transition-colors group">
                                    <td class="px-6 py-5">
                                        <div class="font-bold text-[#2c1a0e] group-hover:text-[#d97706] flex items-center gap-2">
                                            #<?php echo e($order->order_number ?? $order->id); ?>

                                            
                                            <?php if(str_contains(strtolower($order->notes ?? ''), 'sameday') || str_contains(strtolower($order->shipping_address ?? ''), 'sameday')): ?>
                                                <span class="bg-red-600 text-white text-[9px] px-2 py-0.5 rounded font-black animate-pulse">
                                                    SAMEDAY
                                                </span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="text-xs text-[#c9b59b] font-medium"><?php echo e($order->created_at->format('d M Y')); ?></div>
                                    </td>
                                    <?php if(Auth::user()->role === 'admin'): ?>
                                        <td class="px-6 py-5 text-sm">
                                            <div class="font-medium text-[#2c1a0e]"><?php echo e($order->user->name ?? 'Guest'); ?></div>
                                            <div class="text-[#8c6a4a] text-xs"><?php echo e($order->user->email ?? '-'); ?></div>
                                        </td>
                                        <td class="px-6 py-5 text-sm">
                                            <div class="text-[#8c6a4a] italic text-xs max-w-[120px] lg:max-w-[200px] truncate cursor-help" 
                                                title="<?php echo e($order->notes); ?>">
                                                <?php echo e($order->notes ?? '-'); ?>

                                            </div>
                                        </td>
                                    <?php endif; ?>
                                    <td class="px-6 py-5 font-bold text-[#2c1a0e]">
                                        Rp <?php echo e(number_format($order->total_price, 0, ',', '.')); ?>

                                    </td>
                                    <td class="px-6 py-5">
                                        <span class="<?php echo e($current['class']); ?> px-3 py-1.5 rounded-full text-[10px] font-black border flex items-center w-fit gap-1.5 uppercase">
                                            <span class="w-1.5 h-1.5 rounded-full bg-current <?php echo e($order->status === 'shipping' ? 'animate-ping' : ''); ?>"></span>
                                            <?php echo e($current['label']); ?>

                                        </span>
                                        
                                        
                                        <?php if(Auth::user()->role === 'customer'): ?>
                                            <?php if($order->status === 'proccessing'): ?>
                                                <div class="mt-1 text-[9px] text-blue-500 font-bold italic">
                                                    Estimasi: <?php echo e($order->shippingRate->estimation ?? '2-3 Hari'); ?> lagi
                                                </div>
                                            <?php elseif($order->status === 'shipping' && $order->shipped_at): ?>
                                                <?php
                                                    $estText = $order->shippingRate->estimation ?? '3 Hari';
                                                    preg_match_all('!\d+!', $estText, $matches);
                                                    $days = !empty($matches[0]) ? max($matches[0]) : 3;
                                                    $arrival = $order->shipped_at->addDays($days);
                                                ?>
                                                <div class="mt-1 text-[9px] text-purple-600 font-bold">
                                                    📦 Tiba: <?php echo e($arrival->translatedFormat('d M')); ?>

                                                </div>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    </td>
                                    <td class="px-6 py-5 text-right">
                                        <div class="flex items-center justify-end gap-2 text-right">
                                            
                                       
                                        <?php if(Auth::user()->role === 'admin'): ?>
                                            <div class="flex items-center gap-2">
                                                
                                                
                                                <?php if($order->status === 'completed' && $order->proof_of_delivery): ?>
                                                    <div x-data="{ open: false }">
                                                        <button @click="open = true" 
                                                            type="button"
                                                            class="bg-amber-100 text-amber-700 px-3 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm hover:bg-amber-200 transition-all">
                                                            Lihat Bukti Kurir
                                                        </button>

                                                        <template x-teleport="body">
                                                            <div x-show="open" 
                                                                class="fixed inset-0 z-[100] overflow-y-auto flex items-center justify-center p-4 bg-[#2c1a0e]/60 backdrop-blur-sm"
                                                                x-cloak>
                                                                
                                                                <div @click.away="open = false" 
                                                                    class="bg-white w-full max-w-sm rounded-2xl overflow-hidden shadow-2xl border border-[#e0d3c2]">
                                                                    
                                                                    <div class="relative h-64 bg-[#fef9f0]">
                                                                        <img src="<?php echo e(asset('storage/' . $order->proof_of_delivery)); ?>" 
                                                                            class="w-full h-full object-cover">
                                                                        <button @click="open = false" class="absolute top-4 right-4 bg-black/20 hover:bg-black/40 text-white p-2 rounded-full backdrop-blur-md transition-all">
                                                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                                                        </button>
                                                                    </div>

                                                                    <div class="p-6 text-center">
                                                                        <div class="inline-flex items-center justify-center w-12 h-12 bg-[#fef3c7] text-[#d97706] rounded-full mb-4">
                                                                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
                                                                        </div>
                                                                        
                                                                        <h4 class="text-[9px] font-black uppercase text-[#8c6a4a] tracking-wider mb-1">Diterima Oleh</h4>
                                                                        <p class="text-xl font-bold text-[#2c1a0e] capitalize mb-3">
                                                                            <?php echo e($order->receiver_name ?? 'Nama Tidak Terdeteksi'); ?>

                                                                        </p>

                                                                        
                                                                        <div class="bg-[#fef9f0] rounded-lg py-2 px-4 inline-block border border-[#e0d3c2]">
                                                                            <p class="text-[9px] font-bold text-[#8c6a4a] uppercase">Waktu Sampai:</p>
                                                                            <p class="text-xs font-bold text-[#d97706]">
                                                                                <?php echo e($order->updated_at->translatedFormat('d F Y • H:i')); ?> WIB
                                                                            </p>
                                                                        </div>
                                                                        
                                                                        <button @click="open = false" class="mt-6 w-full py-3 bg-[#fef9f0] hover:bg-[#fef3c7] text-[#8c6a4a] rounded-xl font-bold text-xs uppercase transition-all">
                                                                            Tutup Detail
                                                                        </button>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </template>
                                                    </div>
                                                <?php endif; ?>

                                                
                                                <?php if($order->status === 'paid'): ?>
                                                    <form action="<?php echo e(route('orders.confirm', $order->id)); ?>" method="POST">
                                                        <?php echo csrf_field(); ?>
                                                        <button type="submit" class="bg-gradient-to-r from-[#f59e0b] to-[#d97706] hover:from-[#d97706] hover:to-[#b45309] text-white px-3 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all">
                                                            Mulai Kemas
                                                        </button>
                                                    </form>
                                                <?php elseif($order->status === 'proccessing' && !$order->kurir_id): ?>
                                                    <form action="<?php echo e(route('orders.assign', $order->id)); ?>" method="POST" class="flex items-center gap-2">
                                                        <?php echo csrf_field(); ?>
                                                        <select name="kurir_id" required class="text-[10px] py-1 border border-[#e0d3c2] rounded-lg bg-[#fef9f0] text-[#2c1a0e]">
                                                            <option value="" disabled selected>Pilih Kurir</option>
                                                            <?php $__currentLoopData = $kurirs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kurir): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <option value="<?php echo e($kurir->id); ?>"><?php echo e($kurir->name); ?></option>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </select>
                                                        <button type="submit" class="bg-[#2c1a0e] hover:bg-[#d97706] text-white px-3 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all whitespace-nowrap">
                                                            Kirim ke Kurir
                                                        </button>
                                                    </form>
                                                <?php elseif($order->kurir_id): ?>
                                                    <div class="text-left">
                                                        <span class="text-[9px] text-[#c9b59b] block uppercase font-bold">Kurir:</span>
                                                        <span class="text-xs font-bold text-[#d97706]"><?php echo e($order->kurir->name ?? 'N/A'); ?></span>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        <?php endif; ?>

                                            <?php if(Auth::user()->role === 'kurir'): ?>
                                                <?php if($order->status === 'confirmed'): ?>
                                                    <form action="<?php echo e(route('orders.pickup', $order->id)); ?>" method="POST">
                                                        <?php echo csrf_field(); ?>
                                                        <button type="submit" class="bg-[#f59e0b] hover:bg-[#d97706] text-white px-4 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all">
                                                            Mulai Antar
                                                        </button>
                                                    </form>
                                                <?php endif; ?>

                                                <?php if($order->status === 'shipping'): ?>
                                                    <div x-data="{ openConfirm: false }">
                                                        <button @click="openConfirm = true" class="bg-emerald-600 hover:bg-emerald-700 text-white px-4 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all">
                                                            Selesaikan Pesanan
                                                        </button>
                                                        <template x-teleport="body">
                                                            <div x-show="openConfirm" class="fixed inset-0 z-[99] flex items-center justify-center p-4 bg-[#2c1a0e]/60 backdrop-blur-sm" x-cloak>
                                                                <div @click.away="openConfirm = false" class="bg-white border border-[#e0d3c2] w-full max-w-lg rounded-2xl p-6 shadow-2xl">
                                                                    <h2 class="text-[#2c1a0e] font-black text-sm uppercase mb-6 text-left">Konfirmasi Sampai Tujuan</h2>
                                                                    <form action="<?php echo e(route('orders.deliver', $order->id)); ?>" method="POST" enctype="multipart/form-data">
                                                                        <?php echo csrf_field(); ?>
                                                                        <div class="space-y-4 text-left">
                                                                            <div>
                                                                                <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block">Nama Penerima</label>
                                                                                <input type="text" name="receiver_name" required class="w-full bg-[#fef9f0] border border-[#e0d3c2] rounded-xl text-[#2c1a0e] py-3 px-4 focus:ring-2 focus:ring-[#f59e0b]/50">
                                                                            </div>
                                                                            <div>
                                                                                <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block">Foto Bukti (JPG/PNG)</label>
                                                                                <input type="file" name="proof_of_delivery" required accept="image/*" class="text-xs text-[#8c6a4a]">
                                                                            </div>
                                                                            <button type="submit" class="w-full bg-gradient-to-r from-[#f59e0b] to-[#d97706] text-white py-4 rounded-xl font-black text-xs uppercase mt-4">Kirim & Selesai</button>
                                                                        </div>
                                                                    </form>
                                                                </div>
                                                            </div>
                                                        </template>
                                                    </div>
                                                <?php endif; ?>
                                            <?php endif; ?>

                                            
                                            <?php if(Auth::user()->role === 'customer'): ?>
                                                <?php if($order->status === 'waiting_payment'): ?>
                                                    <?php if($order->snap_token): ?>
                                                        <button onclick="bayarSekarang('<?php echo e($order->snap_token); ?>', '<?php echo e(route('orders.index')); ?>')"
                                                            class="bg-gradient-to-r from-[#f59e0b] to-[#d97706] hover:from-[#d97706] hover:to-[#b45309] text-white px-4 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all whitespace-nowrap inline-block text-center">
                                                            BAYAR SEKARANG
                                                        </button>
                                                    <?php else: ?>
                                                        <a href="<?php echo e(route('orders.recheckout', $order->id)); ?>"
                                                            class="bg-gradient-to-r from-[#f59e0b] to-[#d97706] hover:from-[#d97706] hover:to-[#b45309] text-white px-4 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all whitespace-nowrap inline-block text-center">
                                                            BAYAR SEKARANG
                                                        </a>
                                                    <?php endif; ?>
                                                <?php endif; ?>

                                                <?php if($order->status === 'completed' && !$order->user_confirmed_at && !$order->rating): ?>
                                                    <div x-data="{ openRating: false }">
                                                        <button @click="openRating = true" class="bg-emerald-600 hover:bg-emerald-700 text-white px-4 py-2 rounded-xl font-black text-[10px] uppercase shadow-sm transition-all whitespace-nowrap">
                                                            Konfirmasi & Beri Rating
                                                        </button>

                                                        <template x-teleport="body">
                                                            <div x-show="openRating" class="fixed inset-0 z-[99] flex items-center justify-center p-4 bg-[#2c1a0e]/60 backdrop-blur-sm" x-cloak>
                                                                <div @click.away="openRating = false" class="bg-white w-full max-w-md rounded-2xl p-6 shadow-2xl relative max-h-[90vh] overflow-y-auto border border-[#e0d3c2]">
                                                                    <button @click="openRating = false" class="absolute top-4 right-4 text-[#c9b59b] hover:text-[#8c6a4a]">
                                                                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
                                                                    </button>
                                                                    
                                                                    <div class="text-center mb-6">
                                                                        <div class="w-16 h-16 bg-[#fef3c7] text-[#d97706] rounded-full flex items-center justify-center mx-auto mb-4">
                                                                            <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
                                                                        </div>
                                                                        <h2 class="text-xl font-black text-[#2c1a0e] uppercase">Pesanan Diterima</h2>
                                                                        <p class="text-[#8c6a4a] text-sm">Berikan rating & foto untuk menyelesaikan pesanan.</p>
                                                                    </div>

                                                                    <form action="<?php echo e(route('orders.confirm_received', $order->id)); ?>" method="POST" enctype="multipart/form-data">
                                                                        <?php echo csrf_field(); ?>
                                                                        <div class="space-y-6">
                                                                            <div x-data="{ hover: 0, rating: 0 }">
                                                                                <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-3 block text-center">Rating Produk</label>
                                                                                <div class="flex justify-center gap-2">
                                                                                    <template x-for="i in 5">
                                                                                        <svg @click="rating = i" @mouseenter="hover = i" @mouseleave="hover = 0"
                                                                                            :class="(hover || rating) >= i ? 'text-[#f59e0b]' : 'text-[#e0d3c2]'"
                                                                                            class="w-10 h-10 cursor-pointer transition-transform hover:scale-110" fill="currentColor" viewBox="0 0 20 20">
                                                                                            <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
                                                                                        </svg>
                                                                                    </template>
                                                                                </div>
                                                                                <input type="hidden" name="rating" x-model="rating" required>
                                                                            </div>

                                                                            <div>
                                                                                <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block text-left">Ulasan Anda</label>
                                                                                <textarea name="review" required rows="3" class="w-full border-[#e0d3c2] bg-[#fef9f0] rounded-xl text-sm focus:ring-2 focus:ring-[#f59e0b]/50 focus:border-[#f59e0b]" placeholder="Ceritakan kepuasan Anda..."></textarea>
                                                                            </div>

                                                                            <div x-data="{ files: null }">
                                                                                <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block text-left">Tambahkan Foto (Max 5)</label>
                                                                                <div class="relative group">
                                                                                    <input type="file" name="photos[]" multiple accept="image/*" 
                                                                                        @change="files = $event.target.files"
                                                                                        class="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10">
                                                                                    <div class="border-2 border-dashed border-[#e0d3c2] rounded-xl p-4 text-center group-hover:border-[#f59e0b] transition-colors bg-[#fef9f0]">
                                                                                        <svg class="w-8 h-8 text-[#c9b59b] mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
                                                                                        <p class="text-[10px] text-[#8c6a4a] font-medium" x-text="files ? files.length + ' Foto dipilih' : 'Klik atau seret foto ke sini'"></p>
                                                                                    </div>
                                                                                </div>
                                                                            </div>

                                                                            <button type="submit" class="w-full bg-gradient-to-r from-[#f59e0b] to-[#d97706] text-white py-4 rounded-xl font-black text-xs uppercase hover:from-[#d97706] hover:to-[#b45309] transition-all shadow-md shadow-[#f59e0b]/20">
                                                                                Kirim & Selesaikan
                                                                            </button>
                                                                        </div>
                                                                    </form>
                                                                </div>
                                                            </div>
                                                        </template>
                                                    </div>
                                                <?php elseif($order->user_confirmed_at || $order->rating): ?>
                                                    <span class="text-emerald-500 font-black text-[9px] uppercase px-2 py-1 bg-emerald-50 rounded-lg border border-emerald-100 whitespace-nowrap">
                                                        ✅ Selesai
                                                    </span>
                                                <?php endif; ?>
                                            <?php endif; ?>

                                            
                                            <?php if(Auth::user()->role === 'customer'): ?>
                                                <?php if($order->status == 'waiting_payment'): ?>
                                                    <?php if($order->snap_token): ?>
                                                        <button onclick="bayarSekarang('<?php echo e($order->snap_token); ?>', '<?php echo e(route('orders.index')); ?>')"
                                                        class="block w-full text-center py-3 rounded-xl text-xs font-bold uppercase bg-[#f59e0b] text-white hover:bg-[#d97706] mb-3 shadow-md transition">
                                                        <i class="fas fa-wallet mr-2"></i> Bayar Sekarang
                                                        </button>
                                                    <?php else: ?>
                                                        <a href="<?php echo e(route('orders.recheckout', $order->id)); ?>" 
                                                        class="block w-full text-center py-3 rounded-xl text-xs font-bold uppercase bg-[#f59e0b] text-white hover:bg-[#d97706] mb-3 shadow-md transition">
                                                        <i class="fas fa-wallet mr-2"></i> Bayar Sekarang
                                                        </a>
                                                    <?php endif; ?>
                                                <?php elseif($order->status == 'cancelled'): ?>
                                                    <a href="<?php echo e(route('orders.recheckout', $order->id)); ?>" 
                                                    class="block w-full text-center py-3 rounded-xl text-xs font-bold uppercase bg-gray-800 text-white hover:bg-black mb-3 transition">
                                                    <i class="fas fa-redo mr-2"></i> Pesan Lagi
                                                    </a>
                                                <?php endif; ?>
                                            <?php endif; ?>

                                            
                                            <?php if(Auth::user()->role !== 'kurir'): ?>
                                                <a href="<?php echo e(route('orders.show', $order->id)); ?>" 
                                                class="block w-full text-center py-3 rounded-xl text-xs font-bold uppercase border bg-[#fef9f0] text-[#8c6a4a] border-[#e0d3c2] hover:bg-[#fef3c7] hover:text-[#d97706] transition">
                                                    Lihat Detail
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                </div>

                
                <div class="grid grid-cols-1 gap-4 md:hidden">
                    <?php $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="bg-white p-5 rounded-2xl shadow-sm border border-[#e0d3c2]">
                            <div class="flex justify-between items-start mb-4">
                                <span class="font-bold text-[#d97706]">#<?php echo e($order->order_number ?? $order->id); ?></span>
                                <span class="text-xs font-medium text-[#c9b59b]"><?php echo e($order->created_at->format('d/m/y')); ?></span>
                            </div>
                            
                            
                            <div class="mb-4">
                                <?php
                                    $current = $statusMap[$order->status] ?? ['label' => $order->status, 'class' => 'bg-gray-50 text-gray-700'];
                                ?>
                                <span class="<?php echo e($current['class']); ?> px-3 py-1 rounded-full text-[9px] font-black border uppercase">
                                    <?php echo e($current['label']); ?>

                                </span>
                                
                                
                                <?php if(Auth::user()->role === 'customer'): ?>
                                    <?php if($order->status === 'proccessing'): ?>
                                        <p class="text-[10px] text-blue-500 font-bold mt-2">📦 Barang sedang dikemas. Estimasi <?php echo e($order->shippingRate->estimation ?? '2-3 Hari'); ?> lagi sampai.</p>
                                    <?php elseif($order->status === 'shipping' && $order->shipped_at): ?>
                                        <?php
                                            $estText = $order->shippingRate->estimation ?? '3 Hari';
                                            preg_match_all('!\d+!', $estText, $matches);
                                            $days = !empty($matches[0]) ? max($matches[0]) : 3;
                                            $arrival = $order->shipped_at->addDays($days);
                                        ?>
                                        <p class="text-[10px] text-purple-600 font-bold mt-2">🚚 Sedang diantar. Estimasi sampai <?php echo e($arrival->translatedFormat('d F Y')); ?></p>
                                    <?php endif; ?>
                                <?php endif; ?>
                            </div>

                            <?php if(Auth::user()->role === 'admin' && $order->notes): ?>
                            <div class="mb-4 p-3 bg-[#fef9f0] rounded-xl border border-[#e0d3c2]">
                                <span class="text-[9px] font-black text-[#8c6a4a] uppercase block mb-1">Catatan:</span>
                                <p class="text-xs text-[#2c1a0e]/80 italic leading-relaxed"><?php echo e($order->notes); ?></p>
                            </div>
                            <?php endif; ?>

                            <div class="flex justify-between mb-4">
                                <span class="text-[#8c6a4a] text-sm">Total:</span>
                                <span class="font-bold text-[#2c1a0e]">Rp <?php echo e(number_format($order->total_price, 0, ',', '.')); ?></span>
                            </div>
                            
                            <div class="flex flex-col gap-2">
                                <?php if(Auth::user()->role === 'admin'): ?>
                                    <?php if($order->status === 'completed' && $order->proof_of_delivery): ?>
                                        <a href="<?php echo e(asset('storage/' . $order->proof_of_delivery)); ?>" target="_blank" class="w-full bg-amber-100 text-amber-700 py-3 rounded-xl font-bold text-xs uppercase text-center block">Lihat Bukti Kurir</a>
                                    <?php endif; ?>

                                    <?php if($order->status === 'pending'): ?>
                                        <form action="<?php echo e(route('orders.confirm', $order->id)); ?>" method="POST">
                                            <?php echo csrf_field(); ?>
                                            <button type="submit" class="w-full bg-gradient-to-r from-[#f59e0b] to-[#d97706] text-white py-3 rounded-xl font-bold text-xs uppercase">Konfirmasi Pembayaran</button>
                                        </form>
                                    <?php elseif($order->status === 'paid'): ?>
                                        <form action="<?php echo e(route('orders.confirm', $order->id)); ?>" method="POST">
                                            <?php echo csrf_field(); ?>
                                            <button type="submit" class="w-full bg-gradient-to-r from-[#f59e0b] to-[#d97706] text-white py-3 rounded-xl font-bold text-xs uppercase">Kemas & Kurangi Stok</button>
                                        </form>
                                    <?php endif; ?>
                                <?php endif; ?>

                                <?php if(Auth::user()->role === 'kurir' && $order->status === 'confirmed'): ?>
                                    <form action="<?php echo e(route('orders.pickup', $order->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="w-full bg-[#f59e0b] text-white py-3 rounded-xl font-bold text-xs uppercase">Mulai Antar</button>
                                    </form>
                                <?php endif; ?>

                                <?php if(Auth::user()->role === 'customer'): ?>
                                    <?php if($order->status === 'pending'): ?>
                                        <a href="<?php echo e(route('orders.show', $order->id)); ?>" 
                                        class="w-full bg-gradient-to-r from-[#f59e0b] to-[#d97706] text-white py-3 rounded-xl font-bold text-xs uppercase text-center block shadow-md">
                                        Bayar Sekarang
                                        </a>
                                    <?php endif; ?>

                                    
                                    <?php if($order->status === 'completed' && !$order->user_confirmed_at): ?>
                                        <div x-data="{ openRating: false }">
                                            <button @click="openRating = true" class="w-full bg-emerald-600 text-white py-3 rounded-xl font-bold text-xs uppercase shadow-md">
                                                Konfirmasi & Beri Rating
                                            </button>

                                            <template x-teleport="body">
                                                <div x-show="openRating" class="fixed inset-0 z-[99] flex items-center justify-center p-4 bg-[#2c1a0e]/60 backdrop-blur-sm" x-cloak>
                                                    <div @click.away="openRating = false" class="bg-white border border-[#e0d3c2] w-full max-w-lg rounded-2xl p-6">
                                                        <h2 class="text-[#2c1a0e] font-black text-sm uppercase mb-6">Beri Ulasan Produk</h2>
                                                        
                                                        <form action="<?php echo e(route('orders.confirm_received', $order->id)); ?>" method="POST" enctype="multipart/form-data">
                                                            <?php echo csrf_field(); ?>
                                                            <div class="space-y-5">
                                                                <div>
                                                                    <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block">Rating</label>
                                                                    <select name="rating" required class="w-full bg-[#fef9f0] border border-[#e0d3c2] rounded-xl text-[#d97706] py-3 px-4">
                                                                        <option value="5">⭐⭐⭐⭐⭐ (Sangat Puas)</option>
                                                                        <option value="4">⭐⭐⭐⭐ (Puas)</option>
                                                                        <option value="3">⭐⭐⭐ (Cukup)</option>
                                                                        <option value="2">⭐⭐ (Buruk)</option>
                                                                        <option value="1">⭐ (Sangat Buruk)</option>
                                                                    </select>
                                                                </div>

                                                                <div>
                                                                    <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block">Ulasan Anda</label>
                                                                    <textarea name="review" required rows="3" class="w-full bg-[#fef9f0] border border-[#e0d3c2] rounded-xl text-[#2c1a0e] py-3 px-4" placeholder="Tuliskan pendapat anda tentang produk ini..."></textarea>
                                                                </div>

                                                                <div x-data="{ files: null }">
                                                                    <label class="text-[10px] text-[#8c6a4a] font-bold uppercase mb-2 block text-left">Foto Produk (Maks 5)</label>
                                                                    <div class="relative group">
                                                                        <input type="file" name="photos[]" multiple accept="image/*" 
                                                                            @change="files = $event.target.files"
                                                                            class="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10">
                                                                        
                                                                        <div class="border-2 border-dashed border-[#e0d3c2] rounded-xl p-4 text-center group-hover:border-[#f59e0b] transition-colors bg-[#fef9f0]">
                                                                            <p class="text-[10px] text-[#8c6a4a]" x-text="files ? files.length + ' Foto dipilih' : 'Pilih Foto Ulasan'"></p>
                                                                        </div>
                                                                    </div>
                                                                </div>

                                                                <button type="submit" class="w-full bg-gradient-to-r from-[#f59e0b] to-[#d97706] text-white py-4 rounded-xl font-black text-xs uppercase shadow-md shadow-[#f59e0b]/20">
                                                                    Kirim Ulasan & Selesaikan
                                                                </button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            </template>
                                        </div>
                                    <?php endif; ?>

                                    <?php if($order->user_confirmed_at): ?>
                                        <div class="w-full py-3 rounded-xl bg-emerald-50 text-emerald-600 font-bold text-xs uppercase text-center border border-emerald-100">
                                            ✅ Pesanan Selesai
                                        </div>
                                    <?php endif; ?>
                                <?php endif; ?>

                               
                                <?php if(Auth::user()->role !== 'kurir'): ?>
                                    <a href="<?php echo e(route('orders.show', $order->id)); ?>" 
                                    class="block w-full text-center py-3 rounded-xl text-xs font-bold uppercase border bg-[#fef9f0] text-[#8c6a4a] border-[#e0d3c2] hover:bg-[#fef3c7] hover:text-[#d97706] transition">
                                        Lihat Detail
                                    </a>
                                <?php else: ?>
                                    
                                    <div class="w-full text-center py-3 rounded-xl text-[10px] font-bold uppercase bg-gray-50 text-gray-400 border border-gray-100">
                                        Detail Terbatas
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>

                <div class="mt-8">
                    <?php echo e($orders->links()); ?>

                </div>
            <?php endif; ?>
        </div>
    </div>
    
    <script src="https://app.midtrans.com/snap/snap.js" data-client-key="<?php echo e(config('midtrans.client_key')); ?>"></script>
    <script>
        function bayarSekarang(snapToken, redirectUrl) {
            window.snap.pay(snapToken, {
                onSuccess: function(result) {
                    window.location.href = redirectUrl;
                },
                onPending: function(result) {
                    window.location.href = redirectUrl;
                },
                onError: function(result) {
                    alert('Pembayaran gagal. Silakan coba lagi.');
                },
                onClose: function() {
                    // User menutup popup, tidak perlu redirect
                }
            });
        }
    </script>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH C:\laragon\www\LokaFurniture\resources\views/orders/index.blade.php ENDPATH**/ ?>