<form action="{{ route('admin.access.roles.update-store', $role->id) }}" method="POST">
    @csrf

    <div class="form-group">
        <label>@lang('Name')</label>
        <input type="text" class="form-control" name="name" value="{{ $role->name }}" required>
    </div>

    <div class="form-group">
        <label for="permissions">@lang('Permissions')</label>
        <select class="form-control select2-multiple" name="permissions[]" multiple="multiple" id="permissions"
            size="5">
            @foreach ($permissions as $permission)
                <option value="{{ $permission->id }}"
                    {{ in_array($permission->id, $rolePermissions) ? 'selected' : '' }}>{{ str($permission->name)->headline() }}</option>
            @endforeach
        </select>
    </div>

    <div class="form-group">
        <button type="submit" class="btn btn--primary w-100">@lang('Submit')</button>
    </div>

</form>

<script>
    $('.select2-multiple').each(function() {
        if ($(this).data('select2')) {
            $(this).select2('destroy');
        }
        $(this).select2({
            placeholder: 'Select an option',
            allowClear: true,
            width: '100%'
        });
    });
</script>
