<?php $__env->startSection('main-container'); ?>
<main id="main" class="main">
<?php echo $__env->make('cdn', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<div class="row page-titles mx-0">

    <div class="col-sm-6 p-md-0">

        <div class="breadcrumb-range-picker">

             <h3>Roles</h3>

        </div>

    </div>

    <div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('roles.create')): ?>
        <div class="text-end mb-2">
        <button type="button" class="btn btn-primary rounded-pill" data-toggle="modal" data-target="#addRole-<?php echo e($permissions); ?>"><i class="bi bi-plus-circle-fill"></i> Add Role</button>
        </div>
        <?php endif; ?>

    </div>

</div>

<div class="container-fluid" style="margin-top: 15px">

    <?php echo $__env->make('flash_msg', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

    <div class="row">

        <div class="col-12">

            <div class="card">

                <div class="card-body">

                    <form method="GET" action="">

                        <div class="row text-right">

                            <div class="col-md-6"></div>

                            <div class="col-md-4">

                                 <input type="text" class="form-control right-search" name="search" value="<?php echo e($request->search); ?>" placeholder="Search by Roles">

                            </div>

                             <div class="col-md-2">

                                <label class="">&nbsp;</label>

                                <button type="submit" class="btn btn-outline-info bg-grad-4 btn-ft">Search</button>

                            </div>

                        </div>

                    </form>

                    <hr>

                    <div class="table-responsive">

                        <table class="table table-border table-hover table-sm" >
                            <thead>
                                <tr>
                                    <th>S.No</th>
                                    <th>Role</th>
                                    <th>Action</th>
                                </tr>
                            </thead>

                            <tbody>
                                <?php $__currentLoopData = $roles; $__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>
                           <a href="<?php echo e(url('permissions/'.$value->id)); ?>" ><button type="button" class="btn btn-warning" style="border-radius:12px;">Permission</button></a>
                          <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('roles.edit')): ?>
                          <a class="btn btn-primary" role="button" data-toggle="modal" data-target="#editRole-<?php echo e($value->id); ?>"style="border-radius:12px;">Edit</a>
                          <?php endif; ?>
                            <!-- Modal -->
                            <div class="modal fade" id="editRole-<?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 bg-info bg-gradient">
                                <h5 class="modal-title" id="editModalLabel">Edit Role</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('role-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">Role</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-primary">Edit</button>
                              </div>
                            </form>
                            </div>
                            </div>
                            </div>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('roles.delete')): ?>
                          <a href="<?php echo e(url('deleterole/'.$value->id)); ?>" ><button type="button" class="btn btn-danger" style="border-radius:12px;" >delete</button></a>
                          <?php endif; ?>
                        </td>

                    </tr>
                   <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                               </tbody>

                            <tfoot>

                                <tr>
                                    <th>S.No</th>
                                    <th>Role</th>
                                    <th>Action</th>
                                </tr>


                            </tfoot>

                        </table>

                    </div>

                       <div class="text-left float-left mt-1">

                       <p>Displaying <?php echo e($roles->count()); ?> of <?php echo e($roles->total()); ?> Add Roles.</p>

                    </div>

                    <div class="text-right float-right">

                         

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>

<!-- Modal -->
<div class="modal fade" id="addRole-<?php echo e($permissions); ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header  bg-info bg-gradient" >
          <h5 class="modal-title" id="exampleModalLabel">Add Role</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('/role-submit')); ?>" method="post">
          <?php echo e(csrf_field()); ?>


        <div class="modal-body" style="height:380px; overflow-y: scroll;">
          <div class="row mb-3">
                    <label for="inputText" class="col-sm-4 col-form-label">Role<span style="color:red;">*</span></label>
                    <div class="col-sm-7">
                      <input type="text" name="r_name" class="form-control" placeholder="Enter Role" required>
                    </div>
          </div>
            <h5>Permissions</h5>
                   <?php $__currentLoopData = $permissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $permission): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                       <div class="form-check form-check-inline">
                          <input class="form-check-input p-2" type="checkbox" name="permission[]" id="inlineCheckbox1" value="<?php echo e($permission->id); ?>">
                        <label class="form-check-label p-2" for="inlineCheckbox1" style="text-transform:capitalize;"><?php echo e($permission->name); ?></label>
                       </div>
                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </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 () {
      $('#tabl').DataTable({
         order: [],
        columnDefs: [ { orderable: false, targets: [0,1,2] } ],
        bFilter: false,
        bInfo: false
      });
  });
  </script>
  <script type="text/javascript">

     $(document).on('click','.open_modal',function(){
          var url = "domain.com/yoururl";
          var role_id= $(this).val();
          $.get(url + '/' + role_id, function (data) {
              //success data
              console.log(data);
              $('#role_id').val(data.id);
              $('#name').val(data.name);
             $('#btn-save').val("update");

          })
      });
  </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\TADA\resources\views/frontend/rolespage.blade.php ENDPATH**/ ?>