

<?php $__env->startSection('content'); ?>
    <?php
        $role = auth()->user()?->role?->nama_roles;
        $canManage = in_array($role, ['admin', 'cashier', 'supervisor', 'waiter'], true)
            || (int) $order->created_by === (int) auth()->id();
        $menuType = request('menu_type');
        $baseMenuQuery = collect(request()->query())->except('menu_type')->all();
        $isClosedGrid = in_array($role, ['admin', 'cashier', 'supervisor'], true)
            && $order->status === 'closed';
        $showAddForm = $canManage && $order->status === 'open';
        $itemsColClass = $showAddForm ? 'lg:col-span-4' : 'lg:col-span-12';
    ?>

    <div class="space-y-6">
        <?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="flex flex-wrap items-center justify-between gap-4">
                <div>
                    <h2 class="text-2xl font-semibold text-slate-900">Order <?php echo e($order->order_no); ?></h2>
                    <p class="text-sm text-slate-500"><?php echo e($order->tanggal->format('d-m-Y H:i')); ?> - <?php echo e($order->type); ?> - Meja <?php echo e($order->meja?->no_meja ?? '-'); ?></p>
                </div>
                <div class="text-right">
                    <?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; ?>
                    <?php
                        $orderTotal = $order->grand_total_after_discount ?? $order->grand_total;
                    ?>
                    <p class="mt-2 text-lg font-semibold text-slate-900"><?php echo e(format_rupiah($orderTotal)); ?></p>
                    <?php if(($order->discount_amount ?? 0) > 0): ?>
                        <p class="mt-1 text-xs text-slate-500">
                            Total sebelum diskon: <?php echo e(format_rupiah($order->grand_total)); ?>

                        </p>
                        <p class="mt-1 text-xs text-amber-700">
                            Diskon <?php echo e($order->discount_name ? '(' . $order->discount_name . ')' : ''); ?>:
                            -<?php echo e(format_rupiah($order->discount_amount)); ?>

                        </p>
                    <?php endif; ?>
                    <?php if($role === 'cashier' && $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' => ['type' => 'button','id' => 'open-close-modal','class' => 'mt-2 w-full']] + (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','id' => 'open-close-modal','class' => 'mt-2 w-full']); ?>Close 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 endif; ?>
                    <div class="mt-2 flex flex-col 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','id' => 'print-bt-btn','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(['type' => 'button','id' => 'print-bt-btn','variant' => 'secondary']); ?>Print Bluetooth <?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' => 'button','id' => 'print-stand-btn']] + (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','id' => 'print-stand-btn']); ?>Print Stand <?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>
                </div>
            </div>

            <div class="mt-4 flex flex-wrap gap-6 text-sm text-slate-600">
                <div>Waiter: <span class="font-semibold text-slate-800"><?php echo e($order->waiter?->nama ?? '-'); ?></span></div>
                <div>Pelanggan: <span class="font-semibold text-slate-800"><?php echo e($order->nama_pelanggan ?? '-'); ?></span></div>
                <?php if($order->status === 'closed'): ?>
                    <?php
                        $paidAtDisplay = '-';
                        if ($order->updated_at) {
                            $paidAtDisplay = \Illuminate\Support\Carbon::parse($order->updated_at)->format('d-m-Y H:i');
                        }
                    ?>
                    <div>
                        Waktu Bayar: <span class="font-semibold text-slate-800"><?php echo e($paidAtDisplay); ?></span>
                    </div>
                    <div>
                        Pembayaran: <span class="font-semibold text-slate-800"><?php echo e(strtoupper($order->tipe_pembayaran ?? '-')); ?></span>
                        <?php if(($order->tipe_pembayaran ?? '') !== 'cash' && $order->no_transaksi_pembayaran): ?>
                            <span class="text-xs text-slate-500">(<?php echo e($order->no_transaksi_pembayaran); ?>)</span>
                        <?php endif; ?>
                    </div>
                    <?php if(($order->discount_amount ?? 0) > 0): ?>
                        <div>
                            Discount: <span class="font-semibold text-slate-800">
                                <?php echo e($order->discount_name ?? 'Diskon'); ?>

                            </span>
                            <span class="text-xs text-slate-500">(-<?php echo e(format_rupiah($order->discount_amount)); ?>)</span>
                        </div>
                        <div>
                            Total Setelah Diskon:
                            <span class="font-semibold text-slate-800"><?php echo e(format_rupiah($order->grand_total_after_discount ?? $order->grand_total)); ?></span>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
            </div>

            <?php if($order->status === 'open' && $order->type === 'dine_in'): ?>
                <div class="mt-4 rounded-lg border border-slate-200 bg-slate-50 p-4">
                    <div class="flex flex-wrap items-center justify-between gap-4">
                        <div>
                            <p class="text-sm font-semibold text-slate-700">Pindah Meja</p>
                            <p class="text-xs text-slate-500">Pilih meja kosong untuk memindahkan order.</p>
                            <div class="mt-2 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>
                        </div>
                        <form method="post" action="<?php echo e(route('orders.move_table', $order)); ?>" class="flex flex-wrap items-end gap-3">
                            <?php echo csrf_field(); ?>
                            <div class="min-w-[180px]">
                                <?php if (isset($component)) { $__componentOriginaled2cde6083938c436304f332ba96bb7c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginaled2cde6083938c436304f332ba96bb7c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.select','data' => ['name' => 'id_meja','label' => 'Meja','id' => 'move-meja-select']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('select'); ?>
<?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(['name' => 'id_meja','label' => 'Meja','id' => 'move-meja-select']); ?>
                                    <option value="">Pilih Meja</option>
                                    <?php $__currentLoopData = $mejas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $meja): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $isCurrentTable = (int) $order->id_meja === (int) $meja->id;
                                            $isOccupiedByOther = (bool) $meja->is_occupied;
                                            $isOccupied = $isCurrentTable || $isOccupiedByOther;
                                        ?>
                                        <option
                                            value="<?php echo e($meja->id); ?>"
                                            data-label="<?php echo e($meja->no_meja); ?>"
                                            data-status="<?php echo e($isOccupied ? 'occupied' : 'empty'); ?>"
                                            <?php echo e((int) $order->id_meja === (int) $meja->id ? 'selected' : ''); ?>

                                            <?php echo e($isOccupiedByOther ? 'disabled' : ''); ?>

                                        >
                                            <?php echo e($meja->no_meja); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginaled2cde6083938c436304f332ba96bb7c)): ?>
