<?php include __DIR__ . '/../header.php'; ?>
<?php include __DIR__ . '/../menu.php'; ?>
<link rel="stylesheet" href="/css/style.css">

<main class="main-container">
  <section class="friends-list">
    <h2 class="text-warning">🤝 Our Friends & Partners</h2>
    <p class="mb-4">These are the communities and partners who stand with Almost Heaven Radio.</p>

    <?php
      $friends_file = __DIR__ . '/../data/friends.json';
      $friends = file_exists($friends_file) ? json_decode(file_get_contents($friends_file), true) : [];
    ?>

    <div class="friends-grid">
      <?php foreach ($friends as $friend): ?>
        <div class="friend-card">
          <?php if (!empty($friend['image'])): ?>
            <a href="<?= htmlspecialchars($friend['url']) ?>" target="_blank">
              <img src="<?= htmlspecialchars($friend['image']) ?>" 
                   alt="<?= htmlspecialchars($friend['name']) ?>" 
                   class="friend-photo">
            </a>
          <?php endif; ?>
          <h4>
            <a href="<?= htmlspecialchars($friend['url']) ?>" target="_blank">
              <?= htmlspecialchars($friend['name']) ?>
            </a>
          </h4>
          <p><?= nl2br(htmlspecialchars($friend['description'])) ?></p>
          <div class="mt-2">
            <a href="<?= htmlspecialchars($friend['url']) ?>" target="_blank" class="btn btn-sm btn-dark">
              Visit Site
            </a>
          </div>
        </div>
        <hr class="friend-divider">
      <?php endforeach; ?>
    </div>
  </section>
</main>

<?php include __DIR__ . '/../footer.php'; ?>
