<?php $__env->startSection('content'); ?>
    <?php
        if (! isset($selectedPackageItems) || ! is_array($selectedPackageItems)) {
            $selectedPackageItems = [];
        }
    ?>

    <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
        <div class="mb-6">
            <h2 class="text-2xl font-semibold text-slate-900">Edit Menu</h2>
            <p class="text-sm text-slate-500">Perbarui informasi menu.</p>
        </div>
        <form method="post" action="<?php echo e(route('menus.update', $menu)); ?>" enctype="multipart/form-data" class="grid gap-4 md:grid-cols-2">
            <?php echo csrf_field(); ?>
            <?php echo method_field('put'); ?>
            <?php if (isset($component)) { $__componentOriginaled2cde6083938c436304f332ba96bb7c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginaled2cde6083938c436304f332ba96bb7c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.select','data' => ['name' => 'id_stand','label' => 'Stand','required' => true]] + (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_stand','label' => 'Stand','required' => true]); ?>
                <option value="">Pilih Stand</option>
                <?php $__currentLoopData = $stands; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stand): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($stand->id); ?>" <?php echo e(old('id_stand', $menu->id_stand) == $stand->id ? 'selected' : ''); ?>><?php echo e($stand->nama); ?></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; ?>

            <?php if (isset($component)) { $__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input','data' => ['name' => 'nama','label' => 'Nama','value' => $menu->nama,'required' => true]] + (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' => 'nama','label' => 'Nama','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($menu->nama),'required' => true]); ?>
<?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)) { $__componentOriginaled2cde6083938c436304f332ba96bb7c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginaled2cde6083938c436304f332ba96bb7c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.select','data' => ['name' => 'type_menu','label' => 'Type Menu','required' => true]] + (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' => 'type_menu','label' => 'Type Menu','required' => true]); ?>
                <option value="">Pilih Type</option>
                <?php $__currentLoopData = ['makanan' => 'Makanan', 'minuman' => 'Minuman', 'snack' => 'Snack']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($value); ?>" <?php echo e(old('type_menu', $menu->type_menu) === $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; ?>

            <?php if (isset($component)) { $__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input','data' => ['name' => 'harga_pokok','label' => 'Harga Pokok','type' => 'number','step' => '0.01','value' => $menu->harga_pokok]] + (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' => 'harga_pokok','label' => 'Harga Pokok','type' => 'number','step' => '0.01','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($menu->harga_pokok)]); ?>
<?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)) { $__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input','data' => ['name' => 'harga_jual','label' => 'Harga Jual','type' => 'number','step' => '0.01','value' => $menu->harga_jual]] + (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' => 'harga_jual','label' => 'Harga Jual','type' => 'number','step' => '0.01','value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($menu->harga_jual)]); ?>
<?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)) { $__componentOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc2fcfa88dc54fee60e0757a7e0572df1 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.input','data' => ['name' => 'image','label' => 'Image','type' => 'file']] + (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' => 'image','label' => 'Image','type' => 'file']); ?>
<?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($menu->image): ?>
                <div class="md:col-span-2">
                    <p class="text-sm font-semibold text-slate-700">Preview</p>
                    <img src="<?php echo e(asset('storage/' . $menu->image)); ?>" alt="<?php echo e($menu->nama); ?>" class="mt-2 h-28 w-28 rounded-lg border border-slate-200 object-cover">
                </div>
            <?php endif; ?>

            <div class="md:col-span-2">
                <label class="inline-flex items-center gap-2 text-sm font-semibold text-slate-700">
                    <input type="checkbox" name="is_active" value="1" class="rounded border-slate-300" <?php echo e(old('is_active', $menu->is_active) ? 'checked' : ''); ?>>
                    Aktif
                </label>
            </div>

            <div class="md:col-span-2">
                <label class="inline-flex items-center gap-2 text-sm font-semibold text-slate-700">
                    <input type="checkbox" name="is_package" id="is-package" value="1" class="rounded border-slate-300" <?php echo e(old('is_package', $menu->is_package) ? 'checked' : ''); ?>>
                    Menu Paket Bukber
                </label>
                <p class="mt-1 text-xs text-slate-500">Jika aktif, menu ini akan dipecah ke beberapa stand saat print stand.</p>
            </div>

            <div id="package-box" class="md:col-span-2 rounded-xl border border-slate-200 bg-slate-50 p-4 <?php echo e(old('is_package', $menu->is_package) ? '' : 'hidden'); ?>">
                <div class="mb-3 flex items-center justify-between">
                    <div>
                        <p class="text-sm font-semibold text-slate-800">Komponen Paket</p>
                        <p class="text-xs text-slate-500">Pilih menu yang termasuk dalam paket.</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' => 'button','variant' => 'secondary','id' => 'add-package-row']] + (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' => 'add-package-row']); ?>Tambah Komponen <?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 id="package-rows" class="space-y-3">
                    <?php $__empty_1 = true; $__currentLoopData = $selectedPackageItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $idx => $packageItem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="package-row grid gap-3 rounded-lg border border-slate-200 bg-white p-3 md:grid-cols-12">
                            <div class="md:col-span-8">
                                <label class="mb-1 block text-xs font-semibold text-slate-600">Menu Komponen</label>
                                <select name="package_items[<?php echo e($idx); ?>][id_menu]" class="block w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700">
                                    <option value="">Pilih menu</option>
                                    <?php $__currentLoopData = $componentMenus; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $componentMenu): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($componentMenu->id); ?>" <?php echo e((string) ($packageItem['id_menu'] ?? '') === (string) $componentMenu->id ? 'selected' : ''); ?>>
                                            <?php echo e($componentMenu->nama); ?> (<?php echo e(ucfirst($componentMenu->type_menu)); ?>)
                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="md:col-span-3">
                                <label class="mb-1 block text-xs font-semibold text-slate-600">Qty</label>
                                <input
                                    type="number"
                                    min="1"
                                    name="package_items[<?php echo e($idx); ?>][qty]"
                                    value="<?php echo e($packageItem['qty'] ?? 1); ?>"
                                    class="block w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700"
                                >
                            </div>
                            <div class="flex items-end md:col-span-1">
                                <button type="button" class="remove-package-row inline-flex w-full items-center justify-center rounded-lg border border-rose-200 px-2 py-2 text-xs font-semibold text-rose-600 hover:bg-rose-50">
                                    Hapus
                                </button>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <div class="package-row grid gap-3 rounded-lg border border-slate-200 bg-white p-3 md:grid-cols-12">
                            <div class="md:col-span-8">
                                <label class="mb-1 block text-xs font-semibold text-slate-600">Menu Komponen</label>
                                <select name="package_items[0][id_menu]" class="block w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700">
                                    <option value="">Pilih menu</option>
                                    <?php $__currentLoopData = $componentMenus; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $componentMenu): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($componentMenu->id); ?>">
                                            <?php echo e($componentMenu->nama); ?> (<?php echo e(ucfirst($componentMenu->type_menu)); ?>)
                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="md:col-span-3">
                                <label class="mb-1 block text-xs font-semibold text-slate-600">Qty</label>
                                <input
                                    type="number"
                                    min="1"
                                    name="package_items[0][qty]"
                                    value="1"
                                    class="block w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700"
                                >
                            </div>
                            <div class="flex items-end md:col-span-1">
                                <button type="button" class="remove-package-row inline-flex w-full items-center justify-center rounded-lg border border-rose-200 px-2 py-2 text-xs font-semibold text-rose-600 hover:bg-rose-50">
                                    Hapus
                                </button>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>

                <?php if($errors->has('package_items') || $errors->has('package_items.*.id_menu') || $errors->has('package_items.*.qty')): ?>
                    <p class="mt-2 text-xs text-rose-600">
                        <?php echo e($errors->first('package_items') ?: ($errors->first('package_items.*.id_menu') ?: $errors->first('package_items.*.qty'))); ?>

                    </p>
                <?php endif; ?>
            </div>

            <div class="flex gap-3 md:col-span-2">
                <?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']); ?>Update <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $attributes = $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
