@extends('layouts.app')

@section('content')
<div class="container">
    <h2>Asignar Permisos al Rol: <b>{{ $role->name }}</b></h2>

    <form action="{{ route('roles.permissions.sync', $role) }}" method="POST">
        @csrf

        <div class="row">
            @foreach($permissions as $permission)
                <div class="col-md-4 mb-2">
                    <div class="form-check">
                        <input 
                            type="checkbox"
                            name="permissions[]"
                            value="{{ $permission->name }}"
                            class="form-check-input"
                            id="perm{{ $permission->id }}"
                            @checked(in_array($permission->id, $rolePermissions))
                        >

                        <label class="form-check-label" for="perm{{ $permission->id }}">
                            {{ $permission->name }}
                        </label>
                    </div>
                </div>
            @endforeach
        </div>

        <button class="btn btn-success mt-3">Guardar Permisos</button>
        <a href="{{ route('roles.index') }}" class="btn btn-secondary mt-3">
            Regresar
        </a>
    </form>
</div>
@endsection
