import { getBioTemplateInfo, } from './catalog' import { cloneControlDefinition, } from './controlSchemaClone' import type { BioTemplateControlSchema, } from './controlSchemaTypes' import type { TemplateId, } from './types' export function mergeTemplateControlSchemas( templateIds: TemplateId[], templateSchemas: Record ): BioTemplateControlSchema { const merged: BioTemplateControlSchema = {} for (const templateId of templateIds) { const schema = templateSchemas[templateId] const template = getBioTemplateInfo(templateId) for (const [name, definition] of Object.entries(schema)) { const key = `${camelize(templateId)}${capitalize(name)}` merged[key] = { ...cloneControlDefinition(definition), section: definition.section ?? templateId, sectionLabel: definition.sectionLabel ?? template?.label ?? templateId, } } } return merged } function camelize(value: string): string { return value.replace(/-([a-z0-9])/g, (_, char: string) => char.toUpperCase()) } function capitalize(value: string): string { return value.charAt(0).toUpperCase() + value.slice(1) }