
<?php $__env->startSection('title'); ?> User  | Beauty Parlour <?php $__env->stopSection(); ?>
<?php $__env->startSection('users'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('users.index'); ?> active <?php $__env->stopSection(); ?>
<?php $__env->startSection('styles'); ?>
<style>
  .setting-custom-select2-form .select2-container--default .select2-selection--single{
    padding-top: 5px;
    padding-bottom: 5px;
  }
</style>
<?php $__env->stopSection(); ?>

<!-- BEGIN: Content-->
<?php $__env->startSection('main_content_section'); ?>
<div class="row py-3 ps-2">
  <div class="heading d-flex justify-content-start heading-margin-bottom-minus">
    <h3 class="mb-0"><span>User List</span></h3>
  </div>
</div>


<div class="table_wrapper py-1 card">
  <div class="row my-2 aggregate-section-div">
    <div class="px-3 ">
      <div class=" d-flex justify-content-between align-items-center aggregate-section border">
        <div class="d-flex align-items-center py-1">
          <p class="mb-0"><a href="<?php echo e(route('users.index')); ?>"
              class="text-primary  py-2 px-3 active">All (<?php echo e($userCount); ?>)</a></p>
        </div>
        <div class="d-none d-sm-block">
          <?php if(Auth::user()->can('user-create')): ?> 
            <a href="javascript:void(0)" class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0"
              data-bs-toggle="modal" data-bs-target="#oneInputModalCenterForLarge"><span class="">New User</span></a>
          <?php endif; ?>
        </div>
      </div>

     <?php if(Auth::user()->can('user-create')): ?> 
       <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none" data-bs-toggle="modal"
         data-bs-target="#oneInputModalCenterForLarge">New User</div>
     <?php endif; ?>
    </div>
  </div>



  <div class="row px-3">
    <div class="table-container table-responsive">
      <table id="" class="table table-bordered">
        <thead class="text-uppercase">
          <tr class="me-3">

            <th class="text-center" scope="col"><span>User Name</span></th>
            <th class="text-center" scope="col"><span> Email </span></th>
            <th class="text-center" scope="col"><span> Mobile </span></th> 
            <th class="text-center" scope="col"><span> Role </span></th> 


          </tr>
        </thead>
        <tbody class="text-center">

          <?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <?php if(isset($item) && $item != null): ?>
            <tr class="">
              <td> 
                  <?php echo e($item->name); ?>

                  <div class="row-actions">

                      <?php if(Auth::user()->can('user-delete')): ?> 
                          <?php if(Auth::user()->role == 'superadmin' && $item->name != 'superadmin'): ?> 
                            <?php if(Auth::user()->can('user-edit')): ?>
                            <span><button class="text-primary border-0 bg-transparent fw-bolder" value="<?php echo e($item->id); ?>"
                                onclick="updateUser(<?php echo e($item->id); ?>)"> Edit </button> </span>
                            <?php endif; ?>

                            <span> | <a href="<?php echo e(route('user.delete', ['id'=>$item->id])); ?>" class="row-delete"><span
                              class="trash text-danger fw-bolder">Delete</span> </a></span>
                          <?php elseif(Auth::user()->role == 'admin' && $item->name != 'admin'): ?>
                            <?php if(Auth::user()->can('user-edit')): ?>
                            <span><button class="text-primary border-0 bg-transparent fw-bolder" value="<?php echo e($item->id); ?>"
                                onclick="updateUser(<?php echo e($item->id); ?>)"> Edit </button> </span>
                            <?php endif; ?>

                            <span> | <a href="<?php echo e(route('user.delete', ['id'=>$item->id])); ?>" class="row-delete"><span
                              class="trash text-danger fw-bolder">Delete</span> </a></span>
                          <?php elseif(Auth::user()->role == 'manager' && $item->name != 'manager'): ?>
                            <?php if(Auth::user()->can('user-edit')): ?>
                            <span><button class="text-primary border-0 bg-transparent fw-bolder" value="<?php echo e($item->id); ?>"
                                onclick="updateUser(<?php echo e($item->id); ?>)"> Edit </button> </span>
                            <?php endif; ?>

                            <span> | <a href="<?php echo e(route('user.delete', ['id'=>$item->id])); ?>" class="row-delete"><span
                              class="trash text-danger fw-bolder">Delete</span> </a></span>
                          <?php endif; ?>
                      <?php endif; ?>
                  </div>
              </td>
              <td> <?php echo e($item->email); ?></td>
              <td> <?php echo e($item->mobile); ?></td>
              <td> <span class="badge bg-primary p-1"><?php echo e($item->role); ?></span></td>
            </tr>

            
            <div class="modal fade" id="updateUser<?php echo e($item->id); ?>" tabindex="-1" aria-labelledby="oneInputModalLabel"
              aria-hidden="true" data-bs-backdrop='static'>
              <div class="modal-dialog modal-dialog-centered max-width-900px">
                <div class="modal-content">
                  <div class="modal-header">
                    <h1 class="modal-title fs-5" id="oneInputModalLabel">Update User</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body p-0">
                    <form action="<?php echo e(route('users.update', $item->id)); ?>" method="POST" enctype="multipart/form-data">
                      <?php echo csrf_field(); ?>
                      <?php echo method_field('put'); ?>
                      <div class="row">
                        <input type="hidden" id="edit_id" name="edit_id">
                        <div class=" col-md-6 px-4 my-1">
                          <label for="name" class="form-label mb-2">Name<span class="text-danger">(required)</span></label>
                          <input type="text" class="form-control  form-control-solid" name="name" id="edit_name" placeholder="Name"
                            value="<?php echo e($item->name); ?>" required>
                        </div>
            
                        <div class="col-md-6 px-4 my-1">
                          <label for="email" class="form-label mb-2">Email <span class="text-danger">(required)</span></label>
                          <input type="email" class="form-control  form-control-solid" name="email" id="edit_email"
                            value="<?php echo e($item->email); ?>" placeholder="Email" required>
                        </div>
                        <div class="col-md-6 px-4 my-1">
                          <label for="mobile" class="form-label mb-2">Mobile <span class="text-danger">(required)</span></label>
                          <input type="number" class="form-control  form-control-solid number-control-hide" name="mobile"
                            id="mobile<?php echo e($item->id); ?>" value="<?php echo e($item->mobile); ?>" placeholder="Mobile" required>
                        </div>
            
                        <div class="col-md-6 px-4 my-1">
                          <div class="form-group custom-select2-form setting-custom-select2-form">
                            <label for="roles">Role <span class="text-danger">(required)</span>
                            </label>
                            <select name="roles" id="roles<?php echo e($item->id); ?>" class="form-select select2 mt-2" required>
                              <option value="" selected disabled> Select Role </option>
                              <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option value="<?php echo e($role->id); ?>" <?php echo e($item->hasRole($role->name) ? 'selected' : ''); ?>><?php echo e(Str::title($role->name)); ?></option>
                              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                          </div>
                        </div>
                        
                        <div class="col-md-12 px-4 my-1">
                          <div class="form-group custom-select2-form setting-custom-select2-form">
                            <label for="branch_id">Branch <span class="text-danger">(required)</span>
                            </label>
                            <select name="branch_id" id="branch_id<?php echo e($item->id); ?>" class="form-select select2 mt-2" required>
                              <option value="" selected disabled> Select Branch </option>
                              <?php $__currentLoopData = $branchData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $singleBD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option value="<?php echo e($singleBD->id); ?>" <?php echo e($singleBD->id == Auth::user()->branch_id ? 'selected' : ''); ?>>
                                <?php echo e(Str::title($singleBD->branch_title)); ?></option>
                              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                          </div>
                        </div>
                        
                      </div>
                      <div class="modal-footer">
                        <div class="">
                          <button type="submit" class="btn btn-success" onclick="return checkValidateForUpdate(<?php echo e($item->id); ?>)">Update</button>
                          <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
              </div>
            </div>

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


        </tbody>
      </table>
    </div>

    <?php if(isset($userCount) && $userCount > 10): ?>
    <div class="clearfix d-flex">
      <div class="float-left">
        <p class="text-muted">
          <?php echo e(__('Showing')); ?>

          <span class="font-weight-bold"><?php echo e($data->firstItem()); ?></span>
          <?php echo e(__('to')); ?>

          <span class="font-weight-bold"><?php echo e($data->lastItem()); ?></span>
          <?php echo e(__('of')); ?>

          <span class="font-weight-bold"><?php echo e($data->total()); ?></span>
          <?php echo e(__('results')); ?>

        </p>
      </div>
    
      <div class="float-right custom-table-pagination">
        <?php echo $data->links('pagination::bootstrap-4'); ?>

      </div>
    </div>
    <?php endif; ?>

  </div>

  
  <div class="modal fade" id="oneInputModalCenterForLarge" tabindex="-1" aria-labelledby="oneInputModalLabel"
    aria-hidden="true" data-bs-backdrop='static'>
    <div class="modal-dialog modal-dialog-centered max-width-900px">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5" id="oneInputModalLabel">New User</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body p-0">
          <form action="<?php echo e(route('users.store')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <div class="row">
              <div class=" col-md-6 px-4 my-1">
                <label for="name" class="form-label mb-2">Name <span class="text-danger">(required)</span></label>
                <input type="text" class="form-control  form-control-solid" name="name" id="name" placeholder="Name"
                  required>
              </div>
  
              <div class="col-md-6 px-4 my-1">
                <label for="email" class="form-label mb-2">Email <span class="text-danger">(required)</span></label>
                <input type="email" class="form-control  form-control-solid" name="email" id="email" placeholder="Email"
                  required>
              </div>
              <div class="col-md-6 px-4 my-1">
                <label for="mobile" class="form-label mb-2">Mobile <span class="text-danger">(required)</span></label>
                <input type="number" class="form-control  form-control-solid number-control-hide" name="mobile"
                  id="mobile" placeholder="Mobile" required>
              </div>
  
              <div class="col-md-6 px-4 my-1">
                <label for="password" class="form-label mb-2">Password <span class="text-danger">(required)</span></label>
                <input type="password" class="form-control  form-control-solid" name="password" id="password"
                  placeholder="Password" required>
              </div>
  
              <div class="col-md-6 px-4 my-1">
                <label for="password_confirmation" class="form-label mb-2">Confirm Password <span
                    class="text-danger">(required)</span></label>
                <input type="password" class="form-control  form-control-solid" name="password_confirmation"
                  id="password_confirmation" placeholder="Confirm Password" required>
              </div>
  
              <div class="col-md-6 px-4 my-1">
                <div class="form-group custom-select2-form setting-custom-select2-form">
                  <label for="roles">Role <span class="text-danger">(required)</span>
                  </label>
                  <select name="roles" id="roles" class="form-select select2" required>
                    <option value="" selected disabled> Select Role </option>
                    <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($role->id); ?>"><?php echo e(Str::title($role->name)); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                </div>
              </div>

              <div class="col-md-12 px-4 my-1">
                <div class="form-group custom-select2-form setting-custom-select2-form">
                  <label for="branch_id">Branch <span class="text-danger">(required)</span>
                  </label>
                  <select name="branch_id" id="branch_id" class="form-select select2 mt-2" required>
                    <option value="" selected disabled> Select Branch </option>
                    <?php $__currentLoopData = $branchData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $singleBD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($singleBD->id); ?>" <?php echo e($singleBD->id == Auth::user()->branch_id ? 'selected' : ''); ?>>
                      <?php echo e(Str::title($singleBD->branch_title)); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                </div>
              </div>

            </div>
            <div class="modal-footer">
              <div class="">
                <button type="submit" class="btn btn-success" onclick="return checkValidate()">Save</button>
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>


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

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

  $("#roles").select2({
    dropdownParent: $('#oneInputModalCenterForLarge')
  })
  $("#branch_id").select2({
    dropdownParent: $('#oneInputModalCenterForLarge')
  })

  function checkValidate() {
        var mobileNumber = $("#mobile").val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Mobile number must be 11 digit."); 
        }

        return true;
    }
    
    //For update...
    function checkValidateForUpdate(id) {
        var mobileNumber = $("#mobile"+id).val();

        if (mobileNumber != '' && mobileNumber.length != 11) { 
            event.preventDefault();
            toastr.error("Mobile number must be 11 digit."); 
        }

        return true;
    }
  
  //To show update modal...
  function updateUser(id) {
      $("#updateUser"+id).modal('show');
      $("#roles"+id).select2({
        dropdownParent: $('#updateUser'+id)
      })
      $("#branch_id"+id).select2({
        dropdownParent: $('#updateUser'+id)
      })
  }

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\Project\Personal-Project\Office-Project\update\skin-care\resources\views/admin/userRole/users/index.blade.php ENDPATH**/ ?>