<?php
use function App\Core\{e, url};

$heading = $heading ?? 'Modlar';
$mods = $mods ?? [];
$q = $q ?? '';
$sort = $sort ?? 'newest';
$sortOptions = [
    'newest' => 'En yeni',
    'downloaded' => 'En cok indirilen',
    'viewed' => 'En cok goruntulenen',
    'popular' => 'Populer',
    'premium' => 'Premium',
    'free' => 'Ucretsiz',
];
?>
<section class="container section list-header">
    <div>
        <p class="eyebrow">Zalorox Mods</p>
        <h1><?= e($heading) ?></h1>
    </div>
    <form class="list-search" action="<?= url('/arama') ?>">
        <input name="q" value="<?= e($q) ?>" placeholder="Mod, kategori veya creator ara..." aria-label="Mod ara">
        <input type="hidden" name="sirala" value="<?= e($sort) ?>">
        <button class="pill primary" type="submit">Ara</button>
    </form>
</section>

<section class="container section">
    <div class="chips filter-bar" aria-label="Siralama">
        <?php foreach ($sortOptions as $key => $label): ?>
            <?php $query = http_build_query(['q' => $q, 'sirala' => $key]); ?>
            <a class="<?= $sort === $key ? 'is-active' : '' ?>" href="<?= url('/arama?' . $query) ?>"><?= e($label) ?></a>
        <?php endforeach; ?>
    </div>
</section>

<section class="container section">
    <?php if (!empty($mods)): ?>
        <div class="grid mods">
            <?php foreach ($mods as $mod): ?>
                <?php require BASE_PATH . '/app/Views/partials/mod-card.php'; ?>
            <?php endforeach; ?>
        </div>
    <?php else: ?>
        <div class="empty-state">
            <strong>Sonuc bulunamadi.</strong>
            <p>Farkli bir arama veya siralama deneyebilirsin.</p>
        </div>
    <?php endif; ?>
</section>
