// ============================================ // Site Settings Utilities // Helper functions for copy configuration // ============================================ import { getSiteType } from "../site-types"; type SiteCopyTranslator = (key: string) => string; export function getSiteCopyFallbackKey(type: string, key: string): string { return `models.site.types.${type}.copy.${key}.fallback`; } function resolveCopyFallback(type: string, key: string, fallback: string, t?: SiteCopyTranslator): string { if (!t) return fallback; const fallbackKey = getSiteCopyFallbackKey(type, key); const translated = t(fallbackKey); return translated === fallbackKey ? fallback : translated; } /** * Build copy object with fallback values for missing keys */ export function buildCopyWithFallbacks(type: string, savedCopy: Record | null, t?: SiteCopyTranslator): Record { const siteType = getSiteType(type); if (!siteType) return {}; const result: Record = {}; for (const { key, fallback } of siteType.copyKeys) { result[key] = savedCopy?.[key] || resolveCopyFallback(type, key, fallback, t); } return result; }