<?php $__env->startSection("content"); ?>
    <div class="content-header row">
        <div class="content-header-left col-md-6 col-12 mb-2 breadcrumb-new">
            <h3 class="content-header-title mb-0 d-block">Modül Sıralama</h3>
            <div class="row breadcrumbs-top d-inline-block">
                <div class="breadcrumb-wrapper col-12">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="<?php echo e(url('panel')); ?>">Anasayfa</a>
                        </li>
                        <li class="breadcrumb-item active">Modül Ayarları
                        </li>
                    </ol>
                </div>
            </div>
        </div>
        <div class="content-header-right col-md-6 col-12">
            <div class="dropdown float-md-right">
                <a href="<?php echo e(url('panel')); ?>" class="btn btn-dark round btn-glow px-2">Geri Dön</a>
            </div>
        </div>
    </div>
    <div class="content-body">
        <div class="row">
            <div id="recent-sales" class="col-7 col-md-7">
                <div class="card">
                    <div class="card-header">
                        <h4>Ana Sayfa Modülleri</h4>
                    </div>
                    <div class="card-body pt-0">
                        <ul class="list-group" id="ust-moduller">
                            <?php if($moduller): ?>
                                <?php $__currentLoopData = $moduller; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $modul): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if(isset($ayar->{$modul->code})): ?>
                                        <?php if($ayar->{$modul->code} == 1): ?>
                                            <li class="list-group-item py-1 drag mb-1" style="background-color: #f8f8f8" data-id="<?php echo e($modul->id); ?>" id="<?php echo e($modul->id); ?>">
                                                <span class="float-left">
                                                  <i class="la la-arrows-v mr-1"></i>
                                                </span>
                                                <span class="d-inline-block float-left text-dark text-bold-600"><?php echo e($modul->isim); ?></span>
                                                <?php if(count($modul->kategoriler) != 0): ?>
                                                    <div class="clearfix"></div>
                                                    <span class="d-block w-50">
                                                      <select class="form-control my-1" name="ozel1" onchange="degistir(this.value,'<?php echo e($modul->id); ?>')">
                                                          <option selected disabled>Kategori Seçiniz</option>
                                                          <?php $__currentLoopData = $modul->kategoriler; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kategori): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <option value="<?php echo e($kategori->id); ?>" <?php if($kategori->id == $modul->kategori): ?><?php echo e('selected'); ?><?php endif; ?>><?php echo e($kategori->baslik); ?></option>
                                                          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                      </select>
                                                    </span>
                                                <?php endif; ?>
                                            </li>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        <li class="list-group-item py-1 drag mb-1" style="background-color: #f8f8f8" data-id="<?php echo e($modul->id); ?>" id="<?php echo e($modul->id); ?>">
                                            <span class="float-left">
                                              <i class="la la-arrows-v mr-1"></i>
                                            </span>
                                            <span class="d-inline-block float-left text-dark text-bold-600"><?php echo e($modul->isim); ?></span>
                                            <?php if(count($modul->childs)): ?>
                                                <br><br>
                                                <ul class="list-group">
                                                    <?php $__currentLoopData = $modul->childs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $child): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <li class="list-group-item py-1 mb-1" style="background-color: #f8f8f8" data-id="<?php echo e($child->id); ?>" id="<?php echo e($child->id); ?>">
                                                            <span class="float-left">
                                                              <i class="la la-arrows-v mr-1"></i>
                                                            </span>
                                                            <span class="d-inline-block float-left text-dark text-bold-600"><?php echo e($child->isim); ?></span>
                                                            <?php if($child->code == 'gundemhaber' || $child->code == 'sporhaber' || $child->code == 'ikilikategori1' || $child->code == 'ikilikategori2'): ?>
                                                                <div class="clearfix"></div>
                                                                <span class="d-block w-50">
                                                                  <select class="form-control my-1" name="ozel1" onchange="degistir(this.value,'<?php echo e($child->id); ?>')">
                                                                      <option selected disabled>Kategori Seçiniz</option>
                                                                      <?php $__currentLoopData = $kategoriler; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                          <option value="<?php echo e($kat->id); ?>" <?php if($kat->id == $child->kategori): ?><?php echo e('selected'); ?><?php endif; ?>><?php echo e($kat->baslik); ?></option>
                                                                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                  </select>
                                                                </span>
                                                            <?php endif; ?>
                                                        </li>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </ul>
                                            <?php else: ?>
                                                <?php if(count($modul->kategoriler) != 0): ?>
                                                    <div class="clearfix"></div>
                                                    <span class="d-block w-50">
                                                      <select class="form-control my-1" name="ozel1" onchange="degistir(this.value,'<?php echo e($modul->id); ?>')">
                                                          <option selected>Kategori Seçiniz</option>
                                                          <?php $__currentLoopData = $modul->kategoriler; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kategori): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                              <option value="<?php echo e($kategori->id); ?>" <?php if($kategori->id == $modul->kategori): ?><?php echo e('selected'); ?><?php endif; ?>><?php echo e($kategori->baslik); ?></option>
                                                          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                      </select>
                                                    </span>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </li>
                                    <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </ul>
                    </div>
                </div>
            </div>
            <div id="" class="col-5 col-md-5">
                <div class="card">
                    <div class="card-header">
                        <h4>Sidebar (Site Sağ) Modülleri</h4>
                    </div>
                    <div class="card-body pt-0">
                        <ul class="list-group" id="sag-moduller">
                            <?php if($modullerSide): ?>
                                <?php $__currentLoopData = $modullerSide; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $side): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if(isset($ayar->{$side->code})): ?>
                                        <?php if($ayar->{$side->code} == 1): ?>
                                            <li class="list-group-item py-1 drag mb-1" style="background-color: #f8f8f8" data-id="<?php echo e($side->id); ?>" id="<?php echo e($side->id); ?>">
                                                <span class="float-left">
                                                  <i class="la la-arrows-v mr-1"></i>
                                                </span>
                                                <span class="d-inline-block float-left text-dark text-bold-600"><?php echo e($side->isim); ?></span>
                                            </li>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        <li class="list-group-item py-1 drag mb-1" style="background-color: #f8f8f8" data-id="<?php echo e($side->id); ?>" id="<?php echo e($side->id); ?>">
                                                <span class="float-left">
                                                  <i class="la la-arrows-v mr-1"></i>
                                                </span>
                                            <span class="d-inline-block float-left text-dark text-bold-600"><?php echo e($side->isim); ?></span>
                                        </li>
                                    <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startPush("customJs"); ?>
    <script src="<?php echo e(asset('assets/backend/app-assets/vendors/js/ui/jquery-ui.min.js')); ?>" type="text/javascript"></script>
    <script>
        let cats = $("#ust-moduller").sortable({
            items:'.drag',
            revert: true,
            group: 'nested',
            cursor: 'move',
            opacity: 0.5,
            distance: 20,
            tolerance: 'pointer',
            update: function(event, ui){
                /*var order = $('#card-drag-area').sortable('serialize');
                console.log(order);*/

            },
            change: function (event, ui) {
                ui.placeholder.css({visibility: 'visible', border: '1px solid #29C5FF',backgroundColor: '#C5D3E2'});
            },
            stop: function(event, ui) {
                let itemOrder = $('#ust-moduller').sortable("toArray");
                for (let i = 0; i < itemOrder.length; i++) {
                    console.log("Position: " + (i +1) + " ID: " + itemOrder[i]);
                    let id = itemOrder[i];
                    let order = (i+1);
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'
                        },
                        type: 'POST',
                        url: "/panel/modul-ayarlari/order/"+id,
                        data: {id: id,order:order},
                        success: function (data){
                            //console.log(data.success + "id li kategori sıralama yapıldı.");
                            //location.reload();
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });
        let cat = $("#sag-moduller").sortable({
            items:'.drag',
            revert: true,
            cursor: 'move',
            opacity: 0.5,
            distance: 20,
            tolerance: 'pointer',
            update: function(event, ui){
                /*var order = $('#card-drag-area').sortable('serialize');
                console.log(order);*/
            },
            change: function (event, ui) {
                ui.placeholder.css({visibility: 'visible', border: '1px solid #29C5FF',backgroundColor: '#C5D3E2'});
            },
            stop: function(event, ui) {
                let itemOrder = $('#sag-moduller').sortable("toArray");
                for (let i = 0; i < itemOrder.length; i++) {
                    console.log("Position: " + (i +1) + " ID: " + itemOrder[i]);
                    let id = itemOrder[i];
                    let order = (i+1);
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'
                        },
                        type: 'POST',
                        url: "/panel/modul-ayarlari/order/"+id,
                        data: {id: id,order:order},
                        success: function (data){
                            //console.log(data.success + "id li kategori sıralama yapıldı.");
                            //location.reload();
                        },
                        error: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });

        function degistir(value,id) {
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'
                },
                type: 'POST',
                url: "/panel/modul-ayarlari/degistir",
                data: {id: id,value:value},
                success: function (data){
                    swal({
                        title: 'Ayarlar Kaydedildi',
                        text: 'Kategori Değiştirildi',
                        type: "success",
                        timer: 2000,
                        confirmButtonText: 'Tamam'
                    });
                },
                error: function(e) {
                    console.log(e);
                }
            });
        }
    </script>
<?php $__env->stopPush(); ?>

<?php $__env->startPush("customCss"); ?>

<?php $__env->stopPush(); ?>

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