{"version":3,"file":"updateNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/updateNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const updateNodeChildren = <\n  T extends ContentNode,\n  U extends ContentNode,\n>(\n  section: T,\n  newChildren: U\n): ContentNode => {\n  if (typeof section === 'string') {\n    return newChildren;\n  }\n  if (typeof section === 'number') {\n    return newChildren;\n  }\n  if (typeof section === 'boolean') {\n    return newChildren;\n  }\n  if (typeof (section as TypedNode)?.nodeType === 'string') {\n    const typedNode = section as TypedNode;\n    const content =\n      typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n    if (\n      typedNode.nodeType === NodeTypes.TRANSLATION ||\n      typedNode.nodeType === NodeTypes.ENUMERATION ||\n      typedNode.nodeType === NodeTypes.PLURAL ||\n      typedNode.nodeType === NodeTypes.CONDITION\n    ) {\n      const newContent = Object.entries(content).reduce(\n        (acc, [key]) => {\n          acc[key] = newChildren;\n          return acc;\n        },\n        {} as Record<string, ContentNode>\n      );\n\n      return {\n        ...typedNode,\n        [typedNode.nodeType]: newContent,\n      };\n    }\n\n    if (typedNode.nodeType === NodeTypes.NESTED) {\n      return typedNode;\n    }\n\n    return {\n      ...typedNode,\n      [typedNode.nodeType]: newChildren,\n    };\n  }\n\n  if (!section || typeof section !== 'object') {\n    return newChildren;\n  }\n\n  if (Array.isArray(section)) {\n    return section.map(() => newChildren) as unknown as ContentNode;\n  }\n\n  return Object.entries(\n    section as unknown as Record<string, ContentNode>\n  ).reduce(\n    (acc, [key]) => ({\n      ...acc,\n      [key]: newChildren,\n    }),\n    {} as Record<string, ContentNode>\n  ) as unknown as ContentNode;\n};\n"],"mappings":";;;AAIA,MAAa,sBAIX,SACA,gBACgB;AAChB,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,WACjC;GACA,MAAM,aAAa,OAAO,QAAQ,QAAQ,CAAC,QACxC,KAAK,CAAC,SAAS;AACd,QAAI,OAAO;AACX,WAAO;MAET,EAAE,CACH;AAED,UAAO;IACL,GAAG;KACF,UAAU,WAAW;IACvB;;AAGH,MAAI,UAAU,aAAa,UAAU,OACnC,QAAO;AAGT,SAAO;GACL,GAAG;IACF,UAAU,WAAW;GACvB;;AAGH,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,QAAO;AAGT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,UAAU,YAAY;AAGvC,QAAO,OAAO,QACZ,QACD,CAAC,QACC,KAAK,CAAC,UAAU;EACf,GAAG;GACF,MAAM;EACR,GACD,EAAE,CACH"}