<?php

declare(strict_types=1);

final class Sidebar
{
    public static function render(array $items): string
    {
        ob_start();
        ?>
        <aside class="rounded-xl border bg-white p-3 h-fit">
            <nav class="space-y-1">
                <?php foreach ($items as $item): ?>
                    <?php
                        $href = (string)($item['href'] ?? '#');
                        $label = (string)($item['label'] ?? 'Link');
                        $active = !empty($item['active']);
                    ?>
                    <a class="block rounded-lg px-3 py-2 text-sm <?= $active ? 'bg-slate-900 text-white' : 'text-slate-700 hover:bg-slate-50' ?>" href="<?= e($href) ?>"><?= e($label) ?></a>
                <?php endforeach; ?>
            </nav>
        </aside>
        <?php
        return (string)ob_get_clean();
    }
}
