<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <div class="mb-5">
        <?php if($menus->count() != 0): ?>
            <div class="card mb-3">
                <div class="card-body">
                    <div class="row row-cols-lg-auto g-3 align-items-center">
                        <div class="col-auto">
                            <label class="form-label" for="select-menu"><?php echo app('translator')->get('admin.selectMenuEdit'); ?></label>
                        </div>
                        <div class="col-auto">
                            <select class="form-control" name="menu" id="select-menu">
                                <option value=""><?php echo app('translator')->get('common.selectOne'); ?></option>
                                <?php $__currentLoopData = $menus; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($item->id); ?>"
                                        <?php if($menu && $menu->id == $item->id): ?> selected <?php endif; ?>><?php echo e($item->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-auto">
                            <button class="btn btn-secondary btn-sm menu-select" type="submit">
                                <?php echo app('translator')->get('common.select'); ?>
                            </button>
                        </div>
                        <?php if($menu): ?>
                            <div class="col-auto">
                                <span>
                                    <?php echo app('translator')->get('common.orSmall'); ?>
                                    <a href="<?php echo e(route('admin.menus')); ?>">
                                        <?php echo app('translator')->get('admin.createNewMenu'); ?>
                                    </a>
                                </span>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="row">
            <div class="col-md-3 col-sm-12">
                <h3 class="h6 bold"><?php echo app('translator')->get('admin.addMenuItems'); ?></h3>
                <div class="menu-builder" id="menuSections">
                    <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <form action="<?php echo e($menu ? route('admin.menus.add-items', $menu) : ''); ?>" method="post">
                            <?php echo csrf_field(); ?>
                            <div class="card mb-0 rounded-0 border-bottom-0">
                                <div class="card-header rounded-0<?php echo e($loop->first ? '' : ' collapsed'); ?>"
                                    data-coreui-toggle="collapse" data-coreui-target="#<?php echo e($section->key); ?>"
                                    aria-expanded="<?php echo e($loop->first ? 'true' : 'false'); ?>"
                                    aria-controls="<?php echo e($section->key); ?>">
                                    <h6 class="mb-0"><?php echo e($section->name); ?></h6>
                                </div>
                                <div id="<?php echo e($section->key); ?>" class="<?php echo e($loop->first ? 'show collapse' : 'collapse'); ?>"
                                    aria-labelledby="<?php echo e($section->key); ?>" data-coreui-parent="#menuSections">
                                    <div class="card-body rounded-0 overflow-auto" style="max-height:200px;">
                                        <?php if($section->hasItems()): ?>
                                            <?php $__currentLoopData = $section->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <div class="form-check">
                                                    <input class="form-check-input" name="items[]" type="checkbox"
                                                        value="<?php echo e($key); ?>" id="<?php echo e($key); ?>"
                                                        <?php if(!$menu): ?> disabled <?php endif; ?>>
                                                    <label class="form-check-label" for="<?php echo e($key); ?>">
                                                        <?php echo e($item->label); ?>

                                                    </label>
                                                </div>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <?php else: ?>
                                            <div class="card-text">
                                                <?php echo app('translator')->get('admin.noItems'); ?>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                    <div class="card-footer rounded-0 text-end">
                                        <input type="hidden" name="source" value="<?php echo e($section->key); ?>">
                                        <button type="submit" class="btn btn-primary btn-sm"
                                            <?php if(!$menu): ?> disabled <?php endif; ?>><?php echo app('translator')->get('admin.addItems'); ?></button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <div class="card mb-0 rounded-0">
                        <form action="<?php echo e($menu ? route('admin.menus.add-items', $menu) : ''); ?>"
                            class="frmMenuItems customItem" method="post">
                            <?php echo csrf_field(); ?>
                            <div class="card-header" data-coreui-toggle="collapse"
                                data-coreui-target="#placeholder-custom" aria-expanded="false"
                                aria-controls="placeholder-custom">
                                <h6 class="mb-0"><?php echo app('translator')->get('admin.customLink'); ?></h6>
                            </div>
                            <div class="collapse" data-parent="#menuSections" id="placeholder-custom">
                                <div class="card-body overflow-auto" style="max-height:230px;">
                                    <div class="form-group mb-3" id="customlinkdiv">
                                        <label class="form-label" for="custom-menu-item-url"><?php echo app('translator')->get('common.url'); ?></label>
                                        <input class="form-control required" id="custom-menu-item-url" name="url"
                                            type="text" value="http://" placeholder="<?php echo app('translator')->get('common.url'); ?>"
                                            <?php if(!$menu): ?> disabled <?php endif; ?>>
                                    </div>
                                    <div class="form-group" id="customnamediv">
                                        <label class="form-label" for="custom-menu-item-name"><?php echo app('translator')->get('admin.itemTitle'); ?></label>
                                        <input class="form-control required" id="custom-menu-item-name" name="link_text"
                                            type="text" placeholder="<?php echo app('translator')->get('admin.itemTitle'); ?>"
                                            <?php if(!$menu): ?> disabled <?php endif; ?>>
                                    </div>
                                </div>
                                <div class="card-footer form-actions text-end">
                                    <input type="hidden" name="source" value="custom">
                                    <button type="submit" class="btn btn-sm btn-primary addCustomBtn addItemsBtn"
                                        <?php if(!$menu): ?> disabled <?php endif; ?>><?php echo app('translator')->get('admin.addItem'); ?></button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-md-9 col-sm-12">
                <h3 class="h6 bold"><?php echo app('translator')->get('admin.menuStructure'); ?></h3>
                <form action="<?php echo e($menu ? route('admin.menus.update', $menu) : route('admin.menus.create')); ?>"
                    method="post">
                    <?php echo csrf_field(); ?>
                    <div class="card">
                        <div class="card-header">
                            <div class="row row-cols-lg-auto g-3 align-items-center">
                                <div class="col-12">
                                    <label class="form-label mb-0" for="menu_name"><?php echo app('translator')->get('admin.menuName'); ?></label>
                                </div>
                                <div class="col-12">
                                    <input name="name" value="<?php echo e($menu ? $menu->name : ''); ?>"
                                        class="form-control form-control-sm" type="text">
                                </div>
                            </div>
                        </div>
                        <div class="card-body">
                            <p class="card-text">
                                <?php echo e($menu ? __('admin.addMenuItemHelp') : __('admin.createmenuHelp')); ?>

                            </p>
                            <div class="sortable-menu dd">
                                <?php if($menu): ?>
                                    <?php if (isset($component)) { $__componentOriginal08b708aa82b5c912b324a7e265040dbd = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal08b708aa82b5c912b324a7e265040dbd = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.application-menu-builder','data' => ['items' => $menu->parent_items]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('application-menu-builder'); ?>
<?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(['items' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($menu->parent_items)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal08b708aa82b5c912b324a7e265040dbd)): ?>
<?php $attributes = $__attributesOriginal08b708aa82b5c912b324a7e265040dbd; ?>
<?php unset($__attributesOriginal08b708aa82b5c912b324a7e265040dbd); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal08b708aa82b5c912b324a7e265040dbd)): ?>
<?php $component = $__componentOriginal08b708aa82b5c912b324a7e265040dbd; ?>
<?php unset($__componentOriginal08b708aa82b5c912b324a7e265040dbd); ?>
<?php endif; ?>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="card-footer footer-sticky">
                            <?php if($menu): ?>
                                <a class="text-danger deleteMenu small" role="button">
                                    <?php echo app('translator')->get('admin.deleteMenu'); ?>
                                </a>
                                <input type="hidden" name="id" value="<?php echo e($menu->id); ?>">
                            <?php endif; ?>
                            <button class="btn btn-primary btn-sm float-end" type="submit">
                                <?php echo e($menu ? __('admin.saveMenu') : __('admin.createMenu')); ?>

                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php if($menu): ?>
        <form id="deleteFrm" method="post" action="<?php echo e(route('admin.menus.destroy', $menu)); ?>">
            <?php echo method_field('DELETE'); ?>
            <?php echo csrf_field(); ?>
        </form>
    <?php endif; ?>
    <?php $__env->startSection('footer_scripts'); ?>
        <script src="https://code.jquery.com/jquery-2.2.4.min.js"
            integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/nestable2@1.6.0/jquery.nestable.min.js" crossorigin="anonymous"></script>
        <script>
            const ARTISAN_APP = function() {
                const changeOrder = function() {
                        const $m_nestable = $('.dd').nestable({
                            expandBtnHTML: '',
                            collapseBtnHTML: '',
                            maxDepth: 3,
                        });
                        $m_nestable.on('change', function(e) {
                            const items = $('.dd').nestable('serialize')
                            formatMenu(items, null)
                        });
                    },
                    formatMenu = function(items, parent) {
                        items.forEach(function(item, key) {
                            $(`#menu_order_${item.id}`).val(key);
                            $(`#menu_parent_${item.id}`).val(parent?.id);
                            if (item.children) {
                                formatMenu(item.children, item)
                            }
                        });
                    };
                const customLink = function() {
                    function isValidCustomLink() {
                        const url = document.getElementById("custom-menu-item-url"),
                            name = document.getElementById("custom-menu-item-name");
                        var d = url.value,
                            e = name.value;
                        "http://" == d ? url.classList.add("is-invalid") : url.classList.remove(
                            "is-invalid")
                        "" == e ? name.classList.add("is-invalid") : name.classList.remove(
                            "is-invalid")

                        return "http://" == d || '' == e
                    }
                    document.querySelectorAll('#custom-menu-item-url, #custom-menu-item-name').forEach(element => {
                        element.addEventListener('keyup',
                            (event) => {
                                isValidCustomLink()
                            });
                    });
                    document.querySelector('.addCustomBtn').addEventListener('click', (e) => {
                        if (isValidCustomLink()) {
                            e.preventDefault();
                        }
                    });
                };
                const selectMenu = function(e) {
                    document.querySelector('.menu-select').addEventListener('click', function() {
                        const id = document.querySelector('select[name="menu"]').value
                        let route = '<?php echo e(route('admin.menus', ['menu' => ':id'])); ?>'
                        route = route.replace(':id', id)
                        if (id) {
                            window.location.href = route
                        }
                    })
                };
                <?php if($menu): ?>
                    const deleteMenu = function(e) {
                        document.querySelector('.deleteMenu').addEventListener("click", function() {
                            document.getElementById('deleteFrm').submit()
                        })
                    };
                    const deleteMenuItem = function(e) {
                        document.querySelectorAll('.delete-menu-item').forEach((element) => {
                            element.addEventListener('click', (e) => {
                                const id = e.target.getAttribute('data-menu-id')
                                var $url =
                                    '<?php echo e(route('admin.menus.item.destroy', ['menu' => $menu->id, 'item' => ':id'])); ?>';
                                $url = $url.replace(':id', id)
                                axios.delete($url)
                                    .then(res => {
                                        if (res.data)
                                            document.querySelector('[data-id="' + id + '"]')
                                            .remove()
                                    }).catch(err => {
                                        console.log(err.response.data.msg)
                                    });
                            })
                        });
                    };
                <?php endif; ?>

                return {
                    init: function() {
                        selectMenu();
                        customLink();
                        <?php if($menu): ?>
                            deleteMenu()
                            deleteMenuItem()
                            changeOrder()
                        <?php endif; ?>
                    }
                }
            }();
            document.addEventListener("DOMContentLoaded", function(event) {
                ARTISAN_APP.init();
            });
        </script>
    <?php $__env->stopSection(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php /**PATH /www/wwwroot/webtoolzone.com/resources/themes/admin/menu/index.blade.php ENDPATH**/ ?>