@extends('layouts.master')
@section('title', 'Permissions Management')

@section('content')
<div class="container">

    <div class="d-flex justify-content-end mb-3">
        <a href="{{ route('users.index') }}" class="btn-back">
            <i class="fas fa-arrow-left me-2"></i> Back to Users
        </a>
    </div>

    <div class="card-header bg-primary text-white py-3">
        <h5 class="mb-0"><i class="fas fa-chart-line me-2"></i> Assign User Permissions</h5>
    </div>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <!-- FORM START -->
    <form action="" method="POST">
        @csrf

        <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">
                     Edit Menu
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Mainmenu")
                          <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">
                    Chart Of Accounts
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "chartofaccounts")
                          <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">
                    Trancation Types
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "tranctiontypes")
                          <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">
                    Customers
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "customers")
                          <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">
                    Suppliers
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "suppliers")
                          <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">
                    Cashbook
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Cashbook")
                          <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">
                    Inventory
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Inventory")
                          <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">
                   Multicurrency
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Multicurrency")
                          <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["feature"] == "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">
                    Projects
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Projects")
                          <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">
                    Processing Menu
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Process")
                          <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">
                    Process General Ledger
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Process General Ledger")
                          <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">
                    Customer Processing
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Process Customer")
                          <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">
                    Supplier Processing
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Process Supplier")
                          <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">
                    Journal Processing
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Process Journal")
                          <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">
                    Warehouse Transfer
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Warehouse Transfer")
                          <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["feature"] == "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 style="display:flex;" class="cont">
                     <div class="col-md-3">
                    Customer Reports
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Customer 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 style="display:flex;" class="cont">
                     <div class="col-md-3">
                    Supplier Reports
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Supplier 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 style="display:flex;" class="cont">
                     <div class="col-md-3">
                    Inventory Reports
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Inventory 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 style="display:flex;" class="cont">
                     <div class="col-md-3">
                    Administration Menu
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "Administration")
                          <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 Menu
                      </div>
                      <div class="col-md-12">
                      @foreach ($getPermissions as $value)
                        @php
                        $checked = '';
                        @endphp
                          @if ($value["feature"] == "User 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>
        <!-- Submit -->
        <div class="mt-3">
            <button type="" class="btn btn-primary">Submit</button>
            <a href="{{ route('users.index') }}" class="btn btn-secondary">Cancel</a>
        </div>
    </form>
    <!-- FORM END -->

</div>

<!-- Select/Unselect All Script -->
<script>
    document.getElementById("selectAll").addEventListener("click", () => {
        document.querySelectorAll("input[type=checkbox]").forEach(cb => cb.checked = true);
    });
    document.getElementById("unselectAll").addEventListener("click", () => {
        document.querySelectorAll("input[type=checkbox]").forEach(cb => cb.checked = false);
    });
</script>
@endsection
