import type { Dict } from '@/i18n' export type LegalKind = 'privacy' | 'terms' export type CmsLegalDoc = { body?: string | null; updated?: string | null } export type CmsLegal = Partial> export type LegalModel = { title: string; paragraphs: string[]; updated: string | null; tbc: boolean } /** Делит текст на абзацы по пустой строке; переносы строк внутри абзаца сохраняются при выводе. */ export const toParagraphs = (body?: string | null): string[] => (body ?? '') .replace(/\r\n?/g, '\n') .split(/\n\s*\n/) .map((p) => p.trim()) .filter(Boolean) /** Документ показывается только из админ-панели; пусто → пометка «нужно уточнить», ничего не выдумываем. */ export function buildLegalModel(cms: CmsLegal | null, kind: LegalKind, t: Dict): LegalModel { const doc = cms?.[kind] const paragraphs = toParagraphs(doc?.body) const tbc = paragraphs.length === 0 return { title: t.legal[kind].title, paragraphs, updated: tbc ? null : (doc?.updated ?? null), tbc } }