<?php $pageTitle = 'Page Types'; require __DIR__ . '/../layout/header.php'; ?>

<div class="d-flex align-items-center justify-content-between mb-4">
  <div>
    <h4 class="fw-bold mb-1">Page Types</h4>
    <p class="text-muted mb-0">Pre-configured content structures for each content format. Assign to topics when adding them.</p>
  </div>
</div>

<div class="row g-3">
  <?php foreach ($pageTypes as $pt): ?>
  <div class="col-md-6 col-xl-4">
    <div class="card border-0 shadow-sm h-100">
      <div class="card-body">
        <div class="d-flex align-items-start justify-content-between mb-2">
          <div>
            <h5 class="fw-bold mb-0"><?= htmlspecialchars($pt['name']) ?></h5>
            <span class="badge <?= $pt['category'] === 'on_page' ? 'bg-primary-subtle text-primary' : 'bg-info-subtle text-info' ?> mt-1">
              <?= htmlspecialchars($pt['category']) ?>
            </span>
          </div>
          <span class="badge <?= $pt['is_active'] ? 'bg-success-subtle text-success' : 'bg-secondary-subtle text-secondary' ?>">
            <?= $pt['is_active'] ? 'Active' : 'Inactive' ?>
          </span>
        </div>

        <?php if ($pt['description']): ?>
        <p class="text-muted small mb-3"><?= htmlspecialchars($pt['description']) ?></p>
        <?php endif; ?>

        <div class="d-flex gap-2 mb-3">
          <span class="badge bg-light text-dark border small"><i class="bi bi-123 me-1"></i>Min: <?= number_format($pt['min_word_count']) ?></span>
          <span class="badge bg-light text-dark border small"><i class="bi bi-123 me-1"></i>Max: <?= number_format($pt['max_word_count']) ?></span>
        </div>

        <?php if (!empty($pt['content_blocks'])): ?>
        <div class="mb-2">
          <div class="text-muted" style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;">Content Blocks</div>
          <div class="d-flex flex-wrap gap-1 mt-1">
            <?php foreach ($pt['content_blocks'] as $block => $cfg): ?>
            <span class="badge bg-<?= isset($cfg['required']) && $cfg['required'] ? 'primary' : 'secondary' ?>-subtle text-<?= isset($cfg['required']) && $cfg['required'] ? 'primary' : 'secondary' ?> small">
              <?= htmlspecialchars($block) ?>
            </span>
            <?php endforeach; ?>
          </div>
        </div>
        <?php endif; ?>

        <div class="border-top pt-2 mt-2">
          <a href="<?= BASE_URL ?>/templates?page_type_id=<?= $pt['id'] ?>" class="btn btn-sm btn-outline-primary">
            <i class="bi bi-chat-square-text me-1"></i>View Templates
          </a>
        </div>
      </div>
    </div>
  </div>
  <?php endforeach; ?>
</div>

<?php require __DIR__ . '/../layout/footer.php'; ?>
