
<?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>
<div>
  <h4>Lead Source</h4>
</div>
<?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Source.Create')): ?>
<div class="text-end mb-2">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addsource"><i class="bi bi-plus-circle-fill"></i> Add Source</button>
</div>
<?php endif; ?>
 <table class="table table-striped display nowrap" id="tabl" style="width:100%;">
            <thead >
                <tr>
                    <th></th>
                    <th>S.No</th>
                    <th>Name</th>
                    <th>Status</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody> 
              <?php $__currentLoopData = $source; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td></td>
                        <td><?php echo e(++$key); ?></td>
                        <td style="text-transform: capitalize;"><?php echo e($value->name); ?></td>
                        <td> 
                           <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' : ''); ?>>
                        </td>
                        <td>
                          <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Source.Edit')): ?>
                          <a class="btn " role="button" data-toggle="modal" data-target="#editsource-<?php echo e($value->id); ?>" style="color:blue;"><i class="bi bi-pencil-fill"></i></a>
                          <?php endif; ?>

                          <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Source.Delete')): ?>
                            <a href="<?php echo e(url('deletesource/'.$value->id)); ?>" ><button type="button" class="btn"><i class="bi bi-trash" style="color:red;"></i></button></a>
                          <?php endif; ?>
                        </td>

                         <!-- Modal for edit source-->
                            <div class="modal fade" id="editsource-<?php echo e($value->id); ?>" 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:#ffbb33;">
                                <h5 class="modal-title" id="editModalLabel">Edit Source</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('source-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-2 col-form-label">Source</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>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                <button type="submit" class="btn btn-warning">Edit</button>
                              </div>
                            </form>
                            </div>
                            </div>
                            </div>      
                    </tr>
                   <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
<!-- Modal -->
<div class="modal fade" id="addsource" 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:#ffbb33;">
        <h5 class="modal-title" id="exampleModalLabel">Add Source</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('/addsource')); ?>" method="post">
        <?php echo e(csrf_field()); ?>

      <div class="modal-body">
        <div class="row mb-3">
                  <label for="inputText" class="col-sm-2 col-form-label">Source</label>
                  <div class="col-sm-7">
                    <input type="text" name="name" class="form-control" placeholder="Enter Source" required>
                  </div>
                </div>  
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">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,4] } ], 
      responsive: true
    });

    new $.fn.dataTable.FixedHeader( table );
}); 
</script>
<script>
  $(function() {
    $('.toggle-class').change(function() {
        var status = $(this).prop('checked') == true ? 1 : 0; 
        var source_id = $(this).data('id'); 
         
        $.ajax({
            type: "GET",
            dataType: "json",
            url: '/sourceStatus',
            data: {'status': status, 'source_id': source_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 /home/wwwtechturtlecon/public_html/lms.techturtleconsultant.com/resources/views/frontend/lead-source.blade.php ENDPATH**/ ?>