<?php $__env->startSection('title', 'Order Details'); ?>
<?php $__env->startSection('page-title', 'Order Details'); ?>

<?php $__env->startSection('content'); ?>
<div class="mb-6 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
    <div class="flex-1">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white">Order: #<?php echo e($order->order_number); ?></h2>
        <p class="text-sm text-gray-500 dark:text-gray-400">Order placed on <?php echo e($order->created_at->format('M d, Y H:i')); ?></p>
    </div>
    <div class="flex items-center gap-3">
        <a href="<?php echo e(route('admin.orders.index')); ?>" 
           class="inline-flex items-center px-4 py-2.5 bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-700 text-gray-700 dark:text-gray-300 text-sm font-medium rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors">
            <i class="fas fa-arrow-left mr-2"></i>Back to List
        </a>
    </div>
</div>

<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
    <!-- Order Information -->
    <div class="lg:col-span-2 space-y-6">
        <!-- Order Items -->
        <div class="bg-white dark:bg-gray-950 border border-gray-200 dark:border-gray-800 rounded-lg overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-800">
                <h3 class="text-lg font-medium text-gray-900 dark:text-white">Order Items</h3>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-800">
                    <thead class="bg-gray-50 dark:bg-gray-900">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Product</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Quantity</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Price</th>
                            <th class="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Subtotal</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white dark:bg-gray-950 divide-y divide-gray-200 dark:divide-gray-800">
                        <?php $__currentLoopData = $order->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="flex items-center">
                                    <div class="h-10 w-10 flex-shrink-0 bg-gray-100 dark:bg-gray-800 rounded-lg overflow-hidden">
                                        <?php if($item->product && $item->product->featured_image): ?>
                                            <img src="<?php echo e(Str::startsWith($item->product->featured_image, 'http') ? $item->product->featured_image : asset($item->product->featured_image)); ?>" alt="" class="h-full w-full object-cover">
                                        <?php else: ?>
                                            <div class="h-full w-full flex items-center justify-center text-gray-400"><i class="fas fa-image"></i></div>
                                        <?php endif; ?>
                                    </div>
                                    <div class="ml-4">
                                        <div class="text-sm font-medium text-gray-900 dark:text-white"><?php echo e($item->product ? $item->product->name : 'Deleted Product'); ?></div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white"><?php echo e($item->quantity); ?></td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white"><?php echo e(number_format($item->price, 2)); ?> <?php echo e($order->currency); ?></td>
                            <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium text-gray-900 dark:text-white"><?php echo e(number_format($item->line_subtotal, 2)); ?> <?php echo e($order->currency); ?></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot class="bg-gray-50 dark:bg-gray-900">
                        <tr>
                            <td colspan="3" class="px-6 py-3 text-right text-sm font-medium text-gray-500 dark:text-gray-400">Subtotal</td>
                            <td class="px-6 py-3 text-right text-sm font-bold text-gray-900 dark:text-white"><?php echo e(number_format($order->subtotal, 2)); ?> <?php echo e($order->currency); ?></td>
                        </tr>
                        <?php if($order->discount > 0): ?>
                        <tr>
                            <td colspan="3" class="px-6 py-3 text-right text-sm font-medium text-gray-500 dark:text-gray-400">Discount</td>
                            <td class="px-6 py-3 text-right text-sm font-bold text-red-600">- <?php echo e(number_format($order->discount, 2)); ?> <?php echo e($order->currency); ?></td>
                        </tr>
                        <?php endif; ?>
                        <?php if($order->shipping_fee > 0): ?>
                        <tr>
                            <td colspan="3" class="px-6 py-3 text-right text-sm font-medium text-gray-500 dark:text-gray-400">Shipping Fee</td>
                            <td class="px-6 py-3 text-right text-sm font-bold text-gray-900 dark:text-white">+ <?php echo e(number_format($order->shipping_fee, 2)); ?> <?php echo e($order->currency); ?></td>
                        </tr>
                        <?php endif; ?>
                        <tr class="bg-blue-50 dark:bg-blue-900/10">
                            <td colspan="3" class="px-6 py-4 text-right text-base font-bold text-gray-900 dark:text-white uppercase tracking-wider">Total</td>
                            <td class="px-6 py-4 text-right text-xl font-extrabold text-blue-600 dark:text-blue-400"><?php echo e(number_format($order->total, 2)); ?> <?php echo e($order->currency); ?></td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>

        <!-- Note -->
        <?php if($order->note): ?>
        <div class="bg-white dark:bg-gray-950 border border-gray-200 dark:border-gray-800 rounded-lg p-6">
            <h3 class="text-sm font-bold text-gray-900 dark:text-white mb-2 uppercase tracking-wider">Order Note</h3>
            <p class="text-gray-700 dark:text-gray-300 whitespace-pre-line"><?php echo e($order->note); ?></p>
        </div>
        <?php endif; ?>
    </div>

    <!-- Sidebar Info -->
    <div class="space-y-6">
        <!-- Order Status -->
        <div class="bg-white dark:bg-gray-950 border border-gray-200 dark:border-gray-800 rounded-lg p-6">
            <div class="mb-5 flex items-center justify-between"><div><h3 class="text-sm font-bold uppercase tracking-wider text-gray-900 dark:text-white">Order Status</h3><p class="mt-1 text-xs text-gray-500">Select the next stage in the fulfillment workflow.</p></div><span class="rounded-full bg-blue-50 px-3 py-1 text-xs font-semibold text-blue-700 dark:bg-blue-900/30 dark:text-blue-300"><?php echo e(ucfirst($order->order_status)); ?></span></div>
            <form action="<?php echo e(route('admin.orders.update', $order->id)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>
                <div class="space-y-4">
                    <?php ($statusOptions = ['pending' => 'clock', 'confirmed' => 'circle-check', 'processing' => 'gears', 'delivering' => 'truck', 'completed' => 'flag-checkered', 'cancelled' => 'ban', 'returned' => 'rotate-left']); ?>
                    <div class="grid grid-cols-2 gap-2">
                        <?php $__currentLoopData = $statusOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status => $icon): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <label class="cursor-pointer">
                                <input type="radio" name="status" value="<?php echo e($status); ?>" class="peer sr-only" <?php echo e($order->order_status === $status ? 'checked' : ''); ?>>
                                <span class="flex items-center gap-2 rounded-xl border border-slate-200 px-3 py-2.5 text-xs font-semibold text-slate-600 hover:border-blue-300 peer-checked:border-blue-600 peer-checked:bg-blue-50 peer-checked:text-blue-700 dark:border-slate-700 dark:text-slate-300 dark:peer-checked:bg-blue-950/40"><i class="fa-solid fa-<?php echo e($icon); ?> w-4 text-center"></i><?php echo e(ucfirst($status)); ?></span>
                            </label>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <button type="submit" class="btn-primary w-full"><i class="fa-solid fa-arrows-rotate"></i> Update Status</button>
                </div>
            </form>
        </div>

        <!-- Customer Information -->
        <div class="bg-white dark:bg-gray-950 border border-gray-200 dark:border-gray-800 rounded-lg p-6">
            <h3 class="text-sm font-bold text-gray-900 dark:text-white mb-4 uppercase tracking-wider">Customer Details</h3>
            <div class="space-y-4">
                <div class="flex items-start gap-3">
                    <div class="h-10 w-10 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center text-gray-500 dark:text-gray-400 flex-shrink-0">
                        <i class="fas fa-user"></i>
                    </div>
                    <div>
                        <div class="text-sm font-bold text-gray-900 dark:text-white"><?php echo e($order->customer_name); ?></div>
                        <?php if($order->user): ?>
                            <div class="text-xs text-blue-600 dark:text-blue-400 font-medium">Registered User #<?php echo e($order->user_id); ?></div>
                        <?php else: ?>
                            <div class="text-xs text-gray-500 dark:text-gray-400 font-medium">Guest Checkout</div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="pt-4 border-t border-gray-100 dark:border-gray-800 space-y-3">
                    <div class="flex items-center gap-3 text-sm">
                        <i class="fas fa-envelope text-gray-400 w-4"></i>
                        <span class="text-gray-700 dark:text-gray-300 font-medium"><?php echo e($order->customer_email); ?></span>
                    </div>
                    <div class="flex items-center gap-3 text-sm">
                        <i class="fas fa-phone text-gray-400 w-4"></i>
                        <span class="text-gray-700 dark:text-gray-300 font-medium"><?php echo e($order->customer_phone); ?></span>
                    </div>
                    <div class="flex items-start gap-3 text-sm">
                        <i class="fas fa-map-marker-alt text-gray-400 w-4 mt-0.5"></i>
                        <span class="text-gray-700 dark:text-gray-300 font-medium leading-relaxed"><?php echo e($order->shipping_detail); ?></span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Payment Information -->
        <div class="bg-white dark:bg-gray-950 border border-gray-200 dark:border-gray-800 rounded-lg p-6">
            <h3 class="text-sm font-bold text-gray-900 dark:text-white mb-4 uppercase tracking-wider">Payment Details</h3>
            <div class="flex items-center gap-3">
                <div class="h-10 w-10 bg-green-100 dark:bg-green-900/30 rounded-lg flex items-center justify-center text-green-600 dark:text-green-400">
                    <?php if(strtolower($order->payment_method) == 'bakong' || strtolower($order->payment_method) == 'aba'): ?>
                        <i class="fas fa-university"></i>
                    <?php else: ?>
                        <i class="fas fa-money-bill-wave"></i>
                    <?php endif; ?>
                </div>
                <div>
                    <div class="text-sm font-bold text-gray-900 dark:text-white uppercase"><?php echo e($order->payment_method); ?></div>
                    <div class="text-xs text-gray-500 dark:text-gray-400 font-medium font-mono uppercase tracking-widest">Method</div>
                </div>
            </div>
        </div>

        <div class="bg-white dark:bg-gray-950 border border-gray-200 dark:border-gray-800 rounded-lg p-6">
            <h3 class="text-sm font-bold text-gray-900 dark:text-white mb-4 uppercase tracking-wider">Customer Order History</h3>
            <div class="space-y-3">
                <?php $__empty_1 = true; $__currentLoopData = $customerOrderHistory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $historyOrder): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <a href="<?php echo e(route('admin.orders.show', $historyOrder->id)); ?>" class="block rounded-lg border border-gray-100 dark:border-gray-800 p-3 hover:bg-gray-50 dark:hover:bg-gray-900 transition-colors">
                        <div class="flex items-start justify-between gap-3">
                            <div>
                                <div class="text-sm font-semibold text-gray-900 dark:text-white">#<?php echo e($historyOrder->order_number); ?></div>
                                <div class="text-xs text-gray-500 dark:text-gray-400"><?php echo e($historyOrder->created_at->format('M d, Y H:i')); ?></div>
                            </div>
                            <div class="text-right">
                                <div class="text-sm font-medium text-gray-900 dark:text-white"><?php echo e(number_format($historyOrder->total, 2)); ?> <?php echo e($historyOrder->currency); ?></div>
                                <div class="text-xs text-gray-500 dark:text-gray-400"><?php echo e(ucfirst($historyOrder->status)); ?></div>
                            </div>
                        </div>
                    </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="text-sm text-gray-500 dark:text-gray-400">No additional order history found for this customer.</p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/mac/Documents/e-com/resources/views/admin/orders/show.blade.php ENDPATH**/ ?>