<?php $__env->startSection('content'); ?>
<div class="clearfix">
    <div class="full-width-container">
        <?php echo $__env->make('masterHeaderAdmin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <main class="main-container">
            <?php echo $__env->make('masterSidebar', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            <div class="page-body">
                <div class="nav-breadcrumbs">
                    <ul class="breadcrumbs">
                        <li>
                            <a href="<?php echo e(route('admin')); ?>" class="breadcrumbs-link">TRANG CHỦ</a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('quanlytintuc')); ?>" class="breadcrumbs-link">QUẢN LÝ TIN TỨC</a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('danhsachmenu')); ?>" class="breadcrumbs-link">DANH SÁCH MENU</a>
                        </li>
                    </ul>
                    <a href="<?php echo e(route('quanlytintuc')); ?>" class="page-button">
                        <i class="fa-solid fa-rotate-left"></i> Quay lại
                    </a>
                </div>
                <div class="page-table">
                    <table class="table">
                        <thead>
                            <tr>
                                <th class="small">STT</th>
                                <th>Tên danh mục</th>
                                <th>Loại</th>
                                <th>Thuộc</th>
                                <th>Link chi tiết</th>
                                <th>Target</th>
                                <th class="small">Sửa</th>
                                <th class="small">Xóa</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $menus; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $menu): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td>
                                <select onchange="selectVitri(this)" class="" >
                                    <option value="<?php echo e($menu->ViTri); ?>" seleted><?php echo e($menu->ViTri); ?></option>
                                    <?php if($menu->Thuoc==0): ?>
                                    <?php $__currentLoopData = $vitris; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vitri): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($vitri->ViTri); ?>" <?php echo e($menu->ViTri == $vitri->ViTri ? 'hidden' :
                                                                            ($vitri->Thuoc!=0 ? 'hidden' : '')); ?> ><?php echo e($vitri->ViTri); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php else: ?>
                                    <?php $__currentLoopData = $vitris; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vitri): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($vitri->ViTri); ?>" <?php echo e($menu->ViTri == $vitri->ViTri ? 'hidden' :
                                                                            ($vitri->Thuoc!=0 && $vitri->Thuoc==$menu->Thuoc ? '' : 'hidden')); ?> ><?php echo e($vitri->ViTri); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                </select>
                                </td>
                                <td><?php echo ($menu->Thuoc==0) ? $menu->TenDanhMuc : '&emsp;<i class="fa-solid fa-angles-right"></i> '. $menu->TenDanhMuc; ?></td>
                                <td><?php echo e($menu->Loai); ?></td>
                                <td><?php echo e($menu->Thuoc); ?></td>
                                <td><?php echo e($menu->LinkChiTiet); ?></td>
                                <td><?php echo e($menu->Target == '_self' ? 'Mở trong cùng cửa sổ' : ($menu->Target == '_blank' ? 'Mở trong cửa sổ mới' : 'Không có target')); ?></td>
                                <td>
                                    <span class="table-icon"
                                        data-length = "7"
                                        data-0 = "<?php echo e($menu->MaBlock); ?>"
                                        data-1 = "<?php echo e($menu->TenDanhMuc); ?>"
                                        data-2 = "<?php echo e($menu->Loai); ?>"
                                        data-3 = "<?php echo e($menu->Thuoc); ?>"
                                        data-4 = "<?php echo e($menu->Target); ?>"
                                        data-5 = "<?php echo e($menu->LinkChiTiet); ?>"
                                        data-6 = "<?php echo e($menu->ViTri); ?>"
                                        onclick="loadRecordData(this)">
                                        <i class="fa-solid fa-file-pen"></i>
                                    </span>
                                </td>
                                <td>
                                    <a href="<?php echo e(route('del_menu',$menu->MaBlock)); ?>" onclick="return confirm('Bạn có chắc muốn xóa mục này?\nBài viết và loại tin thuộc thể loại này đều sẽ bị xóa. Thao tác này không thể hoàn trả.')" class="table-icon">
                                        <i class="fa-solid fa-trash"></i>
                                    </a>
                                </td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
                <form action="<?php echo e(route('edit_menu')); ?>" method="post" id="form-nhap-lieu" class="add-record-table">
                    <table class="table">
                        <tr>
                            <?php echo $__env->make('alert', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                            <td>
                                <input type="hidden" name="maBlock" id="inp-0" class="add-record-table--input add-record-table--input-text">
                            </td>
                        </tr>
                        <tr>
                            <td>Vị trí</td>
                            <td>
                                <input type="text" placeholder="Nhập vào vị trí" name="vitri" id="inp-6" class="add-record-table--input add-record-table--input-text" readonly>
                            </td>
                        </tr>
                        <tr>
                            <td class="form-field-label--required" >Tên danh mục</td>
                            <td>
                                <input type="text" placeholder="Nhập vào tên thể danh mục" name="tenDanhMuc" id="inp-1" class="add-record-table--input add-record-table--input-text">
                            </td>
                        </tr>
                        <tr>
                            <td class="form-field-label--required">Loại</td>
                            <td>
                                <select name="Loai" id="inp-2" class="add-record-table--input add-record-table--input-text" onchange="changeLoai()">
                                    <?php $__currentLoopData = $loais; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $loai): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($loai); ?>"><?php echo e($loai); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </td>
                        </tr>
                        <tr id="thuoc" >
                            <td>Thuộc</td>
                            <td>
                                <select name="Thuoc" id="inp-3" class="add-record-table--input add-record-table--input-text">
                                    <option value="0" >0</option>
                                    <?php $__currentLoopData = $menus; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $menu): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($menu->ViTri); ?>" <?php echo e($menu->Loai=='DROPDOWN' ?'':'hidden'); ?>><?php echo e($menu->ViTri); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </td>
                        </tr>
                        <tr id="target">
                            <td class="form-field-label--required">Target</td>
                            <td>
                            <select name="target" id="inp-4" class="add-record-table--input add-record-table--input-text">
                                <?php $__currentLoopData = $targets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $target): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($target); ?>"><?php echo e($target == '_self' ? 'Mở trong cùng cửa sổ' : ($target == '_blank' ? 'Mở trong cửa sổ mới' : 'Không có target')); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            </td>
                        </tr>
                        <tr id="link">
                            <td>Link chi tiết</td>
                            <td>
                                <input type="text" placeholder="Nhập vào tên link chi tiết" name="Link" id="inp-5" class="add-record-table--input add-record-table--input-text">
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <label class="add-record-table--button-block" for="them">
                                    <i class="fa-solid fa-plus"></i>
                                    <input type="submit" value="Thêm" name="them" id="them" class="add-record-table--button">
                                </label>
                                <label class="add-record-table--button-block" for="luu">
                                    <i class="fa-solid fa-pencil"></i>
                                    <input type="submit" value="Sửa" name="luu" id="luu" class="add-record-table--button">
                                </label>
                                <label class="add-record-table--button-block" for="xoa">
                                    <i class="fa-solid fa-eraser"></i>
                                    <input type="reset" value="Xóa" name="xoa" id="xoa" class="add-record-table--button">
                                </label>
                            </td>
                        </tr>
                    </table>
                    <?php echo csrf_field(); ?>
                </form>
            </div>
        </main>

    </div>
