


@extends('layouts.app')

@section('content')
<div class="container-xxl flex-grow-1 container-p-y">
    <div class="card">



        <div class="container mt-5">
                    <div class="row">
                        <div class="col-md-12">

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

                            <div class="card  mb-5">
                                <div class="card-header">
                                    <h4>Role : {{ $role->name }}
                                        <a href="{{ url('roles') }}" class="btn btn-danger float-end">Back</a>
                                    </h4>
                                </div>
                                <div class="card-body">

                                    <form action="{{ url('roles/'.$role->id.'/give-permissions') }}" method="POST">
                                        @csrf
                                        @method('PUT')

                                        <div class="mb-3">
                                            @error('permission')
                                            <span class="text-danger">{{ $message }}</span>
                                            @enderror

                                            <label for="">Permissions</label>

                                           <div class="row">
                                                @foreach ($permissions as $permission)
                                                <div class="col-md-4 "> {{-- Changed to col-md-3 for better spacing --}}
                                                    <div class="form-check form-check-inline">
                                                        <input 
                                                            class="form-check-input" 
                                                            type="checkbox" 
                                                            name="permission[]" 
                                                            id="permission_{{ $permission->id }}" {{-- Added ID for clicking label --}}
                                                            value="{{ $permission->name }}"
                                                            {{ in_array($permission->id, $rolePermissions) ? 'checked':'' }}
                                                            style="cursor: pointer; width: 1.2em; height: 1.2em;"
                                                        >
                                                        <label 
                                                            class="form-check-label ms-1" 
                                                            for="permission_{{ $permission->id }}" 
                                                            style="cursor: pointer; font-weight: 500;"
                                                        >
                                                            {{ $permission->name }}
                                                        </label>
                                                    </div>
                                                </div>
                                                @endforeach
                                            </div>

                                        </div>
                                        <div class="mb-3">
                                            <button type="submit" class="btn btn-primary">Update</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

    </div>
</div>
@endsection
