export type WorkspaceLocale = 'en-US' | 'zh-CN' | 'de-DE'
export type LocaleMessageKey = 'workspace' | 'save' | 'unsupported' | 'longLabel'
export type AccessibilityElement = { id: string; role: string; accessibleName?: string; focusable?: boolean; visible?: boolean }
export type AccessibilityReport = { checked: number; missingNames: string[]; duplicateIds: string[]; unnamedFocusable: string[]; pass: boolean }
const messages: Record<WorkspaceLocale, Record<LocaleMessageKey, string>> = {
  'en-US': { workspace: 'Workspace', save: 'Save project', unsupported: 'This command is not supported in the browser.', longLabel: 'Parametric feature history and document dependency inspector' },
  'zh-CN': { workspace: '工作区', save: '保存项目', unsupported: '此命令在浏览器中暂不支持。', longLabel: '参数化特征历史与文档依赖及拓扑引用检查器工作流' },
  'de-DE': { workspace: 'Arbeitsbereich', save: 'Projekt speichern', unsupported: 'Dieser Befehl wird im Browser nicht unterstützt.', longLabel: 'Verlauf parametrischer Features und Dokumentabhängigkeitsprüfung' },
}
const clone = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T
export const supportedLocales = (): WorkspaceLocale[] => ['en-US', 'zh-CN', 'de-DE']
export const translate = (locale: WorkspaceLocale, key: LocaleMessageKey) => messages[locale][key]
export const formatLength = (value: number, locale: WorkspaceLocale, unit = 'mm') => { if (!Number.isFinite(value)) throw new RangeError('Locale quantity must be finite.'); return new Intl.NumberFormat(locale, { maximumFractionDigits: 3, minimumFractionDigits: 0 }).format(value) + ` ${unit}` }
export const checkAccessibilitySemantics = (elements: AccessibilityElement[]): AccessibilityReport => { const counts = new Map<string, number>(); const missingNames: string[] = []; const unnamedFocusable: string[] = []; for (const element of elements) { counts.set(element.id, (counts.get(element.id) ?? 0) + 1); if (element.visible !== false && !element.accessibleName?.trim()) missingNames.push(element.id); if (element.visible !== false && element.focusable === true && !element.accessibleName?.trim()) unnamedFocusable.push(element.id) }; return { checked: elements.length, missingNames, duplicateIds: [...counts.entries()].filter(([, count]) => count > 1).map(([id]) => id), unnamedFocusable, pass: missingNames.length === 0 && unnamedFocusable.length === 0 && [...counts.values()].every((count) => count === 1) } }
export const localeSnapshot = (locale: WorkspaceLocale) => clone({ locale, messages: messages[locale], samples: { zero: formatLength(0, locale), decimal: formatLength(12.3456, locale) } })
