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

<div class="row">
	<div class="col-4">
		<x-leenooks::form.select name="cost_id" icon="fa-list" label="Supplier Invoice" helper="Supplier invoice" addnew="Add New" :options="Cost::where('supplier_id',$spo->id)->orderBy('billed_at','DESC')->get()->map(fn($item,$key)=>['id'=>$item->id,'value'=>sprintf('%s: $%s',$item->billed_at->format('Y-m-d'),number_format($item->total,2))])"/>
	</div>
</div>

@section('page-scripts')
	<script type="text/javascript">
		$(document).ready(function() {
			$('#cost_id')
				.on('change',function(item) {
					window.location.href = '{{ url('a/supplier/cost') }}/'+(item.target.value !== 'new' ? item.target.value : 'new/'+{{ $spo->id }});
				});
		});
	</script>
@append