

<?php $__env->startSection('content'); ?>
<?php ($role = auth()->user()?->role?->nama_roles); ?>
<div class="space-y-6">
    <div>
        <h2 class="text-2xl font-semibold text-slate-900">
            <?php if($role =='cashier'): ?>
            Closed Bill
            <?php else: ?>
            Semua Order
            <?php endif; ?>
        </h2>
        <p class="text-sm text-slate-500">Pantau semua order.</p>
    </div>

    <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
        <div class="mb-4 flex flex-wrap items-center justify-between gap-3">
            <div class="flex flex-wrap items-center gap-3">
                <input
                    id="orders-search"
                    name="q"
                    placeholder="Cari meja atau pelanggan"
                    value="<?php echo e($search); ?>"
                    class="w-full rounded-lg border border-amber-100 px-3 py-2 text-sm text-amber-900 shadow-sm focus:border-amber-400 focus:ring-amber-200 md:w-72" />

                <div id="orders-filters" class="flex flex-wrap items-center gap-2 text-xs">
                    <?php ($statusFilter = $status ?: 'all'); ?>
                    <a href="<?php echo e(route('orders.all', array_merge(request()->query(), ['status' => null]))); ?>"
                        class="rounded-full border px-3 py-1.5 font-semibold transition <?php echo e($statusFilter === 'all' ? 'border-[#4b1a22] bg-[#4b1a22] text-amber-50' : 'border-amber-200 text-amber-900 hover:bg-amber-50'); ?>">
                        Semua
                    </a>
                    <a href="<?php echo e(route('orders.all', array_merge(request()->query(), ['status' => 'open']))); ?>"
                        class="rounded-full border px-3 py-1.5 font-semibold transition <?php echo e($statusFilter === 'open' ? 'border-emerald-700 bg-emerald-700 text-white' : 'border-amber-200 text-amber-900 hover:bg-amber-50'); ?>">
                        Open
                    </a>
                    <a href="<?php echo e(route('orders.all', array_merge(request()->query(), ['status' => 'closed']))); ?>"
                        class="rounded-full border px-3 py-1.5 font-semibold transition <?php echo e($statusFilter === 'closed' ? 'border-sky-700 bg-sky-700 text-white' : 'border-amber-200 text-amber-900 hover:bg-amber-50'); ?>">
                        Closed
                    </a>
                </div>

                <?php if($role === 'cashier'): ?>
                <?php ($typeLinks = ['' => 'Semua', 'take_away' => 'Take Away', 'dine_in' => 'Dine In']); ?>
                <?php $__currentLoopData = $typeLinks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php ($query = array_merge(request()->query(), ['type' => $value ?: null, 'page' => 1])); ?>
                <a href="<?php echo e(route('orders.all', $query)); ?>"
                    class="rounded-full border px-3 py-1.5 text-xs font-semibold transition <?php echo e($type === $value ? 'border-[#4b1a22] bg-[#4b1a22] text-amber-50' : 'border-amber-200 text-amber-900 hover:bg-amber-50'); ?>">
                    <?php echo e($label); ?>

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

            <?php if($role === 'cashier'): ?>
            <div class="ml-auto flex w-full flex-wrap items-center justify-end gap-2 md:w-auto">
                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['href' => ''.e(route('orders.index')).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => ''.e(route('orders.index')).'']); ?>Buat Order <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['href' => ''.e(route('dashboard.cashier')).'','variant' => 'secondary']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => ''.e(route('dashboard.cashier')).'','variant' => 'secondary']); ?>Dashboard Cashier <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['href' => ''.e(route('orders.recap.print')).'','target' => '_blank']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => ''.e(route('orders.recap.print')).'','target' => '_blank']); ?>Print Recap Hari Ini <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
            </div>
            <?php endif; ?>
        </div>
        <div id="orders-table">
            <?php if (isset($component)) { $__componentOriginal163c8ba6efb795223894d5ffef5034f5 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal163c8ba6efb795223894d5ffef5034f5 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.table','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('table'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
                <thead class="bg-slate-50 text-xs uppercase text-slate-500">
                    <tr>
                        <th class="px-4 py-3">Order No</th>
                        <th class="px-4 py-3">Tanggal</th>
                        <th class="px-4 py-3">Meja / Pelanggan</th>
                        <th class="px-4 py-3">Status</th>
                        <th class="px-4 py-3">Grand Total</th>
                        <th class="px-4 py-3 text-right">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="border-b border-slate-100">
                        <td class="px-4 py-3 font-medium text-slate-800"><?php echo e($order->order_no); ?></td>
                        <td class="px-4 py-3"><?php echo e($order->tanggal->format('d-m-Y H:i')); ?></td>
                        <td class="px-4 py-3">
                            <?php if($order->type === 'dine_in'): ?>
                            <div>Meja <?php echo e($order->meja?->no_meja ?? '-'); ?></div>
                            <?php if($order->meja_tambahan): ?>
                            <div class="mt-1 text-xs text-slate-500">
                                Tambahan: <?php echo e($order->meja_tambahan); ?>

                            </div>
                            <?php endif; ?>
                            <?php else: ?>
                            <?php echo e($order->nama_pelanggan ?? '-'); ?>

                            <?php endif; ?>
                        </td>
                        <td class="px-4 py-3">
                            <?php if (isset($component)) { $__componentOriginal2ddbc40e602c342e508ac696e52f8719 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2ddbc40e602c342e508ac696e52f8719 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.badge','data' => ['variant' => $order->status === 'open' ? 'success' : ($order->status === 'closed' ? 'info' : 'danger')]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('badge'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['variant' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($order->status === 'open' ? 'success' : ($order->status === 'closed' ? 'info' : 'danger'))]); ?>
                                <?php echo e(ucfirst($order->status)); ?>

                             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $attributes = $__attributesOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $component = $__componentOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__componentOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
                        </td>
                        <?php ($orderTotal = $order->grand_total_after_discount ?? $order->grand_total); ?>
                        <td class="px-4 py-3"><?php echo e(format_rupiah($orderTotal)); ?></td>
                        <td class="px-4 py-3 text-right">
                            <?php if((auth()->user()?->role?->nama_roles ?? '') === 'cashier'): ?>
                            <div class="inline-flex flex-wrap justify-end gap-2">
                                <?php if($order->status === 'open'): ?>
                                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['variant' => 'secondary','href' => ''.e(route('orders.show', $order)).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['variant' => 'secondary','href' => ''.e(route('orders.show', $order)).'']); ?>Detail <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['variant' => 'secondary','href' => ''.e(route('orders.close_bill', $order)).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['variant' => 'secondary','href' => ''.e(route('orders.close_bill', $order)).'']); ?>Bayar <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                                <?php else: ?>
                                 <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['variant' => 'secondary','href' => ''.e(route('orders.close_bill', $order)).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['variant' => 'secondary','href' => ''.e(route('orders.close_bill', $order)).'']); ?>Detail <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                                <?php endif; ?>
                                <?php if($order->status === 'open' && $order->type === 'dine_in'): ?>
                                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'button','class' => 'open-move-table-modal','dataOrderId' => ''.e($order->id).'','dataOrderNo' => ''.e($order->order_no).'','dataCurrentMejaId' => ''.e($order->id_meja).'','dataCurrentMejaNo' => ''.e($order->meja?->no_meja ?? '-').'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'button','class' => 'open-move-table-modal','data-order-id' => ''.e($order->id).'','data-order-no' => ''.e($order->order_no).'','data-current-meja-id' => ''.e($order->id_meja).'','data-current-meja-no' => ''.e($order->meja?->no_meja ?? '-').'']); ?>
                                    Pindah Meja
                                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                                <?php endif; ?>
                            </div>
                            <?php else: ?>
                            <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['variant' => 'secondary','href' => ''.e(route('orders.show', $order)).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['variant' => 'secondary','href' => ''.e(route('orders.show', $order)).'']); ?>Detail <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td class="px-4 py-6 text-center text-slate-500" colspan="6">Data kosong.</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal163c8ba6efb795223894d5ffef5034f5)): ?>
<?php $attributes = $__attributesOriginal163c8ba6efb795223894d5ffef5034f5; ?>
<?php unset($__attributesOriginal163c8ba6efb795223894d5ffef5034f5); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal163c8ba6efb795223894d5ffef5034f5)): ?>
<?php $component = $__componentOriginal163c8ba6efb795223894d5ffef5034f5; ?>
<?php unset($__componentOriginal163c8ba6efb795223894d5ffef5034f5); ?>
<?php endif; ?>
        </div>

        <div id="orders-pagination" class="mt-4"><?php echo e($orders->links()); ?></div>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $attributes = $__attributesOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__attributesOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $component = $__componentOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__componentOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>

    <?php if($role === 'cashier'): ?>
    <div id="move-table-modal" class="fixed inset-0 z-50 hidden items-center justify-center bg-slate-900/60 p-4">
        <div class="w-full max-w-md rounded-xl bg-white p-6 shadow-lg">
            <div class="flex items-center justify-between">
                <h3 class="text-lg font-semibold text-slate-900">Pindah Meja</h3>
                <button type="button" id="move-table-modal-close" class="text-slate-400 hover:text-slate-600">&times;</button>
            </div>
            <p id="move-table-modal-order" class="mt-1 text-sm text-slate-500"></p>
            <div class="mt-3 flex flex-wrap items-center gap-2 text-xs">
                <span class="inline-flex items-center rounded-full bg-emerald-100 px-2 py-0.5 font-semibold text-emerald-700">Kosong</span>
                <span class="inline-flex items-center rounded-full bg-rose-100 px-2 py-0.5 font-semibold text-rose-700">Terisi</span>
            </div>

            <form method="post" id="move-table-form" class="mt-4 space-y-4">
                <?php echo csrf_field(); ?>
                <div>
                    <label for="move-table-select" class="mb-2 block text-sm font-semibold text-slate-700">Pilih Meja</label>
                    <select id="move-table-select" name="id_meja" class="block w-full rounded-lg border border-amber-100 px-3 py-2 text-sm text-slate-700 shadow-sm focus:border-amber-400 focus:ring-amber-200" required>
                        <option value="">Pilih Meja</option>
                        <?php $__currentLoopData = $mejas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $meja): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option
                            value="<?php echo e($meja->id); ?>"
                            data-label="<?php echo e($meja->no_meja); ?>"
                            data-occupied-by="<?php echo e($meja->open_order_id ?? ''); ?>"
                            data-status="<?php echo e($meja->open_order_id ? 'occupied' : 'empty'); ?>">
                            <?php echo e($meja->no_meja); ?>

                        </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    <p id="move-table-current" class="mt-2 text-xs text-slate-500"></p>
                    <p id="move-table-selected-status" class="mt-1 text-xs text-slate-500"></p>
                </div>
                <div class="flex justify-end gap-2">
                    <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'button','variant' => 'secondary','id' => 'move-table-cancel']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'button','variant' => 'secondary','id' => 'move-table-cancel']); ?>Batal <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                    <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'submit']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('button'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['type' => 'submit']); ?>Pindahkan <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                </div>
            </form>
        </div>
    </div>
    <?php endif; ?>
