import { html, nothing, type TemplateResult } from 'lit';
import type { NuiType } from '../../types/nui-type.js';
import type { TagSeverity } from './types.js';
export interface NuiTagViewState {
value: string;
severity: TagSeverity | '';
rounded: boolean;
icon: string;
nuiType: NuiType;
tagClass: string;
lightDomHasContent: boolean;
}
export function resolveSeverity(
state: Pick,
): TagSeverity | 'primary' {
if (state.severity) {
return state.severity;
}
return 'primary';
}
export function getTagClass(tagClass: string): string {
return ['nui-tag', tagClass].filter(Boolean).join(' ');
}
export function renderTagIcon(icon: string): TemplateResult | typeof nothing {
if (!icon) {
return nothing;
}
return html`
`;
}
export function renderTagLabel(
state: Pick,
): TemplateResult | typeof nothing {
if (state.lightDomHasContent || !state.value) {
return nothing;
}
return html`${state.value}`;
}
export function renderTag(state: NuiTagViewState): TemplateResult {
const severity = resolveSeverity(state);
const showSeverity = Boolean(state.severity);
return html`
${renderTagIcon(state.icon)}
${renderTagLabel(state)}
`;
}