<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/restaurants.php';
require_once __DIR__ . '/includes/settings.php';

$minReviews = get_setting_int('restaurant_ranking_min_reviews');
$ranking = get_restaurant_ranking($minReviews);

$pageTitle = 'Etterem-ranglista — ' . GK_SITE_NAME;
require __DIR__ . '/includes/layout_top.php';
?>
<div class="gk">
  <section class="section ranking-section">
    <div class="section-heading compact">
      <div>
        <span class="kicker">ETTEREM-RANGLISTA</span>
        <h2>Az 5 szempont atlaga<br><em>alapjan, csokkeno sorrendben.</em></h2>
      </div>
      <p>Csak a legalabb <?= $minReviews ?> ertekelessel rendelkezo ettermek szerepelnek.</p>
    </div>

    <?php if (count($ranking) === 0): ?>
      <p style="color:var(--muted)">Meg egyetlen etterem sem eri el a <?= $minReviews ?> ertekeleses kuszobot.</p>
    <?php else: ?>
      <div class="ranking-table">
        <div class="ranking-head"><span>Helyezes</span><span>Etterem</span><span>Ertekelesek</span><span>Pont</span></div>
        <?php foreach ($ranking as $i => $a): $rank = $i + 1; ?>
          <div class="ranking-row">
            <span class="place place-<?= $rank ?>"><?= $rank ?></span>
            <span class="rank-user">
              <span>
                <a href="/etterem.php?id=<?= urlencode($a['restaurant']['id']) ?>" style="text-decoration:underline">
                  <strong><?= h($a['restaurant']['canonical_name']) ?></strong>
                </a>
                <small><?= h($a['restaurant']['city'] ?? '') ?></small>
              </span>
            </span>
            <span class="rank-badge"><?= $a['reviewCount'] ?> ertekeles</span>
            <strong class="rank-score"><?= $a['overallScore'] !== null ? number_format($a['overallScore'], 2, '.', '') : '' ?></strong>
          </div>
        <?php endforeach; ?>
      </div>
    <?php endif; ?>
  </section>
</div>
<?php require __DIR__ . '/includes/layout_bottom.php'; ?>