</div>
<script>
    function changeLoai() {
        var selectedValue = document.getElementById('inp-2').value;

        var thuoc = document.getElementById('thuoc');
        var target = document.getElementById('target');
        var link = document.getElementById('link');

        if (selectedValue === 'LINK') {
            thuoc.style.display = '';
            target.style.display = '';
            link.style.display = '';
        } else {
            thuoc.style.display = 'none';
            target.style.display = 'none';
            link.style.display = 'none';
        }
    }

    var sua = document.querySelectorAll('.table-icon');
    sua.forEach(function(item) {
        item.addEventListener('click', function() {
            var Loai = item.getAttribute('data-2');
            var thuoc = document.getElementById('thuoc');
            var target = document.getElementById('target');
            var link = document.getElementById('link');

            if (Loai === 'LINK') {
                thuoc.style.display = '';
                target.style.display = '';
                link.style.display = '';
            } else {
                thuoc.style.display = 'none';
                target.style.display = 'none';
                link.style.display = 'none';
            }

        });
    });


    function selectVitri(t) {
        var vitri = t.value;
        var sua = t.closest('tr').querySelector('.table-icon');
        sua.setAttribute('data-6', vitri);
    }
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('masterAdmin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/demo/public_html/resources/views/admin/danhsachmenu.blade.php ENDPATH**/ ?>