{"version":3,"file":"flattenTree.mjs","sources":["../../../../../admin/src/components/SelectTree/utils/flattenTree.ts"],"sourcesContent":["type TreeNode<T> = {\n  value: T;\n  children?: TreeNode<T>[];\n  label?: string;\n  path?: string;\n};\n\nexport type FlattenedNode<T> = {\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<T>[];\n};\n\nexport function flattenTree<T>(\n  tree: TreeNode<T>[],\n  parent: TreeNode<T> | null = null,\n  depth: number = 0,\n  path: string = ''\n): FlattenedNode<T>[] {\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,WACdC,CAAAA,IAAmB,EACnBC,MAAAA,GAA6B,IAAI,EACjCC,KAAgB,GAAA,CAAC,EACjBC,IAAAA,GAAe,EAAE,EAAA;IAEjB,OAAOH,IAAAA,CAAKI,OAAO,CAAC,CAACC,IAAAA,GAAAA;QACnB,MAAMC,OAAAA,GAAUD,IAAKE,CAAAA,KAAK,GAAG,CAAA,EAAGJ,IAAK,CAAA,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,MAAQM,EAAAA,KAAAA;AAAOL,gBAAAA,KAAAA;gBAAOC,IAAMG,EAAAA;AAAQ,aAAA;AACpDP,YAAAA,GAAAA,WAAAA,CAAYM,IAAKG,CAAAA,QAAQ,EAAEH,IAAAA,EAAMH,QAAQ,CAAGI,EAAAA,OAAAA;SAChD,GACD;AAAE,YAAA,GAAGD,IAAI;AAAEH,YAAAA,KAAAA;AAAOD,YAAAA,MAAAA,EAAQA,MAAQM,EAAAA,KAAAA;YAAOJ,IAAMG,EAAAA;AAAQ,SAAA;AAC7D,KAAA,CAAA;AACF;;;;"}