/**
 * Context Overflow Shared Utilities
 *
 * Shared truncation badge renderer used by details.js and the inline script
 * on context_overflow.html. Single function on purpose — resist scope creep;
 * formatters belong in services/formatting.js.
 */
(function() {
    'use strict';

    /**
     * Render a truncation status badge.
     * @param {number} truncatedCount - Number of truncated requests (0 = no truncation).
     * @returns {string} HTML string, color-coded by status. Numeric coercion only — no user input.
     */
    function renderTruncationBadge(truncatedCount) {
        const count = Number(truncatedCount) || 0;
        if (count > 0) {
            // bearer:disable javascript_lang_dangerous_insert_html
            // eslint-disable-next-line no-unsanitized/property -- numeric coercion only
            return `<span style="color: var(--error-color);">Yes (${count} requests)</span>`;
        }
        return '<span style="color: var(--success-color);">No truncation</span>';
    }

    window.contextOverflowShared = { renderTruncationBadge };
})();
