<?php $this->start('body'); ?>
<?php $r = $this->data['r']; ?>

<div class="d-flex align-items-center justify-content-between mb-3 flex-wrap gap-2">
  <div>
    <h5 class="mb-0 fw-semibold"><i class="fas fa-route me-2 text-muted"></i><?= htmlspecialchars($r['name']); ?>
      <?php if (!$r['active']): ?><span class="badge bg-secondary ms-2" style="font-size:.65em;vertical-align:middle;">Inactive</span><?php endif; ?>
    </h5>
    <div class="text-muted small">
      <?php if ($r['code']): ?><span class="font-monospace"><?= htmlspecialchars($r['code']); ?></span> · <?php endif; ?>
      <?= htmlspecialchars(ucfirst(str_replace('_',' ',$r['route_type']))); ?>
    </div>
  </div>
  <div class="d-flex gap-2">
    <a href="<?= PROOT; ?>Routes" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i>Back</a>
    <a href="<?= PROOT; ?>Routes/edit/<?= (int)$r['c0d']; ?>" class="btn btn-sm btn-primary"><i class="fas fa-pen me-1"></i>Edit</a>
  </div>
</div>

<?= flashHtml(); ?>

<div class="row g-3">
  <div class="col-lg-5">
    <div class="card border-0 shadow-sm h-100">
      <div class="card-body">
        <h6 class="text-uppercase text-muted small mb-3">Route Details</h6>
        <dl class="row mb-0">
          <dt class="col-5 text-muted fw-normal">Origin</dt>     <dd class="col-7"><?= htmlspecialchars($r['origin_city']      ?: '—'); ?></dd>
          <dt class="col-5 text-muted fw-normal">Destination</dt><dd class="col-7"><?= htmlspecialchars($r['destination_city'] ?: '—'); ?></dd>
          <dt class="col-5 text-muted fw-normal">Distance</dt>   <dd class="col-7"><?= $r['distance_km']      ? number_format((float)$r['distance_km'], 1) . ' km'  : '—'; ?></dd>
          <dt class="col-5 text-muted fw-normal">Avg duration</dt><dd class="col-7"><?= $r['avg_duration_hrs'] ? number_format((float)$r['avg_duration_hrs'], 1) . ' hrs' : '—'; ?></dd>
          <dt class="col-5 text-muted fw-normal">Type</dt>       <dd class="col-7"><?= htmlspecialchars(ucfirst(str_replace('_',' ',$r['route_type']))); ?></dd>
        </dl>
      </div>
    </div>
  </div>

  <div class="col-lg-7">
    <div class="card border-0 shadow-sm mb-3">
      <div class="card-body">
        <h6 class="text-uppercase text-muted small mb-3"><i class="fas fa-map-marked-alt me-1"></i>Stops &amp; Waypoints</h6>
        <?php if (empty(trim((string)$r['stops_summary']))): ?>
          <p class="text-muted small mb-0 fst-italic">No stops recorded.</p>
        <?php else: ?>
          <ol class="mb-0 ps-3">
            <?php foreach (preg_split('/\r?\n/', trim((string)$r['stops_summary'])) as $stop): if (trim($stop) === '') continue; ?>
              <li class="mb-1"><?= htmlspecialchars($stop); ?></li>
            <?php endforeach; ?>
          </ol>
        <?php endif; ?>
      </div>
    </div>

    <?php if (!empty($r['notes'])): ?>
      <div class="card border-0 shadow-sm">
        <div class="card-body">
          <h6 class="text-uppercase text-muted small mb-2">Notes</h6>
          <p class="mb-0"><?= nl2br(htmlspecialchars($r['notes'])); ?></p>
        </div>
      </div>
    <?php endif; ?>
  </div>
</div>

<?php $this->end(); ?>
