<?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=[]; ?>
<style>
.fan-card{background:rgba(59,43,32,.95);border:2px solid var(--accent-color);border-radius:18px;padding:1.2rem;height:100%;box-shadow:0 10px 24px rgba(0,0,0,.26);display:flex;flex-direction:column;}
.fan-card img{width:100%;height:220px;object-fit:contain;background:rgba(0,0,0,.28);border:2px solid var(--accent-color);border-radius:14px;padding:.35rem;}
.fan-card h4{margin:1rem 0 .35rem;}
.fan-card p{color:#fff;flex:1;}
.fan-badge{display:inline-block;margin-bottom:.6rem;padding:.28rem .7rem;border-radius:999px;background:rgba(0,204,136,.18);border:1px solid rgba(0,204,136,.45);color:var(--accent-color);font-weight:700;}
</style>
<div class="container content-box mt-5"><div class="text-center mb-5"><h1>Fans & Supporters</h1><p class="subtext">A shoutout to the people who back Home Time Radio</p></div><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="fan-card"><?php if($img): ?><img src="<?= htmlspecialchars($img, ENT_QUOTES, 'UTF-8') ?>" alt="<?= htmlspecialchars((string)($fan['name']??''), ENT_QUOTES, 'UTF-8') ?>"><?php endif; ?><?php if(!empty($fan['top_fan'])): ?><span class="fan-badge">Top Fan</span><?php endif; ?><h4><?= 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>Visit one of our broadcast friends and check out what they are playing.</p><?php endif; ?><?php if($link): ?><a class="btn btn-dark" target="_blank" rel="noopener" href="<?= htmlspecialchars((string)$link, ENT_QUOTES, 'UTF-8') ?>">Visit</a><?php endif; ?></div></div><?php endforeach; ?><?php if(empty($fans)): ?><div class="col-12"><div class="dj-box">No fan entries yet. Add them from the admin area and they will appear here with their images.</div></div><?php endif; ?></div></div><?php include 'includes/footer.php'; ?>