<?php $attributes = $__attributesOriginaled2cde6083938c436304f332ba96bb7c; ?>
<?php unset($__attributesOriginaled2cde6083938c436304f332ba96bb7c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginaled2cde6083938c436304f332ba96bb7c)): ?>
<?php $component = $__componentOriginaled2cde6083938c436304f332ba96bb7c; ?>
<?php unset($__componentOriginaled2cde6083938c436304f332ba96bb7c); ?>
<?php endif; ?>
                                <p class="mt-1 text-xs text-slate-500">
                                    Meja saat ini:
                                    <span class="font-semibold text-slate-700"><?php echo e($order->meja?->no_meja ?? '-'); ?></span>
                                    <span class="inline-flex items-center rounded-full bg-rose-100 px-2 py-0.5 font-semibold text-rose-700">Terisi</span>
                                </p>
                                <p id="show-move-meja-status" class="mt-1 text-xs text-slate-500"></p>
                            </div>
                            <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'submit','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(['type' => 'submit','variant' => 'secondary']); ?>Pindah <?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; ?>
                        </form>
                    </div>
                </div>
            <?php endif; ?>
         <?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; ?>

        <div class="grid gap-6 lg:grid-cols-12">
            <?php if($showAddForm): ?>
                <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => ['class' => 'flex flex-col gap-4 lg:col-span-8']] + (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(['class' => 'flex flex-col gap-4 lg:col-span-8']); ?>
                    <h3 class="text-lg font-semibold text-slate-900">Tambah Item</h3>
                    <form method="post" action="<?php echo e(route('orders.items.store', $order)); ?>" class="flex flex-col gap-4" id="add-items-form">
                        <?php echo csrf_field(); ?>
                        <div class="flex flex-wrap items-center gap-3">
                            <input id="add-menu-search" type="text" class="w-full rounded-lg border border-slate-200 px-3 py-2 text-sm" placeholder="Cari menu..." value="<?php echo e(request('q')); ?>">
                            <div id="add-menu-filters" class="flex flex-wrap items-center gap-2 text-xs">
                                <a href="<?php echo e(route('orders.show', [$order, ...$baseMenuQuery])); ?>"
                                   class="rounded-full border px-3 py-1 font-semibold <?php echo e($menuType ? 'border-slate-200 text-slate-500 hover:bg-slate-100' : 'border-slate-900 bg-slate-900 text-white'); ?>">
                                    Semua
                                </a>
                                <?php $__currentLoopData = ['makanan' => 'Makanan', 'minuman' => 'Minuman', 'snack' => 'Snack']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <a href="<?php echo e(route('orders.show', [$order, ...array_merge($baseMenuQuery, ['menu_type' => $key])])); ?>"
                                       class="rounded-full border px-3 py-1 font-semibold <?php echo e($menuType === $key ? 'border-slate-900 bg-slate-900 text-white' : 'border-slate-200 text-slate-500 hover:bg-slate-100'); ?>">
                                        <?php echo e($label); ?>

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

                        <div id="add-menu-grid" class="grid max-h-[36vh] gap-3 overflow-y-auto pr-1 sm:grid-cols-2">
                            <?php $__currentLoopData = $menus; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $menu): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <button
                                    type="button"
                                    class="flex gap-3 rounded-xl border border-slate-200 bg-white p-3 text-left transition hover:border-slate-300 hover:shadow-sm"
                                    data-id="<?php echo e($menu->id); ?>"
                                    data-name="<?php echo e($menu->nama); ?>"
                                    data-price="<?php echo e($menu->harga_jual); ?>"
                                    data-type="<?php echo e($menu->type_menu); ?>"
                                    data-stand="<?php echo e($menu->stand?->nama); ?>"
                                >
                                    <div class="h-16 w-16 flex-shrink-0 overflow-hidden rounded-lg bg-slate-100">
                                        <?php if($menu->image): ?>
                                            <img src="<?php echo e(asset('storage/' . $menu->image)); ?>" alt="<?php echo e($menu->nama); ?>" class="h-full w-full object-cover">
                                        <?php else: ?>
                                            <div class="flex h-full w-full items-center justify-center text-xs text-slate-400">No Image</div>
                                        <?php endif; ?>
                                    </div>
                                    <div class="flex-1">
                                        <p class="text-sm font-semibold text-slate-900"><?php echo e($menu->nama); ?></p>
                                        <p class="text-xs text-slate-500"><?php echo e(ucfirst($menu->type_menu)); ?></p>
                                        <p class="mt-2 text-sm font-semibold text-slate-700"><?php echo e(format_rupiah($menu->harga_jual)); ?></p>
                                    </div>
                                </button>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                        <div class="flex items-center justify-center" id="add-menu-pagination">
                            <?php echo e($menus->links()); ?>

                        </div>

                        <div class="overflow-visible">
                            <?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">Menu</th>
                                        <th class="px-4 py-3 text-right">Qty</th>
                                        <th class="px-4 py-3 text-right">Harga</th>
                                        <th class="px-4 py-3 text-right">Subtotal</th>
                                        <th class="px-4 py-3">Note</th>
                                        <th class="px-4 py-3 text-right"></th>
                                    </tr>
                                </thead>
                                <tbody id="add-cart-body">
                                    <tr>
                                        <td class="px-4 py-6 text-center text-slate-500" colspan="6">Belum ada item.</td>
                                    </tr>
                                </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="add-items-inputs"></div>
                        <input type="hidden" name="redirect_to" value="all">

                        <div class="flex justify-end gap-3">
                            <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'button','id' => 'open-add-print-modal']] + (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','id' => 'open-add-print-modal']); ?>Simpan Item <?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>
                 <?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 endif; ?>

            <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => ['class' => $itemsColClass]] + (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(['class' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($itemsColClass)]); ?>
                <div class="mb-4 flex items-center justify-between">
                    <h3 class="text-lg font-semibold text-slate-900">Items</h3>
                </div>
                <div class="<?php echo e($isClosedGrid ? 'grid gap-3 sm:grid-cols-2 lg:grid-cols-3' : 'space-y-3'); ?>">
                    <?php $__empty_1 = true; $__currentLoopData = $order->details->filter(function ($detail) use ($role) {
                        $isCanceled = ($detail->status ?? 'active') === 'canceled';
                        return $role === 'admin' || ! $isCanceled;
                    }); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $isCanceled = ($detail->status ?? 'active') === 'canceled';
                        ?>
                        <div class="w-full rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
                            <div class="flex items-center justify-between">
                                <div class="text-sm font-semibold <?php echo e($isCanceled ? 'text-slate-400 line-through' : 'text-slate-900'); ?>">
                                    <?php echo e($detail->menu?->nama); ?>

                                </div>
                                <?php if($isCanceled): ?>
                                    <?php if (isset($component)) { $__componentOriginal2ddbc40e602c342e508ac696e52f8719 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2ddbc40e602c342e508ac696e52f8719 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.badge','data' => ['variant' => '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' => 'danger']); ?>Canceled <?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; ?>
                                <?php else: ?>
                                    <?php if (isset($component)) { $__componentOriginal2ddbc40e602c342e508ac696e52f8719 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2ddbc40e602c342e508ac696e52f8719 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.badge','data' => ['variant' => 'info']] + (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' => 'info']); ?>Qty <?php echo e($detail->qty); ?> <?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; ?>
                                <?php endif; ?>
                            </div>
                            <div class="mt-3 grid gap-2 text-sm text-slate-600">
                                <div class="flex items-center justify-between">
                                    <span>Harga</span>
                                    <span class="font-semibold text-slate-800"><?php echo e(format_rupiah($detail->harga)); ?></span>
                                </div>
                                <div class="flex items-center justify-between">
                                    <span>Line Total</span>
                                    <span class="font-semibold text-slate-800"><?php echo e(format_rupiah($detail->line_total)); ?></span>
                                </div>
                                <div class="text-xs text-slate-500">Note: <?php echo e($detail->note ?? '-'); ?></div>
                            </div>
                            <?php if(! $isCanceled && in_array($role, ['supervisor', 'waiter'], true) && $order->status === 'open'): ?>
                                <form method="post" action="<?php echo e(route('orders.items.update_qty', [$order, $detail])); ?>" class="mt-3 flex items-center gap-2">
                                    <?php echo csrf_field(); ?>
                                    <input type="number" name="qty" min="1" value="<?php echo e($detail->qty); ?>"
                                           class="w-20 rounded-lg border border-slate-200 px-2 py-1 text-sm">
                                    <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'submit','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(['type' => 'submit','variant' => 'secondary']); ?>Update Qty <?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; ?>
                                </form>
                            <?php endif; ?>
                            <?php if(! $isCanceled && in_array($role, ['supervisor', 'waiter'], true) && $order->status === 'open'): ?>
                                <form method="post" action="<?php echo e(route('orders.items.cancel', [$order, $detail])); ?>" class="mt-3">
                                    <?php echo csrf_field(); ?>
                                    <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['type' => 'submit','variant' => 'danger','class' => 'w-full','onclick' => 'return confirm(\'Batalkan item ini?\')']] + (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','variant' => 'danger','class' => 'w-full','onclick' => 'return confirm(\'Batalkan item ini?\')']); ?>
                                        Cancel Item
                                     <?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; ?>
                                </form>
                            <?php elseif($isCanceled): ?>
                                <div class="mt-2 text-xs text-slate-500">
                                    Dibatalkan <?php echo e($detail->canceled_at ? 'pada ' . $detail->canceled_at->format('d-m-Y H:i') : ''); ?>

                                </div>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <div class="rounded-lg border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-500">
                            Tidak ada item aktif.
                        </div>
                    <?php endif; ?>
                </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; ?>
        </div>

        <div class="flex flex-wrap items-center gap-3">
            <?php if($role === 'admin' && $order->status === 'open'): ?>
                <form method="post" action="<?php echo e(route('orders.cancel', $order)); ?>">
                    <?php echo csrf_field(); ?>
                    <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['variant' => 'danger','type' => 'submit','onclick' => 'return confirm(\'Batalkan 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' => 'danger','type' => 'submit','onclick' => 'return confirm(\'Batalkan order?\')']); ?>Cancel 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; ?>
                </form>
            <?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(in_array($role, ['admin', 'cashier'], true) ? route('orders.all') : route('orders.index')).'','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(in_array($role, ['admin', 'cashier'], true) ? route('orders.all') : route('orders.index')).'','variant' => 'secondary']); ?>Kembali <?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>
    </div>

        <?php if($role === 'cashier' && $order->status === 'open'): ?>
        <div id="close-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">Close Order</h3>
                    <button type="button" id="close-modal-btn" class="text-slate-400 hover:text-slate-600">&times;</button>
                </div>
                <form method="post" action="<?php echo e(route('orders.close', $order)); ?>" class="mt-4 grid gap-4" id="close-order-form" data-print-url="<?php echo e(route('orders.print', $order)); ?>">
                    <?php echo csrf_field(); ?>
                    <?php if (isset($component)) { $__componentOriginaled2cde6083938c436304f332ba96bb7c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginaled2cde6083938c436304f332ba96bb7c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.select','data' => ['name' => 'tipe_pembayaran','label' => 'Tipe Pembayaran','required' => true,'id' => 'close-payment-type']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('select'); ?>
<?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(['name' => 'tipe_pembayaran','label' => 'Tipe Pembayaran','required' => true,'id' => 'close-payment-type']); ?>
                        <option value="">Pilih</option>
                        <?php $__currentLoopData = ['cash' => 'Cash', 'transfer' => 'Transfer', 'qris' => 'QRIS']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($value); ?>" <?php echo e(old('tipe_pembayaran') === $value ? 'selected' : ''); ?>><?php echo e($label); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginaled2cde6083938c436304f332ba96bb7c)): ?>
<?php $attributes = $__attributesOriginaled2cde6083938c436304f332ba96bb7c; ?>
<?php unset($__attributesOriginaled2cde6083938c436304f332ba96bb7c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginaled2cde6083938c436304f332ba96bb7c)): ?>
<?php $component = $__componentOriginaled2cde6083938c436304f332ba96bb7c; ?>
<?php unset($__componentOriginaled2cde6083938c436304f332ba96bb7c); ?>
<?php endif; ?>
                    <div id="close-bank-field" class="hidden">
                        <?php if (isset($component)) { $__componentOriginaled2cde6083938c436304f332ba96bb7c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginaled2cde6083938c436304f332ba96bb7c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.select','data' => ['name' => 'bank_account_id','label' => 'Akun Bank']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('select'); ?>
<?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(['name' => 'bank_account_id','label' => 'Akun Bank']); ?>
                            <option value="">Pilih Akun Bank</option>
                            <?php $__currentLoopData = $bankAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($bank->id); ?>" <?php echo e(old('bank_account_id') == $bank->id ? 'selected' : ''); ?>>
                                    <?php echo e($bank->bank_name); ?> - <?php echo e($bank->account_name); ?> (<?php echo e($bank->account_number); ?>)
                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                         <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginaled2cde6083938c436304f332ba96bb7c)): ?>
