<?php

namespace WPSN\Modules\Diagnostics;

defined('ABSPATH') || exit;

/**
 * Small HTML helper for compact release smoke badges.
 */
final class ReleaseSmokeBadgeHtml
{
    /**
     * @param array<int,array<string,mixed>> $badges
     */
    public static function render(array $badges): string
    {
        $parts = [];
        foreach ($badges as $badge) {
            if (!is_array($badge)) {
                continue;
            }

            $label = isset($badge['label']) ? trim((string) $badge['label']) : '';
            if ($label === '') {
                continue;
            }

            $tone = isset($badge['tone']) ? sanitize_key((string) $badge['tone']) : 'info';
            if (!in_array($tone, ['ok', 'warn', 'bad', 'info'], true)) {
                $tone = 'info';
            }

            $parts[] = '<span class="wpsn-release-badge ' . esc_attr($tone) . '">' . esc_html($label) . '</span>';
        }

        if (empty($parts)) {
            return '';
        }

        return '<div class="wpsn-release-badges">' . implode('', $parts) . '</div>';
    }
}
