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

if (!is_array($category)) {
    $category = [
        'name' => (string) $category,
        'slug' => strtolower(str_replace([' ', '_'], '-', (string) $category)),
        'description' => '',
        'icon' => '',
        'banner' => '',
        'mod_count' => 0,
    ];
}

$name = $category['name'] ?? 'Kategori';
$slug = $category['slug'] ?? strtolower(str_replace([' ', '_'], '-', $name));
$description = $category['description'] ?? '';
$icon = $category['icon'] ?? '';
$banner = $category['banner'] ?? '';
$modCount = (int) ($category['mod_count'] ?? 0);
$style = $banner !== '' ? ' style="--category-banner: url(' . e(url($banner)) . ');"' : '';
?>
<a class="category-card<?= $banner !== '' ? ' has-banner' : '' ?>" href="<?= url('/kategori/' . $slug) ?>"<?= $style ?>>
    <span class="category-card-backdrop" aria-hidden="true"></span>
    <span class="category-icon">
        <?php if (is_string($icon) && str_starts_with($icon, '/')): ?>
            <img loading="lazy" src="<?= url($icon) ?>" alt="">
        <?php else: ?>
            <?= e($icon !== '' ? $icon : strtoupper(substr($name, 0, 2))) ?>
        <?php endif; ?>
    </span>
    <strong><?= e($name) ?></strong>
    <?php if ($description !== ''): ?><small><?= e($description) ?></small><?php endif; ?>
    <em><?= number_format($modCount, 0, ',', '.') ?> mod</em>
</a>
