<!-- $o=Filearea::class -->
@extends('layouts.app')

@section('htmlheader_title')
	@if($o->exists) Update @else Add @endif Filearea
@endsection

@section('content')
	<form class="needs-validation" method="post" novalidate>
		@csrf

		<div class="row">
			<div class="col-12">
				<div class="greyframe titledbox shadow0xb0">
					<h2 class="cap">@if($o->exists) Update @else Add @endif Filearea</h2>

					<div class="row">
						<div class="col-3">
							<label for="domain" class="form-label">Domain</label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-tag-fill"></i></span>
								<select class="form-select @error('domain_id') is-invalid @enderror" id="domain" name="domain_id" required @cannot('admin',$o)disabled @endcannot>
									<option value="">&nbsp;</option>
									@foreach (\App\Models\Domain::active()->orderBy('name')->cursor() as $oo)
										<option value="{{ $oo->id }}" @if(old('domain_id',$o->domain_id)==$oo->id)selected @endif>{{ $oo->name }}</option>
									@endforeach
								</select>
								<span class="invalid-feedback" role="alert">
									@error('domain_id')
										{{ $message }}
									@else
										A domain is required.
									@enderror
								</span>
								<span class="input-helper">Add a <a href="{{ url('domain/addedit') }}">NEW Domain</a></span>
							</div>
						</div>

						<div class="col-4">
							<label for="name" class="form-label">Name</label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-tag-fill"></i></span>
								<input type="text" class="form-control @error('name') is-invalid @enderror" id="name" placeholder="Name" name="name" value="{{ old('name',$o->name) }}" required @cannot('admin',$o)disabled @endcannot autofocus>
								<span class="invalid-feedback" role="alert">
									@error('name')
										{{ $message }}
									@else
										A name is required.
									@enderror
								</span>
							</div>
						</div>

						<div class="offset-1 col-2" style="padding-left: 20px;">
							<label for="active" class="form-label">Active</label>
							<div class="input-group">
								<div class="btn-group" role="group">
									<input type="radio" class="btn-check" name="active" id="active_yes" value="1" required @cannot('admin',$o)disabled @endcannot @if(old('active',$o->active ?? TRUE))checked @endif>
									<label class="btn btn-outline-success" for="active_yes">Yes</label>

									<input type="radio" class="btn-check btn-danger" name="active" id="active_no" value="0" required @cannot('admin',$o)disabled @endcannot @if(! old('active',$o->active ?? TRUE))checked @endif>
									<label class="btn btn-outline-danger" for="active_no">No</label>
								</div>
							</div>
						</div>

						<div class="col-2">
							<label for="show" class="form-label">Show <i class="bi bi-info-circle" title="Show this area in the activity reports"></i></label>
							<div class="input-group">
								<div class="btn-group" role="group">
									<input type="radio" class="btn-check" name="show" id="show_yes" value="1" required @cannot('admin',$o)disabled @endcannot @if(old('show',$o->show ?? TRUE))checked @endif>
									<label class="btn btn-outline-success" for="show_yes">Yes</label>

									<input type="radio" class="btn-check btn-danger" name="show" id="show_no" value="0" required @cannot('admin',$o)disabled @endcannot @if(! old('show',$o->show ?? TRUE))checked @endif>
									<label class="btn btn-outline-danger" for="show_no">No</label>
								</div>
							</div>
						</div>
					</div>

					<div class="row">
						<div class="col-5">
							<label for="description" class="form-label">Description</label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-file-text-fill"></i></span>
								<input type="text" class="form-control @error('description') is-invalid @enderror" id="description" placeholder="Description" name="description" value="{{ old('description',$o->description) }}" @cannot('admin',$o)disabled @endcannot>
								<span class="invalid-feedback" role="alert">
									@error('description')
										{{ $message }}
									@enderror
								</span>
							</div>
						</div>

						<div class="col-3">
							<label for="nodelist" class="form-label">Nodelist File Name</label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-file-earmark-break-fill"></i></span>
								<input type="text" class="form-control @error('nodelist') is-invalid @enderror" id="nodelist" placeholder="NODELIST.Z??" name="nodelist" value="{{ old('nodelist',$o->domain?->nodelist) }}" @cannot('admin',$o->domain)disabled @endcannot>
								<span class="invalid-feedback" role="alert">
									@error('nodelist')
										{{ $message }}
									@enderror
								</span>
							</div>
						</div>

						<div class="col-2">
							<label for="sec_read" class="form-label">Read <i class="bi bi-info-circle" title="Min security level required for read access"></i></label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-eyeglasses"></i></span>
								<input type="text" class="form-control text-end @error('sec_read') is-invalid @enderror" id="sec_read" placeholder="#" name="sec_read" value="{{ old('sec_read',$o->sec_read) }}" required @cannot('admin',$o)disabled @endcannot autofocus>
								<span class="invalid-feedback" role="alert">
									@error('sec_read')
									{{ $message }}
									@enderror
								</span>
							</div>
						</div>

						<div class="col-2">
							<label for="sec_write" class="form-label">Write <i class="bi bi-info-circle" title="Min security level required for write access"></i></label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-pencil"></i></span>
								<input type="text" class="form-control text-end @error('sec_write') is-invalid @enderror" id="sec_write" placeholder="#" name="sec_write" value="{{ old('sec_write',$o->sec_write) }}" required @cannot('admin',$o)disabled @endcannot autofocus>
								<span class="invalid-feedback" role="alert">
									@error('sec_write')
									{{ $message }}
									@enderror
								</span>
							</div>
						</div>
					</div>

					<div class="row">
						<div class="col-12">
							<label for="notes" class="form-label">Notes</label>
							<textarea class="form-control" rows=3 name="notes" placeholder="Notes..." @cannot('admin',$o)disabled @endcannot>{{ old('notes',$o->notes) }}</textarea>
						</div>
					</div>

					<div class="row">
						<div class="col-12">
							<a href="{{ url('filearea') }}" class="btn btn-danger">Cancel</a>
							@can('admin',$o)
								<button type="submit" name="submit" class="btn btn-success float-end">@if ($o->exists)Save @else Add @endif</button>
							@endcan
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
@endsection