

<?php $__env->startSection('title', 'Permissions'); ?>

<?php $__env->startSection('page-style'); ?>
<link href="https://cdn.datatables.net/2.1.8/css/dataTables.bootstrap5.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/3.0.3/css/responsive.dataTables.css">
<link href="https://cdn.datatables.net/buttons/3.2.0/css/buttons.dataTables.css" rel="stylesheet">
<?php $__env->stopSection(); ?>
      
<?php $__env->startSection('content'); ?>

		<div class="mb-2">
		<a href="<?php echo e(url('admin/users')); ?>" class="btn btn-kco-green me-1 mb-2"><i class="bx bx-group  bx-sm me-sm-1"></i>Users</a>
        <a href="<?php echo e(url('admin/roles')); ?>" class="btn btn-kco-dark-yellow mx-1 mb-2"><i class="bx bx-log-in-circle  bx-sm me-sm-1"></i>Roles</a>
        <a href="<?php echo e(url('admin/permissions')); ?>" class="btn btn-kco-light-brown mx-1 mb-2"><i class="bx bx-lock-open  bx-sm me-sm-1"></i>Permissions</a>
		</div>
		
		<?php if(session()->get('success')): ?>
		<div class="alert alert-success">
		  <?php echo e(session()->get('success')); ?>  
		</div>
	<?php endif; ?>
	
	   <?php if($errors->any()): ?>
    <div class="alert alert-danger">
        <strong>Whoops!</strong> There were some problems with your input.<br><br>
        <ul>
            <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <li><?php echo e($error); ?></li>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </ul>
    </div>
	<?php endif; ?>

        <div class="row">
            <div class="col-md-12">
                <div class="card card-datatable table-responsive">
				
                    <div class="card-header">
						<div id="custom-dt-toolbar">
							<div class="row">
								<div class="col-md-6">
									<div class="dt-toolbar-left">
										<h5 class="card-title mb-0">Manage Permissions</h5>
									</div>
								</div>
								
								<div class="col-md-6">
									<div class="dt-toolbar-right">
									<?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('create-permission')): ?>
										<button class="btn create-new btn-kco-green" type="button" data-bs-toggle="modal" data-bs-target="#addModal">
											<span><i class="bx bx-plus bx-sm me-sm-2"></i> 
											<span class="d-none d-sm-inline-block">Add Permission</span>
											</span>
										</button>
									<?php endif; ?>
									</div>
								</div>
								
								</div>
							</div>
					</div><!--/.header-->
					
                    <div class="card-body p-0">

                        <table class="datatables-basic table table-bordered table-striped border-top dataTable" style="width:100%">
                            <thead>
                                <tr>
                                    <th>Id</th>
                                    <th>Name</th>
                                    <th width="40%">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $permissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $permission): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($permission->id); ?></td>
                                    <td><?php echo e($permission->name); ?></td>
                                    <td>
                                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update-permission')): ?>
									<a  href="#" title="Edit" alt="Edit" class="edit" data-id="<?php echo e($permission->id); ?> " data-name="<?php echo e($permission->name); ?>">
                                            <i class="bx bx-edit-alt  bx-sm me-sm-1 txt-kco-green"></i>
                                        </a>
                                        <?php endif; ?>

                                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete-permission')): ?>
                                        <a href="<?php echo e(url('admin/permissions/'.$permission->id.'/delete')); ?>" title="Delete" alt="Delete" class="delete">
										<i class="bx bx-trash  bx-sm me-sm-1 text-danger"></i>
										</a>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>
		
		<!-- Add Modal -->
          <div class="modal fade" id="addModal" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <form action="<?php echo e(url('admin/permissions')); ?>" method="POST" class="needs-validation" novalidate>
				<?php echo csrf_field(); ?>
                <div class="modal-header">
                  <h5 class="modal-title" id="editModalLabel1">Add Permission</h5>
                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                  <div class="row">
                    <div class="col mb-3">
                      <label for="addPermission" class="form-label">Permission</label>
                      <input type="text" name="name" class="form-control" placeholder="Permission Name" required>
					  <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-danger"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					      <div class="invalid-feedback">Permission name is required.</div>
                    </div>
                  </div>	
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-label-secondary" data-bs-dismiss="modal">Close</button>
                  <button type="submit" class="btn btn-primary">Save changes</button>
                </div>
				</form>
              </div>
              </div>
            </div>
	  
          <!-- Edit Modal -->
          <div class="modal fade" id="editModal" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
			  <form action="<?php echo e(url('admin/permissions/updatepermission')); ?>" method="POST" class="needs-validation" novalidate>
				<?php echo csrf_field(); ?>
                <div class="modal-header">
                  <h5 class="modal-title" id="editModalLabel1">Edit Permission</h5>
                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
				<input type="hidden" name="permissionid"  class="form-control edit_permissionid">
                  <div class="row">
                    <div class="col mb-3">
                      <label for="permissionName" class="form-label">Permission Name</label>
                      <input type="text" name="name" class="form-control edit_name" placeholder="Enter Permission Name" required>
					  <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-danger"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
					      <div class="invalid-feedback">Permission name is required.</div>
                    </div>
                  </div>	
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-label-secondary" data-bs-dismiss="modal">Close</button>
                  <button type="submit" class="btn btn-primary">Save changes</button>
                </div>
				</form>
              </div>
            </div>
			</div>
