@extends('layouts.app')
@section('htmlheader_title')
	Link
@endsection

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

		<input type="hidden" id="address_id" name="address_id">

		<div class="row">
			<div class="col-12">
				<div class="greyframe titledbox shadow0xb0">
					<h2 class="cap">Enter your Link code</h2>

					<!-- SYSTEM -->
					<div class="row">
						<!-- Name -->
						<div class="col-5">
							<label for="system" class="form-label">BBS Name</label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-laptop-fill"></i></span>
								<select style="width: 80%;" class="form-select @error('system_id') is-invalid @enderror" id="system" name="address_id" required>
									<option value="">&nbsp;</option>
									@foreach (\App\Models\Address::select(['addresses.id','addresses.host_id','addresses.node_id','addresses.point_id','addresses.zone_id','systems.name'])
										->active()
										->join('systems',['systems.id'=>'addresses.system_id'])
										->whereRaw('systems.id NOT IN (SELECT system_id FROM system_user)')
										->with(['zone'])
										->orderBy('systems.name')
										->get() as $oo)
										<option value="{{ $oo->id }}" @if(old('id')===$oo->id)selected @endif>{{ $oo->name }} ({{ $oo->ftn3d }})</option>
									@endforeach
								</select>
								<span class="invalid-feedback" role="alert">
									@error('system_id')
										{{ $message }}
									@else
										BBS Name is required.
									@enderror
								</span>
							</div>
						</div>
					</div>

					<!-- CODE -->
					<div class="row">
						<div class="col-4">
							<label for="code" class="form-label">Code</label>
							<div class="input-group has-validation">
								<span class="input-group-text"><i class="bi bi-fingerprint"></i></span>
								<input type="text" class="form-control @error('code') is-invalid @enderror" id="code" placeholder="Code" name="code" value="{{ old('code') }}" required>
								<span class="invalid-feedback" role="alert">
									@error('code')
										{{ $message }}
									@else
										A code is required.
									@enderror
								</span>
							</div>
						</div>
					</div>

					<div class="row">
						<div class="col-12">
							<a href="{{ url('home') }}" class="btn btn-danger">Cancel</a>
							<button type="submit" name="submit" class="btn btn-success float-end">Validate</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
@endsection

@section('page-css')
	@css('select2')
@append
@section('page-scripts')
	@js('select2')
	<script type="text/javascript">
		$(document).ready(function() {
			$('#system').select2({
				placeholder: 'Find your Address',
			});
		});
	</script>
@endsection