<?php include 'includes/header.php';
function ht_asset_url(string $path, string $fallbackDir = ''): string {
  $path = trim($path);
  if ($path === '') return '';
  if (preg_match('#^(https?:)?//#i', $path) || str_starts_with($path, 'data:')) return $path;
  $path = str_replace('\\', '/', $path);
  $path = ltrim($path, '/');
  if ($fallbackDir !== '' && strpos($path, '/') === false) $path = trim($fallbackDir, '/') . '/' . $path;
  return '/' . $path;
}
$fans=file_exists(__DIR__.'/data/fans.json')?json_decode((string)file_get_contents(__DIR__.'/data/fans.json'),true):[]; if(!is_array($fans))$fans=[]; ?>
<div class="container ugfx-page-shell">
  <section class="ugfx-page-hero-card mb-4">
    <div class="kicker">Community support</div>
    <h1 class="section-title">Fans & Supporters</h1>
    <p class="section-subtitle text-start ms-0">A more premium supporter wall for the people and projects backing the station.</p>
  </section>
  <div class="row g-4">
    <?php foreach($fans as $fan): $img=ht_asset_url((string)($fan['image']??''),'img/fans'); $link=$fan['link'] ?? ($fan['url'] ?? ''); ?>
      <div class="col-md-6 col-xl-4"><div class="ugfx-card h-100 ugfx-photo-card contain">
        <?php if($img): ?><img src="<?= htmlspecialchars($img, ENT_QUOTES, 'UTF-8') ?>" alt="<?= htmlspecialchars((string)($fan['name']??''), ENT_QUOTES, 'UTF-8') ?>"><?php endif; ?>
        <div class="mt-3"><?php if(!empty($fan['top_fan'])): ?><span class="ugfx-meta-pill"><i class="bi bi-stars"></i> Top Fan</span><?php endif; ?></div>
        <h4 class="mt-3"><?= htmlspecialchars((string)($fan['name']??''), ENT_QUOTES, 'UTF-8') ?></h4>
        <?php if (!empty($fan['description'])): ?><p><?= nl2br(htmlspecialchars((string)$fan['description'], ENT_QUOTES, 'UTF-8')) ?></p><?php else: ?><p>Thanks for backing Underground FX Radio.</p><?php endif; ?>
        <?php if($link): ?><div class="mt-3"><a class="btn btn-outline-light" target="_blank" rel="noopener" href="<?= htmlspecialchars((string)$link, ENT_QUOTES, 'UTF-8') ?>">Visit</a></div><?php endif; ?>
      </div></div>
    <?php endforeach; ?>
    <?php if(empty($fans)): ?><div class="col-12"><div class="ugfx-empty-state">No fan entries yet. Add them from the admin area and they will appear here with the new styling.</div></div><?php endif; ?>
  </div>
</div>
<?php include 'includes/footer.php'; ?>