<?php $this->start('body');
    $status = $this->raw('status', 'ok');
    $meta   = $this->raw('apk_meta', []);
    $form   = $this->raw('form', []);
?>

<div class="card-install">
  <div class="app-badge">
    <div class="icon">P</div>
    <div>
      <div style="font-size:16px; font-weight:800;">Pacific Driver</div>
      <div style="font-size:12px; color:#6B7484;">
        v<?= htmlspecialchars($meta['version'] ?? '—'); ?>
        <?php if (!empty($meta['size'])): ?> &middot; <?= number_format($meta['size'] / 1024 / 1024, 0); ?> MB<?php endif; ?>
        <?php if (!empty($meta['built_on'])): ?> &middot; built <?= htmlspecialchars($meta['built_on']); ?><?php endif; ?>
      </div>
    </div>
  </div>

  <?php if ($status === 'not_found'): ?>
    <div class="verdict" style="color:#DC2626;">LINK NOT VALID</div>
    <p class="mt-2 text-muted small">This install link doesn't exist. Ask your dispatcher to send you a new one.</p>

  <?php elseif ($status === 'expired'): ?>
    <div class="verdict" style="color:#B45309;">LINK EXPIRED</div>
    <p class="mt-2 text-muted small">This link has passed its expiry date. Ask your dispatcher to generate a fresh one.</p>

  <?php elseif ($status === 'revoked'): ?>
    <div class="verdict" style="color:#DC2626;">LINK REVOKED</div>
    <p class="mt-2 text-muted small">This link has been cancelled by the office. Contact your dispatcher.</p>

  <?php elseif ($status === 'no_apk'): ?>
    <div class="verdict" style="color:#B45309;">APK NOT YET AVAILABLE</div>
    <p class="mt-2 text-muted small">The mobile app hasn't been built yet on this server. Please check back shortly.</p>

  <?php else: ?>
    <?= $this->raw('fb_msg', ''); ?>
    <div class="verdict" style="color:#0E9F6E;">READY TO INSTALL</div>
    <h5 class="mt-2 mb-3" style="font-weight:700;">Fill in your details, then tap Download.</h5>

    <form method="POST" action="<?= PROOT; ?>Install/save/<?= htmlspecialchars($this->v('token')); ?>">
      <?= csrf_field(); ?>
      <div class="mb-3">
        <label class="form-label small text-muted">Full name <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control" required autocomplete="name"
               value="<?= htmlspecialchars($form['name'] ?? ''); ?>">
      </div>
      <div class="mb-3">
        <label class="form-label small text-muted">Phone <span class="text-danger">*</span></label>
        <input type="tel" name="phone" class="form-control" required autocomplete="tel"
               placeholder="+255 7xx xxx xxx" value="<?= htmlspecialchars($form['phone'] ?? ''); ?>">
      </div>
      <div class="mb-3">
        <label class="form-label small text-muted">Employee number <span class="text-muted small">(if you have one)</span></label>
        <input type="text" name="employee_no" class="form-control"
               value="<?= htmlspecialchars($form['employee_no'] ?? ''); ?>">
      </div>
      <button type="submit" class="btn-install w-100"><i class="fas fa-download me-1"></i>Download APK</button>
    </form>

    <hr class="my-3">
    <div>
      <div style="font-size:11px; letter-spacing:.08em; text-transform:uppercase; color:#6B7484; font-weight:700; margin-bottom: 8px;">How to install</div>
      <div class="step"><span class="n">1</span> Tap <strong>Download APK</strong> above.</div>
      <div class="step"><span class="n">2</span> Open the file when the download finishes.</div>
      <div class="step"><span class="n">3</span> If Android warns "Install unknown apps", tap <strong>Settings</strong> and enable it for your browser.</div>
      <div class="step"><span class="n">4</span> Tap <strong>Install</strong> &middot; open <strong>Pacific Driver</strong> &middot; log in with your phone number.</div>
    </div>
  <?php endif; ?>
</div>
<?php $this->end(); ?>
