<?php $pageTitle = 'Subscription ended'; require __DIR__ . '/../partials/standalone-head.php'; ?>

<div class="standalone-wrap">
  <div class="d-flex align-items-center gap-2 mb-4">
    <div class="brand-mark" style="background:#D2242A;">!</div>
    <div class="fw-bold fs-5"><?= e($tenant['name'] ?? 'Your company') ?></div>
  </div>

  <div class="standalone-card">
    <h2 class="mb-1">Your subscription has ended</h2>
    <p class="text-muted mb-4">Your team's data is safe and untouched — access is just paused until you renew.</p>

    <?php $errors = \App\Core\Session::getFlash('_errors', []); ?>
    <?php if ($errors): ?>
      <div class="alert alert-danger">
        <ul class="mb-0">
          <?php foreach ($errors as $field => $messages): foreach ((array) $messages as $m): ?>
            <li><?= e($m) ?></li>
          <?php endforeach; endforeach; ?>
        </ul>
      </div>
    <?php endif; ?>

    <?php if (!\App\Core\Auth::check()): ?>
      <div class="alert alert-secondary">Please <a href="<?= base_url('login') ?>">sign in</a> first, then come back here to renew.</div>
    <?php else: ?>
      <?php if ($stripeConfigured): ?>
        <form method="POST" action="<?= base_url('billing/checkout') ?>" class="mb-4">
          <?= csrf_field() ?>
          <button type="submit" class="btn btn-primary w-100"><i class="bi bi-credit-card me-1"></i> Renew with card — 1 year</button>
        </form>
      <?php else: ?>
        <div class="alert alert-secondary small">Card payment isn't set up yet — use a renewal code below, or contact your account manager.</div>
      <?php endif; ?>

      <hr class="my-4">

      <form method="POST" action="<?= base_url('billing/redeem-code') ?>">
        <?= csrf_field() ?>
        <label class="form-label">Have a renewal code?</label>
        <div class="input-group">
          <input type="text" name="code" class="form-control" placeholder="SUB-XXXXXXXXXXXXXXXX" required>
          <button type="submit" class="btn btn-outline-secondary">Redeem</button>
        </div>
      </form>
    <?php endif; ?>
  </div>
</div>

</body>
</html>
