// Общие помощники UI задач: подписи статусов, приоритеты, Markdown.
import DOMPurify from 'dompurify'
import { marked } from 'marked'
export const STATUS_LABELS: Record<string, string> = {
to_do: 'К выполнению',
in_progress: 'В работе',
done: 'Завершено',
cancelled: 'Отменено',
deferred: 'Отложено',
}
export const STATUS_VARIANTS: Record<string, string> = {
to_do: 'info',
in_progress: 'accent',
done: 'success',
cancelled: 'error',
deferred: 'warning',
}
export const RELEVANCE_LABELS: Record<string, string> = {
active: 'Активен',
paused: 'Приостановлен',
archived: 'Закрыт',
}
export function statusLabel(status: string): string {
return STATUS_LABELS[status] ?? status
}
export function statusVariant(status: string): string {
return STATUS_VARIANTS[status] ?? 'neutral'
}
export function relevanceLabel(status: string): string {
return RELEVANCE_LABELS[status] ?? status
}
export function renderMarkdown(text: string): string {
return DOMPurify.sanitize(marked.parse(text, { async: false }))
}
// «90» → «1 ч 30 м»; для чипов оценок времени
export function formatMinutes(minutes: number | null): string {
if (minutes === null) return ''
const h = Math.floor(minutes / 60)
const m = minutes % 60
if (h && m) return `${h} ч ${m} м`
if (h) return `${h} ч`
return `${m} м`
}
// Валюта бюджетов — глобальная настройка, выбирается один раз и применяется всюду
export const CURRENCIES: { value: string; label: string }[] = [
{ value: 'UAH', label: '₴ Гривна (UAH)' },
{ value: 'USD', label: '$ Доллар (USD)' },
{ value: 'EUR', label: '€ Евро (EUR)' },
{ value: 'GBP', label: '£ Фунт (GBP)' },
{ value: 'PLN', label: 'zł Злотый (PLN)' },
]
const CURRENCY_SYMBOLS: Record<string, string> = {
UAH: '₴',
USD: '$',
EUR: '€',
GBP: '£',
PLN: 'zł',
}
let activeCurrency = 'UAH'
export function setCurrency(currency: string): void {
activeCurrency = currency
}
export function currencySymbol(): string {
return CURRENCY_SYMBOLS[activeCurrency] ?? activeCurrency
}
// «5 000 ₴» — суммы задач; валюта берётся из глобальной настройки
export function formatMoney(amount: number | null): string {
if (amount === null) return ''
return `${amount.toLocaleString('ru-RU')} ${currencySymbol()}`
}