<?php if (isset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561)): ?>
<?php $component = $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561; ?>
<?php unset($__componentOriginald0f1fd2689e4bb7060122a5b91fe8561); ?>
<?php endif; ?>
                <?php if (isset($component)) { $__componentOriginald0f1fd2689e4bb7060122a5b91fe8561 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald0f1fd2689e4bb7060122a5b91fe8561 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.button','data' => ['href' => ''.e(route('menus.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(route('menus.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>
        </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; ?>

    <script>
        const packageCheckbox = document.getElementById('is-package');
        const packageBox = document.getElementById('package-box');
        const packageRows = document.getElementById('package-rows');
        const addPackageRowButton = document.getElementById('add-package-row');
        const packageOptions = <?php echo json_encode($componentMenus->map(fn ($menu) => [
            'id' => $menu->id, 'label' => $menu->nama . ' (' . ucfirst($menu->type_menu) . ')', ])->values()) ?>;
        let packageIndex = packageRows.querySelectorAll('.package-row').length;

        function togglePackageBox() {
            const show = packageCheckbox.checked;
            packageBox.classList.toggle('hidden', !show);
        }

        function buildPackageSelectHtml(index) {
            const options = ['<option value="">Pilih menu</option>'];
            packageOptions.forEach((option) => {
                options.push(`<option value="${option.id}">${option.label}</option>`);
            });

            return `
                <select name="package_items[${index}][id_menu]" class="block w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700">
                    ${options.join('')}
                </select>
            `;
        }

        function createPackageRow() {
            const row = document.createElement('div');
            row.className = 'package-row grid gap-3 rounded-lg border border-slate-200 bg-white p-3 md:grid-cols-12';
            row.innerHTML = `
                <div class="md:col-span-8">
                    <label class="mb-1 block text-xs font-semibold text-slate-600">Menu Komponen</label>
                    ${buildPackageSelectHtml(packageIndex)}
                </div>
                <div class="md:col-span-3">
                    <label class="mb-1 block text-xs font-semibold text-slate-600">Qty</label>
                    <input
                        type="number"
                        min="1"
                        name="package_items[${packageIndex}][qty]"
                        value="1"
                        class="block w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700"
                    >
                </div>
                <div class="flex items-end md:col-span-1">
                    <button type="button" class="remove-package-row inline-flex w-full items-center justify-center rounded-lg border border-rose-200 px-2 py-2 text-xs font-semibold text-rose-600 hover:bg-rose-50">
                        Hapus
                    </button>
                </div>
            `;
            packageRows.appendChild(row);
            packageIndex += 1;
        }

        packageCheckbox?.addEventListener('change', togglePackageBox);
        addPackageRowButton?.addEventListener('click', createPackageRow);

        packageRows?.addEventListener('click', (event) => {
            const removeButton = event.target.closest('.remove-package-row');
            if (!removeButton) {
                return;
            }

            const row = removeButton.closest('.package-row');
            const rowCount = packageRows.querySelectorAll('.package-row').length;
            if (rowCount <= 1) {
                row.querySelector('select').value = '';
                const qtyInput = row.querySelector('input[type="number"]');
                if (qtyInput) {
                    qtyInput.value = 1;
                }
                return;
            }

            row.remove();
        });

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

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