import { i18n, t, type Key } from './i18n/index.svelte'; import type { Inertia, Proposal, Unit } from './types'; /** « 3 / 5 · moyenne ». */ export function inertiaLevel(k: Inertia): string { return t('inertia.level', { k, name: t(`inertia.name.${k}`) }); } /** « inertie 3 / 5 · moyenne ». */ export function inertiaBadge(k: Inertia): string { return t('inertia.badge', { level: inertiaLevel(k) }); } const SECTIONS = ['introduction', 'fondamental', 'technique', 'conclusion', 'annexe', 'formule', 'inertie', 'ordonnancement']; /** The name of a section of the seed, or null. */ export function sectionLabel(s: string | null | undefined): string | null { return s && SECTIONS.includes(s) ? t(`section.${s}` as Key) : null; } /** The name of a module (ADR 0009): « Titre du document », « Ordre des articles · Conclusion ». */ export function moduleName(unit: Unit): string { if (unit.kind === 'title') return t('module.title.name'); const section = sectionLabel(unit.section) ?? unit.section; return section ? t('module.order.named', { section }) : t('module.order.name'); } /** What a proposal is, in words, whatever its kind. */ export function titleOf(p: Proposal, unit: Unit | undefined): string { if (p.kind === 'inertia' && p.inertiaTarget) { return t('deep.inertia', { level: inertiaLevel(p.inertiaTarget) }); } if (p.kind === 'remove') return t('deep.removal', { title: unit?.inForce?.title ?? p.title }); if (p.kind === 'order') return unit ? moduleName(unit) : t('module.order.name'); return p.title; } /** Its relation to the text in force. */ export function relationOf(p: Proposal, unit: Unit | undefined): string { if (p.kind !== 'text' && p.kind !== 'title') return ''; if (unit?.inForce && unit.inForce.id !== p.id) return t('deep.rival', { title: unit.inForce.title }); return ''; } /** What an order version says of itself: completed at the end, or the order in force already. */ export function orderNote(p: Proposal): string[] { const o = p.order; if (!o || p.status === 'in_force') return []; const notes: string[] = []; if (o.added.length) notes.push(i18n.plural('module.order.added', o.added.length)); if (o.dropped.length) notes.push(i18n.plural('module.order.dropped', o.dropped.length)); if (o.same) notes.push(t('module.order.same')); return notes; }