// Run/job statuses: labels, icons, sort order, and the badge that shows one. import { el } from './dom.js'; // rank drives default sort: worst first export const STATUS = { failed: { label: 'Failed', icon: '✕', rank: 0 }, warning: { label: 'Warning', icon: '!', rank: 1 }, unknown: { label: 'Unknown', icon: '?', rank: 2 }, running: { label: 'Running', icon: '↻', rank: 3 }, success: { label: 'Success', icon: '✓', rank: 4 }, }; // Anything the backend sends that we don't recognise becomes "unknown" rather than breaking the UI export function normalizeStatus(raw) { const s = String(raw ?? '').toLowerCase(); return Object.hasOwn(STATUS, s) ? s : 'unknown'; } export function statusBadge(status, { asButton = false, opensDialog = false, dataset = null, title = null } = {}) { const { label, icon } = STATUS[status]; const content = [el('span', { class: 'badge__icon', 'aria-hidden': 'true' }, icon), label]; return asButton ? el('button', { type: 'button', class: `badge badge--${status}`, 'aria-haspopup': opensDialog ? 'dialog' : null, 'aria-label': `${label} – view details`, title, dataset, }, content) : el('span', { class: `badge badge--${status}`, title }, content); }