<x-admin-panel-layout>
    <x-slot name="title">
        تعریف دسترسی جدید
    </x-slot>
    <x-slot name="main">
        <!-- Checked checkbox -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0 text-dark">ایجاد دسترسی جدید</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-left">
                            <li class="breadcrumb-item"><a href="{{ route("admin.dashboard") }}">داشبورد</a></li>

                            <li class="breadcrumb-item active">ایجاد دسترسی</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </div>
        <section class="content mt-sm-3">
            <div class="card p-0 card-primary col-md-8 mx-auto">
                <div class="card-header">
                    <h3 class="card-title">ایجاد نقش</h3>
                </div>
                @if(session()->exists('status'))
                    <div class="alert alert-success col-md-11 mx-auto mt-2" role="alert" id="alertAddCategory">
                        نقش جدید موفقیت ایجاد گردید
                    </div>
            @endif

            <!-- /.card-header -->
                <!-- form start -->
                <form class="mt-3 p-2" action="{{route('role_permission.store')}}" method="post">
                    @csrf
                    <div class="form-group">
                        <input type="text" name='name' class="form-control" id="InputUserName"
                               placeholder="نام نقش" value="{{old('name')}}" required>
                        @error('name')
                        <div class="invalid">
                            <p class="text-danger" style="font-size: 0.8rem;padding-right: 0.2rem">{{$message}}</p>
                        </div>
                        @enderror
                    </div>
                    @error('permissions')
                    <div class="invalid">
                        <p class="text-danger" style="font-size: 0.8rem;padding-right: 0.2rem">{{$message}}</p>
                    </div>
                    @enderror
                    <div class="d-flex flex-wrap col-12">
                    @foreach($permissions as $permission)
                        <div class="form-check col-sm-6 mb-sm-2">
                            <input
                                class="form-check-input"
                                type="checkbox"
                                name="permissions[{{$permission->name}}]"
                                value="{{$permission->name}}"
                                id="flexCheckChecked"
                                @if(is_array(old('permissions')) && array_key_exists($permission->name,old('permissions')))
                                    checked
                                @endif
                            />
                            <label class="form-check-label" for="flexCheckChecked">
                                @lang($permission->name)
                            </label>
                        </div>
                        @endforeach
                    </div>

                    <button type="submit" class="btn btn-primary btn-block mt-3">ثبت</button>
                </form>
            </div>
        </section>
    </x-slot>
</x-admin-panel-layout>
