<?php
// components/Card.php
namespace Components;

use Components\Ui\CardUI;

class Card extends Base
{
    public static function render(string $title, string $bodyHtml, ?string $icon = null, ?string $footerHtml = null, string $class = ''): string
    {
        // Resolve potential language key for title, then escape for output
        $titleEsc = self::h(self::lng($title, $title));

        ob_start();
        ?>
        <div class="flex flex-row items-center space-x-2">
            <?php if (!empty($icon)): ?>
                <div class="flex items-center justify-center rounded-md bg-brand-500 text-brand-50 p-1 size-6">
                    <?= $icon ?>
                </div>
            <?php endif; ?>
            <div class="text-sm font-semibold tracking-tight text-primary"><?= $titleEsc ?></div>
        </div>
        <?php
        $bodyHeaderHtml = ob_get_clean();

        return CardUI::render([
            'no_preview' => true,
            'card_classes' => $class,
            'body_header_html' => $bodyHeaderHtml,
            'body_footer_html' => '<div class="mt-2">' . $bodyHtml . '</div>',
            'actions_html' => $footerHtml ? '<div class="mt-2">' . $footerHtml . '</div>' : '',
        ]);
    }
}
