<?php $this->start('body');
    include __DIR__ . '/_dash_header.php';
    include __DIR__ . '/_kpi_strip.php';
?>

<div class="row g-3">
  <div class="col-lg-8">
    <div class="card border-0 shadow-sm h-100"><div class="card-body">
      <div class="d-flex justify-content-between align-items-baseline mb-2">
        <h6 class="text-uppercase text-muted small mb-0">Trip pipeline &middot; request → closed</h6>
        <a href="<?= PROOT; ?>Trips" class="small text-decoration-none">Trips &rarr;</a>
      </div>
      <div id="c-funnel" style="min-height: 260px;"></div>
    </div></div>
  </div>
  <div class="col-lg-4">
    <div class="card border-0 shadow-sm h-100"><div class="card-body">
      <div class="d-flex justify-content-between align-items-baseline mb-2">
        <h6 class="text-uppercase text-muted small mb-0">On-time delivery &middot; 30 d</h6>
        <a href="<?= PROOT; ?>FleetAnalytics" class="small text-decoration-none">Analytics &rarr;</a>
      </div>
      <div id="c-ontime" style="min-height: 260px;"></div>
    </div></div>
  </div>
</div>

<div class="row g-3 mt-1">
  <div class="col-lg-5">
    <div class="card border-0 shadow-sm h-100"><div class="card-body">
      <div class="d-flex justify-content-between align-items-baseline mb-2">
        <h6 class="text-uppercase text-muted small mb-0">Top customers &middot; open trips</h6>
        <a href="<?= PROOT; ?>Customers" class="small text-decoration-none">Customers &rarr;</a>
      </div>
      <div id="c-cust" style="min-height: 260px;"></div>
    </div></div>
  </div>
  <div class="col-lg-7">
    <div class="card border-0 shadow-sm h-100"><div class="card-body">
      <div class="d-flex justify-content-between align-items-baseline mb-2">
        <h6 class="text-uppercase text-muted small mb-0">Today's schedule (Gantt)</h6>
        <a href="<?= PROOT; ?>GpsDashboard" class="small text-decoration-none">Live map &rarr;</a>
      </div>
      <div id="c-gantt" style="min-height: 300px;"></div>
    </div></div>
  </div>
</div>

<!-- Zone 3 · Attention + Zone 4 · Activity -->
<div class="row g-3 mt-1">
  <div class="col-lg-6"><?php include __DIR__ . '/_feed_requests.php'; ?></div>
  <div class="col-lg-6"><?php include __DIR__ . '/_feed_trips.php'; ?></div>
</div>

<div class="row g-3 mt-1">
  <div class="col-12">
    <div class="card border-0 shadow-sm"><div class="card-body">
      <h6 class="text-uppercase text-muted small mb-3">Dispatch shortcuts</h6>
      <div class="d-flex flex-wrap gap-2">
        <a href="<?= PROOT; ?>TripRequests" class="btn btn-sm btn-outline-primary"><i class="fas fa-inbox me-1"></i>Trip requests</a>
        <a href="<?= PROOT; ?>Trips" class="btn btn-sm btn-outline-primary"><i class="fas fa-truck me-1"></i>Trips</a>
        <a href="<?= PROOT; ?>DriverAssignments" class="btn btn-sm btn-outline-primary"><i class="fas fa-exchange-alt me-1"></i>Assignments</a>
        <a href="<?= PROOT; ?>GpsDashboard" class="btn btn-sm btn-outline-primary"><i class="fas fa-map-marked-alt me-1"></i>Live map</a>
        <a href="<?= PROOT; ?>Routes" class="btn btn-sm btn-outline-primary"><i class="fas fa-route me-1"></i>Routes</a>
      </div>
    </div></div>
  </div>
</div>

<?php $this->end(); $this->start('section_js'); ?>
<script>
document.addEventListener('DOMContentLoaded', function () {
  new PacificChart('#c-funnel', 'bar',
    <?= json_encode(array_merge($this->data['charts']['funnel'] ?? [], ['horizontal' => true, 'distributed' => true, 'colors' => 'penta'])); ?>);
  new PacificChart('#c-ontime', 'radialBar',
    <?= json_encode($this->data['charts']['ontime'] ?? []); ?>);
  new PacificChart('#c-cust',   'bar',
    <?= json_encode(array_merge($this->data['charts']['cust'] ?? [], ['horizontal' => true, 'distributed' => true, 'colors' => 'penta'])); ?>);
  new PacificChart('#c-gantt',  'rangeBar',
    <?= json_encode(array_merge($this->data['charts']['gantt'] ?? [], ['xaxis' => ['type' => 'datetime']])); ?>);
});
</script>
<?php $this->end(); ?>
