
@extends('layouts.nav')
@section('title')
@endsection
@section('content')               

<div class="pagetitle">
      <h1>User permissions</h1>
      
    </div><!-- End Page Title -->
    <section class="section">
      <div class="row">
       
        <div class="col-lg-8">

 
          <div class="card">
            <div class="card-body">

              <!-- No Labels Form -->
              <form action="" style="display:flex; flex-direction:column; gap:20px;" class="row g-3" method="POST">
               {{csrf_field()}}
                <div class="col-md-6">
                  <input type="text" name="roleName" class="form-control" readonly   placeholder="{{$getUser['FullName']}}">
                </div>
                <div class="col-md-12">
                  <label for="">Permissions</label>
                  <hr>
                  <div style="display: flex; margin-bottom:10px;" class="row">
                      <div class="col-md-3">
                        <strong>
                        Module Name

                        </strong>
                        </div>
                      <div class="col-md-3">
                        <strong>
                        Module Features

                        </strong>
                        </div>
                        <div style="display: flex; gap:30px; text-align:left" class="roles-choose">
                          <div style="display: flex; gap:30px; text-align:left class="row">
                           <div class="role-head">
                            <strong>
                            View
                            </strong> 
                           </div>
                           <div class="role-head">
                            <strong>

                              Add
                            </strong>
                           </div>
                           <div class="role-head">
                            <strong>

                              Edit
                            </strong>
                           </div>
                           <div class="role-head">
                            <strong>

                              Delete
                            </strong>

                           </div>
                           <div style="margin-bottom: 20px;">
                                <button type="button" class="btn btn-primary btn-sm" id="selectAll">Select All</button>
                                <button type="button" class="btn btn-secondary btn-sm" id="unselectAll">Unselect All</button>
                            </div>

                          </div>
                        </div>

                    </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Chart Accounts
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Accounts")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Accounting
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Accounting")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Currency
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Currency")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Affiliates
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Affiliates")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Facilities
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Facilities")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Invoices
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Invoices")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Receipts
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Receipts")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                            Settings
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "settings")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Tax
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Tax")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Banks
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Banks")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Accounting Statements
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Accounting Statements")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Tenant Transaction Listing
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Transaction Listing")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Affiliates Listing
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Affiliates Listing")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                   <div style="display:flex;" class="cont">
                     <div class="col-md-3">
                     Reports
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["module_name"] == "Reports")
                          <div style="display: flex; margin-bottom:0px;" class="row">                      
                          <div class="col-md-3">
                                {{$value["name"]}}
                            </div>
                            <div style="display: flex; gap:60px; text-align:left" class="roles-choose">
                                @foreach ($value["group"] as $group)
                                    @php
                                        $checked = '';
                                    @endphp
                                    @foreach ($getUserPermissions as $userPermissions)
                                  
                                  @if ($userPermissions->permissions_id == $group['id'])
                                  @php
                                    $checked = 'checked';
                                  @endphp
                                  @endif
                              @endforeach
                            <div style="display: flex; gap:30px; text-align:left" class="">
                                <label for=""><input type="checkbox" {{$checked}}  value="{{$group["id"]}}" name="permission_id[]">
                                </label>
    
                            </div>
                                @endforeach
                          </div>
    
                          </div>
                          @endif
                        @endforeach
                      </div>
                    
                   </div>
                   <hr>
                  
                   

                </div>
               
                
                <div style="padding-left: 15px; display:flex; gap:20px;" class="">
                    <button type="reset" class="btn btn-secondary">Reset</button>
                  <button type="submit" class="btn btn-primary">Submit</button>
                </div>
              </for><!-- End No Labels Form -->

            </div>
          </div>

        

        </div>
      </div>
    </section>
    <script>
    // JavaScript for Select All and Unselect All functionality
    document.addEventListener('DOMContentLoaded', function () {
        const selectAllButton = document.getElementById('selectAll');
        const unselectAllButton = document.getElementById('unselectAll');
        
        // Select all input elements of type checkbox
        const checkboxes = document.querySelectorAll('input[type="checkbox"]');

        selectAllButton.addEventListener('click', () => {
            checkboxes.forEach(checkbox => {
                checkbox.checked = true;
            });
        });

        unselectAllButton.addEventListener('click', () => {
            checkboxes.forEach(checkbox => {
                checkbox.checked = false;
            });
        });
    });
</script>

@endsection