<?php
// components/CampaignFlow/WaitBadge.php
namespace Components\CampaignFlow;

class WaitBadge extends FlowBadge
{

    /**
     * Render a wait badge, optionally editable with Alpine and HTMX.
     * $wait keys:
     * - label (string) e.g., "Wait 3 days"
     * - icon (string) e.g., emoji or SVG
     * - index (int) optional key for editing
     * - variant (string) optional layout variant, supports 'pill'
     * - color (string) optional palette token for 'pill' (default: 'orange')
     */
    public static function render(array $wait, array $opts = []): string
    {
        $size =  $opts['size'] ?? 'md'; // xs|sm|md|lg
        $orientation = $opts['orientation'] ?? 'horizontal';
        $sz = self::getSizes()[$size] ?? self::getSizes()['md'];

        $label = (string)($wait['label'] ?? '');
        $labelEsc = self::h($label);
        $icon = (string)($wait['icon'] ?? self::SVG_WAIT);

        $wait['color'] = 'brand';

        $iconWrapCls = self::getIconWrapClasses($wait, $opts, $sz);
        $iconWrapEsc = self::h($iconWrapCls);

        $labelPosCls = $orientation == 'vertical' ? '' : 'absolute -bottom-4';
        $labelCls = trim(($labelPosCls) . ' rounded bg-surface px-1 ' . $sz['labelText'] . '  ');
        $labelClsEsc = self::h($labelCls);

        // Build the core badge inner HTML
        $badgeInner = <<<HTML
  <div class="$iconWrapEsc" title="$labelEsc">$icon</div>
  <div class="$labelClsEsc">$labelEsc</div>
HTML;

        return self::renderFlowBadge($wait, array_merge($opts, [
            'badge_type_class' => 'wait-badge',
            'badge_inner_html' => $badgeInner,
        ]));
    }
}
