{"version":3,"file":"flattenTree.mjs","sources":["../../../../../admin/src/components/SelectTree/utils/flattenTree.ts"],"sourcesContent":["type TreeNode = {\n value: T;\n children?: TreeNode[];\n label?: string;\n path?: string;\n};\n\nexport type FlattenedNode = {\n value: T;\n parent?: T;\n depth: number;\n // we need the label in places where flattenTree is used\n label?: string;\n path?: string;\n children?: TreeNode[];\n};\n\nexport function flattenTree(\n tree: TreeNode[],\n parent: TreeNode | null = null,\n depth: number = 0,\n path: string = ''\n): FlattenedNode[] {\n return tree.flatMap((item) => {\n const newPath = item.value ? `${path}/${item.value}` : path;\n\n return item.children\n ? [\n { ...item, parent: parent?.value, depth, path: newPath },\n ...flattenTree(item.children, item, depth + 1, newPath),\n ]\n : { ...item, depth, parent: parent?.value, path: newPath };\n });\n}\n"],"names":["flattenTree","tree","parent","depth","path","flatMap","item","newPath","value","children"],"mappings":"AAiBO,SAASA,WAAAA,CACdC,IAAmB,EACnBC,MAAAA,GAA6B,IAAI,EACjCC,KAAAA,GAAgB,CAAC,EACjBC,IAAAA,GAAe,EAAE,EAAA;IAEjB,OAAOH,IAAAA,CAAKI,OAAO,CAAC,CAACC,IAAAA,GAAAA;QACnB,MAAMC,OAAAA,GAAUD,IAAAA,CAAKE,KAAK,GAAG,CAAA,EAAGJ,IAAAA,CAAK,CAAC,EAAEE,IAAAA,CAAKE,KAAK,CAAA,CAAE,GAAGJ,IAAAA;QAEvD,OAAOE,IAAAA,CAAKG,QAAQ,GAChB;AACE,YAAA;AAAE,gBAAA,GAAGH,IAAI;AAAEJ,gBAAAA,MAAAA,EAAQA,MAAAA,EAAQM,KAAAA;AAAOL,gBAAAA,KAAAA;gBAAOC,IAAAA,EAAMG;AAAQ,aAAA;AACpDP,YAAAA,GAAAA,WAAAA,CAAYM,IAAAA,CAAKG,QAAQ,EAAEH,IAAAA,EAAMH,QAAQ,CAAA,EAAGI,OAAAA;SAChD,GACD;AAAE,YAAA,GAAGD,IAAI;AAAEH,YAAAA,KAAAA;AAAOD,YAAAA,MAAAA,EAAQA,MAAAA,EAAQM,KAAAA;YAAOJ,IAAAA,EAAMG;AAAQ,SAAA;AAC7D,IAAA,CAAA,CAAA;AACF;;;;"}