<!-- $o=Account::class -->
@use(App\Models\Supplier)

<!-- Suppliers Configuration for this User -->
<div class="row">
	<div class="col-6">
		<div class="card">
			<div class="card-body">
				<x-leenooks::button.success class="float-right"/>

				<table class="table">
					<thead>
					<tr>
						<th>Supplier</th>
						<th>ID</th>
						<th>Added</th>
					</tr>
					</thead>

					<tbody>
					@foreach ($o->suppliers as $so)
						<tr>
							<td>{{ $so->name }}</td>
							<td>{{ $so->pivot->supplier_ref }}</td>
							<td>{{ $so->pivot->created_at }} <a class="float-right" href="{{ url('a/account/supplier/delete',[$o->id,$so->id]) }}"><i class="fas fa-fw fa-trash"></i></a></td>
						</tr>
					@endforeach
					</tbody>

					@if(($x=Supplier::active()->whereNotIn('id',$o->suppliers->pluck('id'))->orderBy(DB::raw('UPPER(name)'))->get())->count())
						<tfoot>
						<tr>
							<td colspan="3">
								<form method="POST" action="{{ url('a/account/supplier/add',[$o->id]) }}">
									@csrf

									<div class="row">
										<div class="col-6">
											<x-leenooks::form.select id="supplier_id" name="supplier_id" icon="fa-handshake" label="Add Supplier" :options="$x->map(fn($item)=>['id'=>$item->id,'value'=>$item->name])"/>
										</div>

										<div class="col-4">
											<x-leenooks::form.text id="supplier_ref" name="supplier_ref" icon="fa-hashtag" label="ID"/>
										</div>

										<div class="col-2">
											<x-leenooks::button.submit class="float-right">Save</x-leenooks::button.submit>
										</div>
									</div>
								</form>
							</td>
						</tr>
						</tfoot>
					@endif
				</table>
			</div>
		</div>
	</div>
</div>