<?php
$section = $section ?? 'index';
$dirty = !empty($dirty);
$canUndo = !empty($canUndo);
$publishedAt = $publishedAt ?? null;
$steps = [
    ['index', 'Industry', 'bi-buildings', 'setup'],
    ['names', 'Names', 'bi-type', 'setup/names'],
    ['stages', 'Stages', 'bi-kanban', 'setup/stages'],
    ['fields', 'Fields', 'bi-input-cursor-text', 'setup/fields'],
    ['forms', 'Forms', 'bi-ui-checks-grid', 'setup/forms'],
    ['alerts', 'Alerts', 'bi-lightning-charge', 'setup/alerts'],
    ['dashboard', 'Home cards', 'bi-grid-1x2', 'setup/dashboard'],
    ['permissions', 'Permissions', 'bi-shield-check', 'setup/permissions'],
];
?>
<div class="sup-head">
  <div>
    <h1 class="page-title">Setup</h1>
    <p class="page-sub mb-0">Change words, stages, boxes, and who sees what. Staff only see it after you publish.</p>
  </div>
  <div class="sup-actions">
    <?php if ($publishedAt): ?>
      <span class="sup-stamp">Published <?= e(dt_fmt($publishedAt, 'M j, g:i A')) ?></span>
    <?php endif; ?>
    <?php if ($canUndo): ?>
      <form class="ajax-form" action="<?= e(url('setup/undo')) ?>" method="post">
        <?= csrf_field() ?>
        <button class="btn btn-outline-secondary" type="submit">Undo last publish</button>
      </form>
    <?php endif; ?>
    <form class="ajax-form" action="<?= e(url('setup/publish')) ?>" method="post">
      <?= csrf_field() ?>
      <button class="btn btn-primary" type="submit" <?= $dirty ? '' : 'disabled' ?>><?= $dirty ? 'Publish' : 'Published' ?></button>
    </form>
  </div>
</div>
<?php if ($dirty): ?>
  <div class="sup-draft">Draft changes are waiting. Publish to show them to everyone else.</div>
<?php endif; ?>
<nav class="sup-steps" aria-label="Setup path">
  <?php foreach ($steps as $i => $s): ?>
    <a class="sup-step <?= $section === $s[0] ? 'is-on' : '' ?>" href="<?= e(url($s[3])) ?>">
      <span class="sup-step-n"><?= $i + 1 ?></span>
      <i class="bi <?= e($s[2]) ?>"></i>
      <?= e($s[1]) ?>
    </a>
  <?php endforeach; ?>
</nav>
