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

@section('htmlheader_title')
	Address Merge
@endsection

@section('content')
	<div class="row pt-0">
		<div class="col-12">
			<h2>Merge Address {{ $o->ftn }}</h2>
			<p>{{ $o->system->sysop }} : {{ $o->system->name }}</p>
		</div>

		<div class="col-12">
			<form method="POST">
				@csrf

				<table class="table monotable">
					<thead>
					<tr>
						<th>F</th>
						<th>T</th>
						<th>ID</th>
						<th>FTN</th>
						<th>ACTIVE</th>
						<th>Messages</th>
					</tr>
					</thead>

					<tbody>
					@foreach ($oo as $ao)
						<tr>
							<td><input type="radio" name="src" value="{{ $ao->id }}"></td>
							<td><input type="radio" name="dst" value="{{ $ao->id }}"></td>
							<th>{{ $ao->id }} {{ $ao->system_id }}:<a href="{{ url('system/addedit',$ao->system_id) }}">{{ $ao->system->name }}</a></th>
							<th>{{ $ao->ftn }}</th>
							<td>
								@if($ao->trashed())
									<a href="{{ url('system/address/rec',[$ao->id]) }}" title="Restore Address"><i class="bi bi-bandaid"></i></a>
									<a href="{{ url('system/address/pur',[$ao->id]) }}" title="Purge Address" class="purge"><i class="bi bi-scissors"></i></a>
								@else
									<a href="{{ url('system/address/sus',[$ao->id]) }}" title="@if($ao->active)Pause @else Activate @endif Address"><i class="bi @if($ao->active)bi-pause-circle @else bi-play-circle @endif"></i></a>
									<a href="{{ url('system/address/mov',[$ao->system_id,$ao->id]) }}" title="Move Address to another System"><i class="bi bi-arrow-right-square"></i></a>
									<a href="{{ url('system/address/del',[$ao->id]) }}" title="Delete Address"><i class="bi bi-trash"></i></a>
								@endif
							</td>
							<td>
								<ul>
									@foreach(\App\Models\Echomail::select(['id','msgid','from','msg','echoarea_id'])
										->where('fftn_id',$ao->id)
										->orderBy('created_at','DESC')
										->with('echoarea')
										->limit(5)
										->get() as $eo)
										<li class="pb-4">{{ sprintf('%s-%04d: %s (%s) %s',$eo->echoarea->name,$eo->id,$eo->from,$eo->msgid,$eo->msg) }}</li>
									@endforeach
								</ul>
							</td>
						</tr>
					@endforeach
					</tbody>
				</table>

				<button type="submit" name="submit" class="btn btn-success float-end">Merge</button>
			</form>
		</div>

		@include('error')
	</div>
@endsection