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

<div class="row g-3">
  <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">Fleet utilisation</h6>
        <a href="<?= PROOT; ?>Trucks" class="small text-decoration-none">Trucks &rarr;</a>
      </div>
      <div id="c-util" style="min-height: 260px;"></div>
    </div></div>
  </div>
  <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">Km driven per truck &middot; last 30 days</h6>
        <a href="<?= PROOT; ?>FleetAnalytics" class="small text-decoration-none">Analytics &rarr;</a>
      </div>
      <div id="c-km" 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">Compliance composition</h6>
        <a href="<?= PROOT; ?>DocExpiries" class="small text-decoration-none">Docs &rarr;</a>
      </div>
      <div id="c-docs" 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">Trip departures &middot; day &times; hour</h6>
        <a href="<?= PROOT; ?>Trips" class="small text-decoration-none">Trips &rarr;</a>
      </div>
      <div id="c-heat" style="min-height: 260px;"></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_compliance.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">Fleet shortcuts</h6>
      <div class="d-flex flex-wrap gap-2">
        <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; ?>PmDashboard" class="btn btn-sm btn-outline-primary"><i class="fas fa-tools me-1"></i>PM due</a>
        <a href="<?= PROOT; ?>WorkRequests" class="btn btn-sm btn-outline-primary"><i class="fas fa-hand-paper me-1"></i>Work requests</a>
        <a href="<?= PROOT; ?>WorkOrders" class="btn btn-sm btn-outline-primary"><i class="fas fa-wrench me-1"></i>Work orders</a>
        <a href="<?= PROOT; ?>DocExpiries" class="btn btn-sm btn-outline-primary"><i class="fas fa-file-signature me-1"></i>Doc expiries</a>
        <a href="<?= PROOT; ?>DriverAssignments" class="btn btn-sm btn-outline-primary"><i class="fas fa-exchange-alt me-1"></i>Assignments</a>
      </div>
    </div></div>
  </div>
</div>

<?php $this->end(); $this->start('section_js'); ?>
<script>
document.addEventListener('DOMContentLoaded', function () {
  new PacificChart('#c-util', 'radialBar',
    <?= json_encode($this->data['charts']['util'] ?? []); ?>);
  new PacificChart('#c-km',   'bar',
    <?= json_encode(array_merge($this->data['charts']['km']   ?? [], ['distributed' => true, 'colors' => 'penta'])); ?>);
  new PacificChart('#c-docs', 'donut',
    <?= json_encode(array_merge($this->data['charts']['docs'] ?? [], ['colors' => ['#0E9F6E','#F59E0B','#DC2626']])); ?>);
  new PacificChart('#c-heat', 'heatmap',
    <?= json_encode($this->data['charts']['heat'] ?? []); ?>);
});
</script>
<?php $this->end(); ?>