<?php $__env->stopSection(); ?>

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

<script type="text/javascript">
(function () {
  'use strict';
  window.addEventListener('load', function () {
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function (form) {
      form.addEventListener('submit', function (event) {
        if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);
})();

document.addEventListener('livewire:navigated', () => {
	 console.log('dt navigated');
$(function () {
     $.noConflict();   
    var table = $('.dataTable').DataTable({
		order:[],
		dom: 'Bfrltip',
		lengthMenu: [[10, 25, 50, 100, 500, 1000, -1], [10, 25, 50, 100, 500, 1000, "All"]],
		language: {
			"emptyTable": "No data available in table",
			"lengthMenu": "Show _MENU_ entries",
		},
		responsive: true,
		buttons: [
					{
						extend: 'collection',
						text: "<i class='bx bx-download bx-sm me-sm-1'></i> Export",
						className: 'export_btns btn btn-outline-kco me-4',
						buttons: [
							{
								extend: 'csv',
								text: '<i class="bx bx-file me-1"></i> CSV',
								titleAttr: 'CSV'
							},
							{
								extend: 'excel',
								text: '<i class="bx bxs-file-export me-1"></i> Excel',
								titleAttr: 'Excel'
							},
							{
								extend: 'pdf',
								text: '<i class="bx bxs-file-pdf me-1"></i> PDF',
								titleAttr: 'PDF'
							},
						]
					},
					/*{
						extend: 'colvis',
						text: 'Display',
					}*/
				],
    });
	$('.export_btns').detach().prependTo('.dt-toolbar-right');
    $(".export_btns").addClass("dropdown-toggle");

	$('.dataTable').on('click', '.edit', function (e) {
	  e.preventDefault();
		$(".edit_permissionid").val($(this).data('id'));
		$(".edit_name").val($(this).data('name'));
		let modal = bootstrap.Modal.getOrCreateInstance($('#editModal')); // Returns a Bootstrap modal instance //modal.show //modal.hide
		modal.show();
  });
  
  $('.dataTable').on('click', '.delete', function (e) {
	  e.preventDefault();
	  var href = $(this).attr('href');
      Swal.fire({
        title: 'Delete permission?',
        text: "This action is irreversible",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete!'
      }).then((result) => {
        if (result.isConfirmed) {
          window.location.href = href;
        }
      });
  });
	
  });
  }, { once:true });
  </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts/contentNavbarLayout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\kcofbms\resources\views/users/permission/index.blade.php ENDPATH**/ ?>