@extends('layouts.app')
@section('title', ($isNew?'New ':'Edit ').'Role')
@section('crumbs', '<a href="'.route('roles.index').'">Roles</a> · <b>'.($isNew?'New':'Edit').'</b>')
@section('content')
<div class="card"><div class="card-h"><h2>{{ $isNew?'New':'Edit' }} role</h2></div>
<div class="card-b"><form method="POST" action="{{ $isNew?route('roles.store'):route('roles.update',$role->id) }}">@csrf @if(!$isNew)@method('PUT')@endif
<div class="frow">
<div class="fld c4"><label>Name *</label><input type="text" name="name" value="{{ old('name',$role->name) }}" required></div>
<div class="fld c4"><label>Slug *</label><input type="text" name="slug" value="{{ old('slug',$role->slug) }}" {{ $isNew?'required':'disabled' }} placeholder="e.g. quarry-manager"></div>
<div class="fld c4"><label>Description</label><input type="text" name="description" value="{{ old('description',$role->description) }}"></div>
</div>
<h3>Permissions</h3>
@foreach($matrix as $mod => $perms)
<div class="perm-mod"><h4>{{ ucfirst($mod) }} <button type="button" class="link-btn" data-check-all data-on="0" style="float:right">Check all</button></h4>
<div class="picks">@foreach($perms as $p)<label><input type="checkbox" name="permissions[]" value="{{ $p->id }}" {{ in_array($p->id,$checked)?'checked':'' }} {{ $role->is_system?'disabled':'' }}> {{ $p->label }}</label>@endforeach</div></div>
@endforeach
@if($role->is_system)<p class="muted small">System role permissions are locked.</p>@endif
<button class="btn btn-pri">Save role</button> <a class="btn btn-ghost" href="{{ route('roles.index') }}">Cancel</a>
</form></div></div>
@endsection
