<?php $pageTitle='Dispatch Board'; ?>
<div class="panel dispatch-board-panel">
<div class="panel-header"><div><p class="eyebrow">Carrier Dispatch</p><h2>Visual Dispatch Board</h2><p class="muted">Manage external carriers, owner-operators, reefer requirements, and load status from one board.</p></div><div class="page-actions"><a class="btn btn-light" href="<?= url('/carriers') ?>">Carrier Network</a><a class="btn btn-primary" href="<?= url('/loads/create') ?>">Add Load</a></div></div>
<div class="kanban-board">
<?php foreach($board as $status=>$loads): ?><div class="kanban-column"><div class="kanban-title"><span><?= e(readable_status($status)) ?></span><strong><?= count($loads) ?></strong></div><div class="kanban-list">
<?php foreach($loads as $load): ?><article class="load-card <?= !empty($load['temperature_controlled'])?'load-card-reefer':'' ?>">
<div class="load-card-top"><strong><?= e($load['load_number']) ?></strong><span><?= money($load['dispatch_fee_amount']) ?> fee</span></div>
<p><?= e($load['pickup_location']) ?> → <?= e($load['delivery_location']) ?></p>
<div class="load-card-carrier"><strong><?= e($load['carrier_name']??'Carrier unassigned') ?></strong><span><?= e($load['driver_name']??'Driver unassigned') ?></span></div>
<small><?= e($load['truck_number']??'-') ?> · <?= e($load['trailer_number']??'-') ?> · <?= e(datetime_display($load['pickup_datetime']??null)) ?></small>
<div class="load-card-flags"><span><?= e(readable_status($load['carrier_confirmation_status']??'not_sent')) ?></span><?php if(!empty($load['temperature_controlled'])): ?><span class="reefer-badge">Reefer <?= e((string)$load['temperature_setpoint'].($load['temperature_unit']??'F')) ?></span><?php endif; ?></div>
<form method="post" action="<?= url('/loads/status') ?>" class="status-form"><?= csrf_field() ?><input type="hidden" name="id" value="<?= e((string)$load['id']) ?>"><select name="status" onchange="this.form.submit()"><?php foreach(Load::STATUSES as $option): ?><option value="<?= e($option) ?>" <?= $status===$option?'selected':'' ?>><?= e(readable_status($option)) ?></option><?php endforeach; ?></select></form>
<div class="load-card-links"><?php if(!empty($load['current_latitude'])&&!empty($load['current_longitude'])): ?><a target="_blank" rel="noopener" href="https://www.google.com/maps?q=<?= e((string)$load['current_latitude']) ?>,<?= e((string)$load['current_longitude']) ?>">Location</a><?php endif; ?><a href="<?= url('/loads/edit?id='.$load['id']) ?>">Open load</a></div>
</article><?php endforeach; ?><?php if(!$loads): ?><div class="empty-card">No loads</div><?php endif; ?></div></div><?php endforeach; ?>
</div></div>
