<?php $__env->startSection('title', 'Daftar Pesanan'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-6">

    <!-- Alert -->
    <?php if(session('success')): ?>
        <div x-data="{ show: true }" x-show="show" x-transition
             class="flex items-center gap-3 px-5 py-4 bg-emerald-50 border border-emerald-200 rounded-xl text-emerald-800">
            <i class="bi bi-check-circle-fill text-emerald-500"></i>
            <span class="flex-1"><?php echo e(session('success')); ?></span>
            <button @click="show = false" class="text-emerald-400 hover:text-emerald-600">
                <i class="bi bi-x-lg"></i>
            </button>
        </div>
    <?php endif; ?>

    <!-- Header -->
    <div class="flex items-center justify-between">
        <h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
            <i class="bi bi-bag-check text-primary"></i>
            Daftar Pesanan
        </h2>

        <div class="flex gap-3 items-center">
            <a href="<?php echo e(route('pesanans.laporan')); ?>" target="_blank" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-xl flex items-center gap-2 transition shadow-sm">
                <i class="bi bi-file-earmark-pdf"></i>
                Cetak Laporan
            </a>
            <span class="px-4 py-1.5 bg-emerald-100 text-emerald-700 text-sm font-medium rounded-xl">
                <?php echo e($pesanans->count()); ?> Pesanan
            </span>
        </div>
    </div>

    <!-- Table -->
    <div class="bg-white border border-gray-200 rounded-2xl shadow-sm overflow-hidden">

        <div class="overflow-x-auto">
            <table class="min-w-full text-sm text-left text-gray-600">

                <!-- Head -->
                <thead class="bg-gray-50 text-xs uppercase text-gray-500">
                    <tr>
                        <th class="px-6 py-3">ID</th>
                        <th class="px-6 py-3">Pelanggan</th>
                        <th class="px-6 py-3">Tanggal</th>
                        <th class="px-6 py-3">Total</th>
                        <th class="px-6 py-3">Pembayaran</th>
                        <th class="px-6 py-3">Status</th>
                        <th class="px-6 py-3 text-center">Aksi</th>
                    </tr>
                </thead>

                <!-- Body -->
                <tbody class="divide-y divide-gray-100">

                    <?php $__empty_1 = true; $__currentLoopData = $pesanans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pesanan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="hover:bg-gray-50 transition">

                        <!-- ID -->
                        <td class="px-6 py-4 text-gray-500">
                            #<?php echo e($pesanan->id); ?>

                        </td>

                        <!-- Pelanggan -->
                        <td class="px-6 py-4 font-medium text-gray-800">
                            <?php echo e($pesanan->user->nama ?? 'Umum'); ?>

                        </td>

                        <!-- Tanggal -->
                        <td class="px-6 py-4">
                            <?php echo e(\Carbon\Carbon::parse($pesanan->tanggal_pesanan)->format('d M Y')); ?>

                        </td>

                        <!-- Total -->
                        <td class="px-6 py-4 font-semibold text-orange-600">
                            Rp <?php echo e(number_format($pesanan->total_harga, 0, ',', '.')); ?>

                        </td>

                        <!-- Pembayaran -->
                        <td class="px-6 py-4">
                            <?php if($pesanan->pembayaran || $pesanan->metode_pembayaran): ?>
                                <div class="font-medium text-gray-800 text-sm">
                                    <?php echo e(strtoupper($pesanan->pembayaran->payment_type ?? $pesanan->metode_pembayaran)); ?>

                                </div>

                                <?php
                                    $statusBayar = $pesanan->pembayaran->transaction_status ?? 
                                        (in_array($pesanan->status, ['diproses', 'dikirim', 'selesai']) ? 'berhasil' : 'pending');
                                ?>

                                <?php if($statusBayar === 'berhasil'): ?>
                                    <span class="text-xs text-emerald-600">✔ Terbayar</span>
                                <?php elseif($statusBayar === 'pending'): ?>
                                    <span class="text-xs text-amber-500">⏳ Pending</span>
                                <?php else: ?>
                                    <span class="text-xs text-red-500">✖ Gagal</span>
                                <?php endif; ?>
                            <?php else: ?>
                                <span class="text-gray-400 text-sm">-</span>
                            <?php endif; ?>
                        </td>

                        <!-- Status -->
                        <td class="px-6 py-4">
                            <?php
                                $statusColors = [
                                    'pending'    => 'bg-yellow-100 text-yellow-700',
                                    'diproses'   => 'bg-blue-100 text-blue-700',
                                    'dikirim'    => 'bg-purple-100 text-purple-700',
                                    'selesai'    => 'bg-green-100 text-green-700',
                                    'dibatalkan' => 'bg-red-100 text-red-700'
                                ];
                                $color = $statusColors[$pesanan->status] ?? 'bg-gray-100 text-gray-700';
                            ?>
                            <span class="px-3 py-1.5 <?php echo e($color); ?> text-[11px] font-bold rounded-lg uppercase tracking-wider shadow-sm">
                                <?php echo e($pesanan->status); ?>

                            </span>
                        </td>

                        <!-- Aksi -->
                        <td class="px-6 py-4 text-center">
                            <a href="<?php echo e(route('pesanans.show', $pesanan->id)); ?>"
                               class="inline-flex items-center gap-1 px-3 py-1.5 text-sm border border-blue-300 text-blue-700 rounded-lg hover:bg-blue-50 transition">
                                <i class="bi bi-eye"></i>
                                Detail
                            </a>
                        </td>

                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="7" class="text-center py-12">
                            <div class="flex flex-col items-center text-gray-400">
                                <i class="bi bi-inbox text-4xl mb-3"></i>
                                <p>Belum ada pesanan</p>
                            </div>
                        </td>
                    </tr>
                    <?php endif; ?>

                </tbody>
            </table>
        </div>

    </div>

</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\Toko-miftah\resources\views/pesanans/index.blade.php ENDPATH**/ ?>