<?php $attributes = $__attributesOriginaled2cde6083938c436304f332ba96bb7c; ?>
<?php unset($__attributesOriginaled2cde6083938c436304f332ba96bb7c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginaled2cde6083938c436304f332ba96bb7c)): ?>
<?php $component = $__componentOriginaled2cde6083938c436304f332ba96bb7c; ?>
<?php unset($__componentOriginaled2cde6083938c436304f332ba96bb7c); ?>
<?php endif; ?>
                    </div>
                    <?php if (isset($component)) { $__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input','data' => ['name' => 'no_transaksi_pembayaran','label' => 'No Transaksi Pembayaran','value' => old('no_transaksi_pembayaran')]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('input'); ?>
<?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(['name' => 'no_transaksi_pembayaran','label' => 'No Transaksi Pembayaran','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(old('no_transaksi_pembayaran'))]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1)): ?>
<?php $attributes = $__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1; ?>
<?php unset($__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1)): ?>
<?php $component = $__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1; ?>
<?php unset($__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1); ?>
<?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']); ?>Konfirmasi Close <?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; ?>
                </form>
            </div>
        </div>
    <?php endif; ?>

    <?php if($canManage && $order->status === 'open'): ?>
                <div id="add-print-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">Cetak Tambahan</h3>
                    <button type="button" id="close-add-print-modal" class="text-slate-400 hover:text-slate-600">&times;</button>
                </div>
                <div class="mt-4 flex items-center gap-3 rounded-xl border border-slate-200 bg-slate-50 px-4 py-3">
                    <span id="add-print-step-badge" class="inline-flex h-6 w-6 items-center justify-center rounded-full bg-slate-900 text-xs text-white">1</span>
                    <div>
                        <p id="add-print-step-title" class="text-sm font-semibold text-slate-900">Print Bluetooth</p>
                        <p class="text-xs text-slate-500">Cetak untuk pelanggan terlebih dahulu</p>
                    </div>
                </div>
                <button type="button" id="add-print-main-button" class="mt-5 flex h-28 w-full flex-col items-center justify-center gap-2 rounded-2xl border border-slate-200 bg-white text-sm font-semibold text-slate-800 shadow-sm hover:bg-slate-50">
                    <span class="text-base" id="add-print-main-title">Mulai Print Bluetooth</span>
                    <span class="text-xs text-slate-500" id="add-print-main-desc">Cetak via perangkat tablet</span>
                </button>
                <button type="button" id="add-print-prev" class="mt-4 hidden w-full rounded-lg border border-slate-200 px-4 py-2 text-sm font-semibold text-slate-600 hover:bg-slate-50">Kembali ke Bluetooth</button>
                <div class="mt-6 flex justify-end gap-3">
                    <button type="button" id="confirm-add-print" class="rounded-lg bg-slate-300 px-4 py-2 text-sm font-semibold text-white" disabled>OK</button>
                </div>
            </div>
        </div>

        <div id="add-note-modal" class="fixed inset-0 z-50 hidden items-center justify-center bg-slate-900/60 p-4">
            <div class="w-full max-w-lg rounded-xl bg-white p-6 shadow-lg">
                <div class="flex items-center justify-between">
                    <h3 class="text-lg font-semibold text-slate-900">Catatan Item</h3>
                    <button type="button" id="close-add-note" class="text-slate-400 hover:text-slate-600">&times;</button>
                </div>
                <textarea id="add-note-textarea" rows="5" class="mt-4 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700" placeholder="Tulis catatan untuk item..."></textarea>
                <div class="mt-4 flex justify-end gap-3">
                    <?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' => 'close-add-note-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(['type' => 'button','variant' => 'secondary','id' => 'close-add-note-secondary']); ?>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' => 'button','id' => 'save-add-note']] + (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','id' => 'save-add-note']); ?>Simpan <?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>
            </div>
        </div>

        <script>
            const addMenuSearch = document.getElementById('add-menu-search');
            const addMenuGrid = document.getElementById('add-menu-grid');
            const addCartBody = document.getElementById('add-cart-body');
            const addItemsInputs = document.getElementById('add-items-inputs');
            const addItemsForm = document.getElementById('add-items-form');
            const openAddPrintModal = document.getElementById('open-add-print-modal');
            const addPrintModal = document.getElementById('add-print-modal');
            const closeAddPrintModal = document.getElementById('close-add-print-modal');
            const addPrintMainButton = document.getElementById('add-print-main-button');
            const addPrintStepBadge = document.getElementById('add-print-step-badge');
            const addPrintStepTitle = document.getElementById('add-print-step-title');
            const addPrintPrev = document.getElementById('add-print-prev');
            const confirmAddPrint = document.getElementById('confirm-add-print');
            const addNoteModal = document.getElementById('add-note-modal');
            const addNoteTextarea = document.getElementById('add-note-textarea');
            const saveAddNote = document.getElementById('save-add-note');
            const closeAddNote = document.getElementById('close-add-note');
            const closeAddNoteSecondary = document.getElementById('close-add-note-secondary');
            let currentAddNoteIndex = null;

            const addItems = [];
            const orderType = <?php echo json_encode($order->type, 15, 512) ?>;
            const orderMeja = <?php echo json_encode($order->meja?->no_meja, 15, 512) ?>;
            const orderPelanggan = <?php echo json_encode($order->nama_pelanggan, 15, 512) ?>;
            const orderWaiter = <?php echo json_encode($order->waiter?->nama, 15, 512) ?>;

            function formatRupiah(value) {
                return new Intl.NumberFormat('id-ID', {
                    style: 'currency',
                    currency: 'IDR',
                    minimumFractionDigits: 0,
                }).format(value);
            }

            function appendHiddenInput(name, value) {
                const input = document.createElement('input');
                input.type = 'hidden';
                input.name = name;
                input.value = value;
                addItemsInputs.appendChild(input);
            }

            function renderAddCart() {
                addCartBody.innerHTML = '';
                addItemsInputs.innerHTML = '';

                if (addItems.length === 0) {
                    addCartBody.innerHTML = `<tr><td class="px-4 py-6 text-center text-slate-500" colspan="6">Belum ada item.</td></tr>`;
                    return;
                }

                addItems.forEach((item, index) => {
                    const subtotal = item.qty * item.harga;
                    const row = document.createElement('tr');
                    row.className = 'border-b border-slate-100';
                    row.innerHTML = `
                        <td class="px-4 py-3 font-medium text-slate-800">${item.nama}</td>
                        <td class="px-4 py-3 text-right">
                            <div class="inline-flex items-center rounded-lg border border-slate-200">
                                <button type="button" data-index="${index}" data-action="decrease" class="px-3 py-1 text-slate-600 hover:bg-slate-100">-</button>
                                <input type="number" min="1" value="${item.qty}" data-index="${index}" class="qty-input w-14 border-x border-slate-200 px-2 py-1 text-center text-sm">
                                <button type="button" data-index="${index}" data-action="increase" class="px-3 py-1 text-slate-600 hover:bg-slate-100">+</button>
                            </div>
                        </td>
                        <td class="px-4 py-3 text-right">${formatRupiah(item.harga)}</td>
                        <td class="px-4 py-3 text-right">${formatRupiah(subtotal)}</td>
                        <td class="px-4 py-3">
                            <button type="button" data-index="${index}" class="add-note-btn inline-flex w-full items-center justify-between rounded-lg border border-slate-200 bg-white px-2 py-1 text-left text-sm text-slate-600 hover:bg-slate-50">
                                <span class="truncate">${item.note ? item.note : 'Tambah catatan'}</span>
                            </button>
                        </td>
                        <td class="px-4 py-3 text-right">
                            <button type="button" data-index="${index}" data-action="remove" class="text-rose-600 hover:text-rose-700">Hapus</button>
                        </td>
                    `;
                    addCartBody.appendChild(row);

                    appendHiddenInput(`items[${index}][id_menu]`, item.id);
                    appendHiddenInput(`items[${index}][qty]`, item.qty);
                    appendHiddenInput(`items[${index}][note]`, item.note);
                });
            }

            addMenuGrid.addEventListener('click', (event) => {
                const button = event.target.closest('button[data-id]');
                if (!button) return;

                const id = button.dataset.id;
                const existing = addItems.find((item) => item.id === id);
                if (existing) {
                    existing.qty += 1;
                    renderAddCart();
                    return;
                }

                addItems.push({
                    id,
                    nama: button.dataset.name,
                    harga: parseFloat(button.dataset.price || 0),
                    qty: 1,
                    note: '',
                    type_menu: button.dataset.type || null,
                    stand: button.dataset.stand || null,
                });
                renderAddCart();
            });

            addCartBody.addEventListener('click', (event) => {
                const button = event.target.closest('button');
                if (!button) {
                    return;
                }
                const index = button.dataset.index;
                if (button.dataset.action === 'increase') {
                    addItems[index].qty += 1;
                    renderAddCart();
                    return;
                }
                if (button.dataset.action === 'decrease') {
                    addItems[index].qty = Math.max(1, addItems[index].qty - 1);
                    renderAddCart();
                    return;
                }
                if (button.dataset.action === 'remove') {
                    addItems.splice(index, 1);
                    renderAddCart();
                }
            });

            addCartBody.addEventListener('input', (event) => {
                if (event.target.classList.contains('qty-input')) {
                    const index = event.target.dataset.index;
                    const qty = parseInt(event.target.value, 10) || 1;
                    addItems[index].qty = qty;
                    renderAddCart();
                }
            });

            addCartBody.addEventListener('click', (event) => {
                const noteButton = event.target.closest('.add-note-btn');
                if (!noteButton) {
                    return;
                }
                currentAddNoteIndex = noteButton.dataset.index;
                addNoteTextarea.value = addItems[currentAddNoteIndex]?.note ?? '';
                addNoteModal.classList.remove('hidden');
                addNoteModal.classList.add('flex');
                setTimeout(() => addNoteTextarea.focus(), 50);
            });

            function closeAddNoteModal() {
                addNoteModal.classList.add('hidden');
                addNoteModal.classList.remove('flex');
                currentAddNoteIndex = null;
            }

            saveAddNote?.addEventListener('click', () => {
                if (currentAddNoteIndex === null) {
                    return;
                }
                addItems[currentAddNoteIndex].note = addNoteTextarea.value.trim();
                renderAddCart();
                closeAddNoteModal();
            });

            closeAddNote?.addEventListener('click', closeAddNoteModal);
            closeAddNoteSecondary?.addEventListener('click', closeAddNoteModal);
            addNoteModal?.addEventListener('click', (event) => {
                if (event.target === addNoteModal) {
                    closeAddNoteModal();
                }
            });

            let addMenuSearchTimer;
            let isFetchingAddMenus = false;
            const ADD_SEARCH_DEBOUNCE = 700;

            async function fetchAddMenuPage(url) {
                if (isFetchingAddMenus) return;
                isFetchingAddMenus = true;
                addMenuGrid?.classList.add('opacity-60');
                try {
                    const response = await fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
                    if (!response.ok) throw new Error('Gagal memuat menu.');
                    const html = await response.text();
                    const parser = new DOMParser();
                    const doc = parser.parseFromString(html, 'text/html');
                    const newGrid = doc.querySelector('#add-menu-grid');
                    const newPagination = doc.querySelector('#add-menu-pagination');
                    const newFilters = doc.querySelector('#add-menu-filters');
                    if (newGrid && addMenuGrid) {
                        addMenuGrid.innerHTML = newGrid.innerHTML;
                    }
                    const paginationWrap = document.getElementById('add-menu-pagination');
                    if (paginationWrap && newPagination) {
                        paginationWrap.innerHTML = newPagination.innerHTML;
                    }
                    const currentFilters = document.getElementById('add-menu-filters');
                    if (currentFilters && newFilters) {
                        currentFilters.innerHTML = newFilters.innerHTML;
                    }
                    rebindAddMenuLinks();
                    window.history.replaceState({}, '', url);
                } catch (error) {
                    console.error(error);
                } finally {
                    addMenuGrid?.classList.remove('opacity-60');
                    isFetchingAddMenus = false;
                }
            }

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

            function debounceAddSearch(value) {
                clearTimeout(addMenuSearchTimer);
                addMenuSearchTimer = setTimeout(() => {
                    updateAddSearchQuery(value);
                }, ADD_SEARCH_DEBOUNCE);
            }

            addMenuSearch.addEventListener('input', () => {
                const value = addMenuSearch.value.trim();
                if (!value) {
                    debounceAddSearch('');
                    return;
                }
                if (value.length < 2) {
                    clearTimeout(addMenuSearchTimer);
                    return;
                }
                debounceAddSearch(value);
            });

            addMenuSearch.addEventListener('keydown', (event) => {
                if (event.key === 'Enter') {
                    event.preventDefault();
                    updateAddSearchQuery(addMenuSearch.value.trim());
                }
            });

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

            rebindAddMenuLinks();

            openAddPrintModal?.addEventListener('click', () => {
                if (addItems.length === 0) {
                    alert('Item tambahan belum ada.');
                    return;
                }
                doneAddPrints.clear();
                addPrintStep = 1;
                updateAddPrintStepUI();
                setConfirmAddState();
                addPrintModal.classList.remove('hidden');
                addPrintModal.classList.add('flex');
            });

            closeAddPrintModal?.addEventListener('click', () => {
                addPrintModal.classList.add('hidden');
                addPrintModal.classList.remove('flex');
            });

            addPrintModal?.addEventListener('click', (event) => {
                if (event.target === addPrintModal) {
                    addPrintModal.classList.add('hidden');
                    addPrintModal.classList.remove('flex');
                }
            });

            const doneAddPrints = new Set();
            let addPrintStep = 1;

            function setConfirmAddState() {
                const ready = doneAddPrints.size === 2;
                confirmAddPrint.disabled = !ready;
                confirmAddPrint.classList.toggle('bg-slate-300', !ready);
                confirmAddPrint.classList.toggle('bg-slate-900', ready);
                confirmAddPrint.classList.toggle('hover:bg-slate-800', ready);
            }

            function updateAddPrintStepUI() {
                if (!addPrintStepBadge || !addPrintStepTitle) return;
                const titleEl = document.getElementById('add-print-main-title');
                const descEl = document.getElementById('add-print-main-desc');
                if (addPrintStep === 1) {
                    addPrintStepBadge.textContent = '1';
                    addPrintStepBadge.className = 'inline-flex h-6 w-6 items-center justify-center rounded-full bg-slate-900 text-xs text-white';
                    addPrintStepTitle.textContent = 'Print Bluetooth';
                    if (titleEl) titleEl.textContent = 'Mulai Print Bluetooth';
                    if (descEl) descEl.textContent = 'Cetak via perangkat tablet';
                    addPrintPrev?.classList.add('hidden');
                } else {
                    addPrintStepBadge.textContent = '2';
                    addPrintStepBadge.className = 'inline-flex h-6 w-6 items-center justify-center rounded-full bg-emerald-600 text-xs text-white';
                    addPrintStepTitle.textContent = 'Print Stand';
                    if (titleEl) titleEl.textContent = 'Mulai Print Stand';
                    if (descEl) descEl.textContent = 'Kirim ke printer stand';
                    addPrintPrev?.classList.remove('hidden');
                }
            }

            updateAddPrintStepUI();

            function openAddPrintPreview() {
                const typeLabel = orderType === 'dine_in' ? 'Dine In' : 'Take Away';
                const isDineIn = orderType === 'dine_in';
                const itemRows = addItems.map((item) => `
                    <div class="item">
                        <div class="item-row">
                            <span class="item-name">${item.nama}</span>
                            <span class="item-qty">x${item.qty}</span>
                        </div>
                        ${item.note ? `<div class="item-note">Catatan: ${item.note}</div>` : ''}
                    </div>
                `).join('');

                const html = `
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Print Preview</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
@page { size: 80mm auto; margin: 0; }
html, body { width: 80mm; height: fit-content; font-family: Arial, sans-serif; color: #111; overflow: hidden; }
.receipt { width: 80mm; display: inline-block; height: fit-content; padding: 0; margin: 0; }
.meta { font-size: 14px; margin: 0 0 6px 6px; }
.meta-row { display: grid; grid-template-columns: 18mm 2mm 1fr; }
.items { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.item { padding-bottom: 4px; }
.item-row { display: flex; justify-content: space-between; gap: 8px; }
.item-name { font-weight: 600; font-size: 14px; }
.item-qty { text-align: right; min-width: 24px; }
.item-note { margin-top: 2px; font-size: 11px; color: #555; }
.items, .item, .meta { page-break-inside: avoid; break-inside: avoid; }
</style>
</head>
<body>
<div class="receipt">
    <div class="meta">
        ${typeLabel ? `<div class="meta-row">${typeLabel}</div>` : ''}
        ${isDineIn
            ? `<div class="meta-row"><span>Meja</span><span>:</span><span>${orderMeja || '-'}</span></div>`
            : `<div class="meta-row"><span>Pelanggan</span><span>:</span><span>${orderPelanggan || '-'}</span></div>`
        }
        <div class="meta-row"><span>Waiter</span><span>:</span><span>${orderWaiter || '-'}</span></div>
    </div>
    <div class="items">
        ${itemRows}
    </div>
</div>
</body>
</html>`;
                const win = window.open('', '_blank');
                if (win) {
                    win.document.write(html);
                    win.document.close();
                    win.onload = () => win.print();
                    win.focus();
                }
            }

            function buildAddDraftPayload() {
                const grandTotal = addItems.reduce((sum, item) => sum + (item.qty * item.harga), 0);
                return {
                    header: {
                        type: orderType || null,
                        meja: orderType === 'dine_in' ? (orderMeja || null) : null,
                        waiter: orderWaiter || null,
                        nama_pelanggan: orderPelanggan || null,
                        grand_total: grandTotal,
                    },
                    items: addItems.map((item) => ({
                        nama: item.nama,
                        qty: item.qty,
                        harga: item.harga,
                        note: item.note,
                        type_menu: item.type_menu || null,
                        stand: item.stand || 'General',
                    })),
                };
            }

            async function triggerAddPrintStandDraft() {
                const response = await fetch('/api/print/order/draft', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                    },
                    body: JSON.stringify(buildAddDraftPayload()),
                });
                if (!response.ok) {
                    throw new Error('Gagal mengirim ke printer stand.');
                }
                return response.json();
            }

            function setAddPrintLoading(loading) {
                if (!addPrintMainButton) return;
                if (loading) {
                    addPrintMainButton.disabled = true;
                    addPrintMainButton.classList.add('opacity-70');
                    addPrintMainButton.innerHTML = `
                        <svg class="h-5 w-5 animate-spin text-slate-500" viewBox="0 0 24 24" fill="none">
                            <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                            <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4Z"></path>
                        </svg>
                        <span class="text-xs text-slate-500">Memproses...</span>
                    `;
                    return;
                }
                addPrintMainButton.disabled = false;
                addPrintMainButton.classList.remove('opacity-70');
                addPrintMainButton.innerHTML = `
                    <span class="text-base" id="add-print-main-title">${addPrintStep === 1 ? 'Mulai Print Bluetooth' : 'Mulai Print Stand'}</span>
                    <span class="text-xs text-slate-500" id="add-print-main-desc">${addPrintStep === 1 ? 'Cetak via perangkat tablet' : 'Kirim ke printer stand'}</span>
                `;
            }

            addPrintMainButton?.addEventListener('click', async () => {
                if (addPrintStep === 1) {
                    openAddPrintPreview();
                    doneAddPrints.add('bluetooth');
                    addPrintStep = 2;
                    updateAddPrintStepUI();
                    setAddPrintLoading(false);
                    setConfirmAddState();
                    return;
                }
                if (doneAddPrints.has('stand')) {
                    return;
                }
                try {
                    setAddPrintLoading(true);
                    await triggerAddPrintStandDraft();
                    doneAddPrints.add('stand');
                    setAddPrintLoading(false);
                    setConfirmAddState();
                } catch (error) {
                    setAddPrintLoading(false);
                    alert(error.message || 'Gagal print stand.');
                }
            });

            addPrintPrev?.addEventListener('click', () => {
                addPrintStep = 1;
                updateAddPrintStepUI();
            });

            confirmAddPrint?.addEventListener('click', () => {
                if (confirmAddPrint.disabled) {
                    return;
                }
                addItemsForm.submit();
            });
        </script>
    <?php endif; ?>

    <?php if($role === 'cashier' && $order->status === 'open'): ?>
        <script>
            window.addEventListener('load', () => {
                const openCloseModal = document.getElementById('open-close-modal');
                const closeModal = document.getElementById('close-modal');
                const closeModalBtn = document.getElementById('close-modal-btn');
                const closeOrderForm = document.getElementById('close-order-form');
                const closePaymentType = document.getElementById('close-payment-type');
                const closeBankField = document.getElementById('close-bank-field');
                const closeBankSelect = closeBankField?.querySelector('select');

                openCloseModal?.addEventListener('click', () => {
                    closeModal.classList.remove('hidden');
                    closeModal.classList.add('flex');
                });

                closeModalBtn?.addEventListener('click', () => {
                    closeModal.classList.add('hidden');
                    closeModal.classList.remove('flex');
                });

                closeModal?.addEventListener('click', (event) => {
                    if (event.target === closeModal) {
                        closeModal.classList.add('hidden');
                        closeModal.classList.remove('flex');
                    }
                });

                function toggleCloseBankField() {
                    if (!closePaymentType || !closeBankField) return;
                    const isTransfer = closePaymentType.value === 'transfer';
                    closeBankField.classList.toggle('hidden', !isTransfer);
                    closeBankField.style.display = isTransfer ? 'block' : 'none';
                    if (closeBankSelect) {
                        closeBankSelect.required = isTransfer;
                    }
                }

                document.addEventListener('change', (event) => {
                    if (event.target && event.target.id === 'close-payment-type') {
                        toggleCloseBankField();
                    }
                });

                if (window.$ && $.fn.select2 && closePaymentType) {
                    $(closePaymentType).on('select2:select', toggleCloseBankField);
                }

                toggleCloseBankField();

                closeOrderForm?.addEventListener('submit', async (event) => {
                    event.preventDefault();
                    const printUrl = closeOrderForm.dataset.printUrl;
                    const submitButton = closeOrderForm.querySelector('button[type="submit"]');
                    submitButton?.setAttribute('disabled', 'disabled');

                    try {
                        const response = await fetch(closeOrderForm.action, {
                            method: 'POST',
                            headers: { 'X-Requested-With': 'XMLHttpRequest' },
                            body: new FormData(closeOrderForm),
                        });

                        if (!response.ok) {
                            submitButton?.removeAttribute('disabled');
                            return;
                        }

                        if (printUrl) {
                            const printWindow = window.open(`${printUrl}?t=${Date.now()}`, '_blank');
                            if (printWindow) {
                                printWindow.focus();
                            }
                        }

                        if (response.redirected) {
                            window.location.href = response.url;
                        } else {
                            window.location.reload();
                        }
                    } catch (error) {
                        submitButton?.removeAttribute('disabled');
                    }
                });
            });
        </script>
    <?php endif; ?>

    <?php
        $printItems = $order->details
            ->where('status', 'active')
            ->map(function ($detail) {
                return [
                    'nama' => $detail->menu?->nama,
                    'qty' => (int) $detail->qty,
                    'note' => $detail->note,
                ];
            })
            ->values();
    ?>

    <script>
        window.addEventListener('load', () => {
            const printBtBtn = document.getElementById('print-bt-btn');
            const printStandBtn = document.getElementById('print-stand-btn');
            const printStandUrl = <?php echo json_encode(url('/api/print/order/' . $order->id), 15, 512) ?>;
            const orderType = <?php echo json_encode($order->type, 15, 512) ?>;
            const orderMeja = <?php echo json_encode($order->meja?->no_meja, 15, 512) ?>;
            const orderPelanggan = <?php echo json_encode($order->nama_pelanggan, 15, 512) ?>;
            const orderWaiter = <?php echo json_encode($order->waiter?->nama, 15, 512) ?>;
            const orderItems = <?php echo json_encode($printItems, 15, 512) ?>;

            function openPrintPreview() {
                const typeLabel = orderType === 'dine_in' ? 'Dine In' : 'Take Away';
                const isDineIn = orderType === 'dine_in';
                const itemRows = (orderItems || []).map((item) => `
                    <div class="item">
                        <div class="item-row">
                            <span class="item-name">${item.nama || '-'}</span>
                            <span class="item-qty">x${item.qty}</span>
                        </div>
                        ${item.note ? `<div class="item-note">Catatan: ${item.note}</div>` : ''}
                    </div>
                `).join('');

                const html = `
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Print Preview</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
@page { size: 80mm auto; margin: 0; }
html, body { width: 80mm; height: fit-content; font-family: Arial, sans-serif; color: #111; overflow: hidden; }
.receipt { width: 80mm; display: inline-block; height: fit-content; padding: 0; margin: 0; }
.meta { font-size: 14px; margin: 0 0 6px 6px; }
.meta-row { display: grid; grid-template-columns: 18mm 2mm 1fr; }
.items { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.item { padding-bottom: 4px; }
.item-row { display: flex; justify-content: space-between; gap: 8px; }
.item-name { font-weight: 600; font-size: 14px; }
.item-qty { text-align: right; min-width: 24px; }
.item-note { margin-top: 2px; font-size: 11px; color: #555; }
.items, .item, .meta { page-break-inside: avoid; break-inside: avoid; }
</style>
</head>
<body>
<div class="receipt">
    <div class="meta">
        ${typeLabel ? `<div class="meta-row">${typeLabel}</div>` : ''}
        ${isDineIn
            ? `<div class="meta-row"><span>Meja</span><span>:</span><span>${orderMeja || '-'}</span></div>`
            : `<div class="meta-row"><span>Pelanggan</span><span>:</span><span>${orderPelanggan || '-'}</span></div>`
        }
        <div class="meta-row"><span>Waiter</span><span>:</span><span>${orderWaiter || '-'}</span></div>
    </div>
    <div class="items">
        ${itemRows}
    </div>
</div>
</body>
</html>`;

                const win = window.open('', '_blank');
                if (win) {
                    win.document.write(html);
                    win.document.close();
                    win.onload = () => win.print();
                    win.focus();
                }
            }

            printBtBtn?.addEventListener('click', () => {
                openPrintPreview();
            });

            function setStandButtonState(loading, success = false) {
                if (!printStandBtn) return;
                if (loading) {
                    printStandBtn.setAttribute('disabled', 'disabled');
                    printStandBtn.classList.add('opacity-70');
                    printStandBtn.textContent = 'Mengirim...';
                    return;
                }
                printStandBtn.removeAttribute('disabled');
                printStandBtn.classList.remove('opacity-70');
                printStandBtn.textContent = success ? 'Print Stand (OK)' : 'Print Stand';
                printStandBtn.classList.toggle('ring-2', success);
                printStandBtn.classList.toggle('ring-emerald-500', success);
                printStandBtn.classList.toggle('bg-emerald-50', success);
                printStandBtn.classList.toggle('border-emerald-300', success);
                printStandBtn.classList.toggle('text-emerald-700', success);
            }

            printStandBtn?.addEventListener('click', async () => {
                setStandButtonState(true);
                try {
                    const response = await fetch(printStandUrl, {
                        method: 'POST',
                        headers: {
                            'Accept': 'application/json',
                            'X-Requested-With': 'XMLHttpRequest',
                        },
                    });
                    if (!response.ok) {
                        throw new Error('Gagal print stand.');
                    }
                    setStandButtonState(false, true);
                } catch (error) {
                    setStandButtonState(false, false);
                    alert(error.message || 'Gagal print stand.');
                }
            });
        });
    </script>

    <script>
        window.addEventListener('load', () => {
            const moveMejaSelect = document.getElementById('move-meja-select');
            const moveMejaStatus = document.getElementById('show-move-meja-status');

            function buildBadge(status, text) {
                const cls = status === 'occupied'
                    ? '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 updateMoveMejaStatus() {
                if (!moveMejaSelect || !moveMejaStatus) return;
                const selected = moveMejaSelect.options[moveMejaSelect.selectedIndex];
                if (!selected || !selected.value) {
                    moveMejaStatus.innerHTML = '';
                    return;
                }

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

            moveMejaSelect?.addEventListener('change', updateMoveMejaStatus);
            updateMoveMejaStatus();
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>