</div>

<script>
    let ordersReloadTimer;
    const ordersSearch = document.getElementById('orders-search');
    const ordersTable = document.getElementById('orders-table');
    const ordersPagination = document.getElementById('orders-pagination');
    const userRole = <?php echo json_encode($role, 15, 512) ?>;
    const moveTableModal = document.getElementById('move-table-modal');
    const moveTableModalClose = document.getElementById('move-table-modal-close');
    const moveTableCancel = document.getElementById('move-table-cancel');
    const moveTableForm = document.getElementById('move-table-form');
    const moveTableSelect = document.getElementById('move-table-select');
    const moveTableModalOrder = document.getElementById('move-table-modal-order');
    const moveTableCurrent = document.getElementById('move-table-current');
    const moveTableSelectedStatus = document.getElementById('move-table-selected-status');
    let searchTimer;
    let isFetchingOrders = false;
    const ORDERS_DEBOUNCE = 500;

    function fetchOrders(url) {
        if (isFetchingOrders) return;
        isFetchingOrders = true;
        ordersTable?.classList.add('opacity-60');

        fetch(url, {
                headers: {
                    'X-Requested-With': 'XMLHttpRequest'
                }
            })
            .then((res) => res.text())
            .then((html) => {
                const parser = new DOMParser();
                const doc = parser.parseFromString(html, 'text/html');
                const newTable = doc.querySelector('#orders-table');
                const newPagination = doc.querySelector('#orders-pagination');
                const newFilters = doc.querySelector('#orders-filters');

                if (newTable && ordersTable) ordersTable.innerHTML = newTable.innerHTML;
                if (newPagination && ordersPagination) ordersPagination.innerHTML = newPagination.innerHTML;
                if (newFilters) document.getElementById('orders-filters').innerHTML = newFilters.innerHTML;

                rebindOrdersLinks();
                window.history.replaceState({}, '', url);
            })
            .finally(() => {
                ordersTable?.classList.remove('opacity-60');
                isFetchingOrders = false;
            });
    }

    function updateSearchQuery(value) {
        const url = new URL(window.location.href);
        if (value) {
            url.searchParams.set('q', value);
        } else {
            url.searchParams.delete('q');
        }
        url.searchParams.set('page', '1');
        fetchOrders(url.toString());
    }

    ordersSearch?.addEventListener('input', () => {
        const value = ordersSearch.value.trim();
        clearTimeout(searchTimer);
        searchTimer = setTimeout(() => {
            updateSearchQuery(value);
        }, ORDERS_DEBOUNCE);
    });

    function rebindOrdersLinks() {
        document.querySelectorAll('#orders-pagination a').forEach((link) => {
            link.addEventListener('click', (event) => {
                event.preventDefault();
                fetchOrders(link.href);
            });
        });
        document.querySelectorAll('#orders-filters a').forEach((link) => {
            link.addEventListener('click', (event) => {
                event.preventDefault();
                const url = new URL(link.href);
                url.searchParams.set('page', '1');
                fetchOrders(url.toString());
            });
        });
    }

    function showOrderToast(message) {
        const toast = document.createElement('div');
        toast.className = 'fixed right-6 top-20 z-50 flex items-center gap-3 rounded-xl bg-slate-900 px-4 py-3 text-sm text-white shadow-lg';
        toast.innerHTML = `
                <span class="inline-flex h-8 w-8 items-center justify-center rounded-full bg-emerald-500/20 text-emerald-200">
                    <svg class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                        <path d="M16.707 5.293a1 1 0 0 1 0 1.414l-8 8a1 1 0 0 1-1.414 0l-4-4a1 1 0 0 1 1.414-1.414L8 12.586l7.293-7.293a1 1 0 0 1 1.414 0Z"/>
                    </svg>
                </span>
                <div>${message}</div>
            `;
        document.body.appendChild(toast);
        setTimeout(() => toast.remove(), 2400);
    }

    function closeMoveTableModal() {
        if (!moveTableModal) return;
        moveTableModal.classList.add('hidden');
        moveTableModal.classList.remove('flex');
    }

    function buildTableStatusBadge(status, text) {
        const isOccupied = status === 'occupied';
        const cls = isOccupied ?
            'bg-rose-100 text-rose-700' :
            'bg-emerald-100 text-emerald-700';
        return `<span class="inline-flex items-center rounded-full px-2 py-0.5 font-semibold ${cls}">${text}</span>`;
    }

    function updateSelectedTableStatus() {
        if (!moveTableSelect || !moveTableSelectedStatus) return;
        const selected = moveTableSelect.options[moveTableSelect.selectedIndex];
        if (!selected || !selected.value) {
            moveTableSelectedStatus.innerHTML = '';
            return;
        }

        const status = selected.dataset.status || 'empty';
        const label = selected.dataset.label || selected.textContent || '-';
        moveTableSelectedStatus.innerHTML = `Status ${label}: ${buildTableStatusBadge(status, status === 'occupied' ? 'Terisi' : 'Kosong')}`;
    }

    function openMoveTableModal(button) {
        if (!moveTableModal || !moveTableForm || !moveTableSelect) return;

        const orderId = button.dataset.orderId;
        const orderNo = button.dataset.orderNo || '-';
        const currentMejaId = Number(button.dataset.currentMejaId || 0);
        const currentMejaNo = button.dataset.currentMejaNo || '-';

        moveTableForm.action = `<?php echo e(url('/orders')); ?>/${orderId}/move-table`;
        moveTableModalOrder.textContent = `Order: ${orderNo}`;
        moveTableCurrent.innerHTML = `Meja saat ini: <span class="font-semibold text-slate-700">${currentMejaNo}</span> ${buildTableStatusBadge('occupied', 'Terisi')}`;

        Array.from(moveTableSelect.options).forEach((option) => {
            if (!option.value) {
                return;
            }

            const occupiedBy = Number(option.dataset.occupiedBy || 0);
            const occupiedByOtherOrder = occupiedBy > 0 && occupiedBy !== Number(orderId);
            option.disabled = occupiedByOtherOrder;

            const baseLabel = option.dataset.label || option.textContent;
            if (occupiedByOtherOrder) {
                option.textContent = `${baseLabel} (Terisi)`;
            } else if (Number(option.value) === currentMejaId) {
                option.textContent = `${baseLabel} (Saat ini)`;
            } else {
                option.textContent = baseLabel;
            }
        });

        moveTableSelect.value = currentMejaId > 0 ? String(currentMejaId) : '';
        updateSelectedTableStatus();
        moveTableModal.classList.remove('hidden');
        moveTableModal.classList.add('flex');
    }

    window.addEventListener('orders-realtime', (event) => {
        clearTimeout(ordersReloadTimer);
        const orderNo = event.detail?.order_no ? ` (${event.detail.order_no})` : '';
        const message = event.detail?.status === 'open' ?
            `Order baru masuk${orderNo}.` :
            `Order diperbarui${orderNo}.`;
        showOrderToast(message);
        ordersReloadTimer = setTimeout(() => {
            const url = new URL(window.location.href);
            fetchOrders(url.toString());
        }, 1200);
    });

    if (userRole === 'cashier') {
        document.addEventListener('click', (event) => {
            const trigger = event.target.closest('.open-move-table-modal');
            if (trigger) {
                event.preventDefault();
                openMoveTableModal(trigger);
            }
        });

        moveTableModalClose?.addEventListener('click', closeMoveTableModal);
        moveTableCancel?.addEventListener('click', closeMoveTableModal);
        moveTableModal?.addEventListener('click', (event) => {
            if (event.target === moveTableModal) {
                closeMoveTableModal();
            }
        });
        moveTableSelect?.addEventListener('change', updateSelectedTableStatus);
    }

    rebindOrdersLinks();
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\foodcourt\resources\views/orders/all.blade.php ENDPATH**/ ?>