<?php $__env->startSection('content'); ?>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="<?php echo e(asset('admin/assets/extra-libs/multicheck/datatable-checkbox-init.js')); ?>"></script>
    <script src="<?php echo e(asset('admin/assets/extra-libs/multicheck/jquery.multicheck.js')); ?>"></script>
    <script src="<?php echo e(asset('admin/assets/extra-libs/DataTables/datatables.min.js')); ?>"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('admin/assets/extra-libs/multicheck/multicheck.css')); ?>">
    <link href="<?php echo e(asset('admin/assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.css')); ?>" rel="stylesheet"> -->

    <main id="main" class="main">

        <?php if( Session::get('permissions.user_type') == 'A' || Session::get('permissions.user_type') == 'SA'): ?>
	        <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center justify-content-between px-4 mb-2">
                        <h4 class="page-title">Add Sub Group List</h4>
                        <div class="ml-auto text-right">
                            <a href="<?php echo e(route('admin.addon.addon_sub_group_add')); ?>" class="btn btn-success">ADD Addon Sub Group</a>
                        </div>
                    </div>
                </div>
            </div>
            <!-- modal head -->
            <head>
                <style>
                    #sortable { list-style-type: none; margin: 0; padding: 0; width: 80%; height: auto; }
                    #sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: auto; }
                    #sortable li span { position: absolute; margin-left: -1.3em; }
                </style>
            </head>
            <!-- modal head close -->
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <?php $__currentLoopData = ['danger', 'warning', 'success', 'info']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $msg): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if(Session::has('alert-' . $msg)): ?>
                                        <h4 class="font-weight-light alert alert-<?php echo e($msg); ?>"><?php echo e(Session::get('alert-' . $msg)); ?></h4>
                                    <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <h5 class="card-title">Addon Sub Group</h5>
                                <?php if(count($result) > 0): ?>
                                <div class="table-responsive">
                                    <table id="zero_config" class="table table-striped table-bordered">
                                        <thead>
                                            <tr>
                                                <th style="width: 5%"><b>No.</b></th>
                                                <th style="width: 20%"><b>Name</b></th>
                                                <th style="width: 20%"><b>Sort</b></th>
                                                <th style="width: 20%"><b>Addon Group Id</b></th>
                                                <th style="width: 20%"><b>Addon Group</b></th>
                                                <th style="width: 15%"><b>Created Date</b></th>
                                                <th style="width: 9%">Action</th>
                                                <th style="width: 6%"><b>Status</b></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $i=1; ?>
                                            <?php $__currentLoopData = $result; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                <td><?php echo e($i + $key); ?></td>
                                                <td><?php echo e($data->name); ?></td>
                                                <td><?php echo e($data->sort); ?></td>
                                                <td><?php echo e($data->addon_group_id); ?></td>
                                                <td>
                                                    <?php $__currentLoopData = $result1; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <?php if($data->addon_group_id==$value->id): ?>
                                                            <?php echo e($value->title); ?>

                                                        <?php endif; ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </td>
                                                <td><?php echo e(date('d-m-Y', strtotime($data->created_at))); ?></td>
                                                <td>
                                                    <a href="<?php echo e(route('admin.addon.addon_sub_group_edit', base64_encode($data->id).'?redirect='.urlencode($request->fullUrl()))); ?>">
                                                        <i class="fas fa-edit"></i>
                                                    </a>
                                                    <a href="<?php echo e(route('admin.addon.addon_sub_group_product_edit', base64_encode($data->id).'?redirect='.urlencode($request->fullUrl()))); ?>">
                                                        <i class="fas fa-eye"></i>
                                                    </a>
                                                </td>
                                                <td>
                                                    
                                                    <button data-toggle="modal" data-target="#addonproduct" data-addon_group_id="<?php echo e($data->addon_group_id); ?>" data-addon_sub_group_id="<?php echo e($data->id); ?>" class="btn btn-primary addon">Sort</button>
                                                </td>
                                            </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </tfoot>
                                    </table>
                                </div>
                                <?php else: ?>
                                    <div class="card">No Data Found...</div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>    
    </main><!-- End #main -->

    <script>

        /****************************************
         *       Basic Table                   *
         ****************************************/

        // $('#zero_config').DataTable({
        //     "order": [[5, "desc"]] 
        // });

        document.addEventListener("DOMContentLoaded", function () {
            const table = document.querySelector("#zero_config");
            const dataTable = new simpleDatatables.DataTable(table, {
                sortable: true,
                fixedHeight: true,
                columns: [
                    { select: 5, sort: "desc" } // Sort by the 6th column (index 5) descending
                ]
            });
        });


        //ajax call thats occcur to show multiple product list in the modal

        $(document).ready(function(){
            $('.addon').click(function (e){
                e.preventDefault();
                var addon_group_id = $(this).attr('data-addon_group_id');
                var addon_sub_group_id = $(this).attr('data-addon_sub_group_id');

                // console.log(addon_group_id);
                // console.log(addon_sub_group_id);

                $.ajax({
                    type : 'POST',
                    url : "<?php echo e(route('admin.addon.dragproduct')); ?>",
                    data : {
                            'addon_group_id' : addon_group_id,
                            'addon_sub_group_id' : addon_sub_group_id
                    },
                    headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    success : function(response){
                        $('#sortable').html(response);
                        $('#addonproduct').modal('show');
                    }
                });
                
                
            });
        });

        //sortable method called and ajax is called for update the sort field in tha database
       
        $( "#sortable" ).sortable({
            stop: function(event, ui) {
                var $data = $.map($(this).find('li'), function(e) {
                    return {id : $(e).data('id'), position : $(e).index(), addon_group_id : $(e).data('addon_group_id'), addon_sub_group_id : $(e).data('addon_sub_group_id')};
                });
                console.log($data);
                
                $.ajax({
                    type : 'POST',
                    url : "<?php echo e(route('admin.addon.sorthomepageproduct')); ?>",
                    data : { data : JSON.stringify($data) },
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    success : function(response){
                        response = JSON.parse(response);
                        if(response.status == 'success'){
                            alert(response.msg);
                        }
                        
                    },
                    error : function(){

                    }
                });
                
                
            }
        });

        $(function () {
            $(".btn-default, .close").click(function () {
                $("#addonproduct").modal("hide");
            });
        });

        // $(function(){
        //     setTimeout(function(){ $('.alert').hide(); }, 3000);
        //     var status, id;
        //     $('#zero_config').on('change', '.blockstatus', function() {
        //     //$('.blockstatus').change(function(){
        //         if(this.checked){
        //             status = 'Y';
        //         }else{
        //             status = 'N'
        //         }
        //         id = $(this).attr('data-id');
        //         var ajaxurl = ""; 
        //         $.ajax({
        //             type : 'POST',
        //             url : ajaxurl,
        //             data : { 'id' : id, 'status' : status },
        //             headers: {
        //                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        //             },
        //             success : function(response){
        //                 response = JSON.parse(response);
        //                 if(response.status == 1){
        //                     $('#status-info-'+response.id).html(response.event).fadeIn(100).delay(1000).fadeOut();
        //                 }
        //             },
        //             error : function(){
        //                 $('.selected_records_data').html('<span class="error-msg text-danger">There was an unexpected error!! Please try again later.</span>');
        //             }
        //         });
        //     });
        // })

    </script>

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


<!-- Modal -->
<div class="modal fade" id="addonproduct" role="dialog">
    <div class="modal-dialog">
    <script>
    </script>
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <!-- <h4 class="modal-title">Modal Header</h4> -->
        </div>

        <div class="modal-body">
            <ul id="sortable">
                
            </ul>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>

</div>


<?php echo $__env->make('layouts.admin.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/rightflorist/public_html/ofadmin.rightflorist.org/resources/views/admin/addon/addon_sub_group_list.blade.php ENDPATH**/ ?>