
<?php $__env->startSection('main-container'); ?>
<?php echo $__env->make('cdn', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<main id="main" class="main">
  <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
  <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<h4>Groups</h4>
 <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Group.Create')): ?>
<div class="text-end mb-2">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newgroup-<?php echo e($users); ?>"><i class="bi bi-plus-circle-fill"></i>&nbsp; New Group</button>
</div>
<?php endif; ?>
 <table class="table table-striped display nowrap" id="tabl" style="width:100%;">
            <thead>
                <tr>
                    <th>S.No</th>
                    <th>Group</th>
                    <th>Group Manager</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody> 
              <?php $__currentLoopData = $groups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td style="text-transform:capitalize;"><?php echo e($value->name); ?></td>
                        <td style="text-transform:capitalize;"><?php echo e($value->userName->name); ?></td>
                        <td> 
                           <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Group.Edit')): ?>                    
                          <a class="btn " role="button" data-toggle="modal" data-target="#editGroup-<?php echo e($value); ?>"><i class="bi bi-pencil-fill" style="color:navy;"></i></a>
                           <?php endif; ?> 

                           <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Group.Status')): ?>
                           <input data-id="<?php echo e($value->id); ?>" class="toggle-class" type="checkbox" data-onstyle="success" data-offstyle="danger" data-toggle="toggle" data-on="Active" data-off="InActive" <?php echo e($value->status ? 'checked' : ''); ?>>  
                           <?php endif; ?>
                    
                         <a href="<?php echo e(url('/group-users/'.$value->id)); ?>" class="btn btn-primary" style="color:white;"><i class="bi bi-person-fill-add"></i> Member</a>
                        </td> 

                        <!-- Modal for edit group-->
                            <div class="modal fade" id="editGroup-<?php echo e($value); ?>" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                            <div class="modal-content">
                              <div class="modal-header" style="background-color: #ffb74d;">
                                <h5 class="modal-title" id="editModalLabel">Edit Group</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                  <span aria-hidden="true">&times;</span>
                                </button>
                              </div>
                             
                               <form action="<?php echo e(url('group-edit/'.$value->id)); ?>" method="post">
                                <?php echo e(csrf_field()); ?>

                              
                              <div class="modal-body">
                                <div class="row mb-3">
                                  <label for="inputText" class="col-sm-4 col-form-label">Group Name<span style="color:red;">*</span></label>
                                  <div class="col-sm-7">
                                    <input type="text" name="name" value="<?php echo e($value->name); ?>" class="form-control" style="text-transform: capitalize;" required>
                                  </div> 
                                  </div>
                                  <div class="row mb-3"> 
                                  <label for="inputText" class="col-sm-4 col-form-label">Group Manager<span style="color:red;">*</span></label>
                                  <div class="col-sm-7">
                                  <select class="custom-select form-control" name="group_manager" style="text-transform:capitalize;" required>
                                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($user->id==$value->group_manager): ?>
                                    <option value="<?php echo e($value->group_manager); ?>" selected><?php echo e($value->userName->name); ?></option>
                                    <?php else: ?>
                                    <option value="<?php echo e($user->id); ?>"><?php echo e($user->name); ?></option>
                                    <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                  </select>  
                                  </div>
                                </div>  
                              </div>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                <button type="submit" class="btn " style="background-color: #ffb74d;">Edit</button>
                              </div>
                            </form>
                            </div>
                            </div>
                            </div>

                    </tr>
                   <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
  </table>
  
<!-- Modal -->
<div class="modal fade" id="newgroup-<?php echo e($users); ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="background-color: #ffb74d;">
        <h5 class="modal-title" id="exampleModalLabel">Add Group</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
       <form action="<?php echo e(url('/savegroup')); ?>" method="post">
        <?php echo e(csrf_field()); ?>

      <div class="modal-body">
        <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">Group Name<span style="color:red;">*</span></label>
                  <div class="col-sm-7">
                    <input type="text" name="name" class="form-control" placeholder="Enter Group Name" required>
                  </div>
          </div>
          <div class="row mb-3">
                  <label for="inputText" class="col-sm-4 col-form-label">Group Manager<span style="color:red;">*</span></label>
                  <div class="col-sm-7">
                  <select name="group_manager" class="custom-select form-control" required>
                    <option>Select Manager</option>
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($user->id); ?>"><?php echo e($user->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                  </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn" style="background-color: #ffb74d;">Add</button>
      </div>
    </form>
    </div>
  </div>
</div>
</main>
<script type="text/javascript">  
   $(document).ready(function () {
    var table = $('#tabl').DataTable({
      order: [],
      columnDefs: [ { orderable: false, targets: [0,1,2,3] } ], 
      responsive: true
    });

    new $.fn.dataTable.FixedHeader( table );
}); 
</script>
<script>
  $(function() {
    $('.toggle-class').change(function() {
        var status = $(this).prop('checked') == true ? 1 : 0; 
        var group_id = $(this).data('id'); 
        $.ajax({
            type: "GET",
            dataType: "json",
            url: '/groupstatus',
            data: {'status': status, 'group_id': group_id},
            success: function(data){
              console.log(data.success)
            }
        });
    })
  })
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('frontend.layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\CRM\resources\views/frontend/newgroup.blade.php ENDPATH**/ ?>