{"version":3,"file":"flatten-tree-select-data.cjs","names":[],"sources":["../../../src/components/TreeSelect/flatten-tree-select-data.ts"],"sourcesContent":["import type { TreeNodeData } from '../Tree';\nimport type { TreeExpandedState } from '../Tree/use-tree';\n\nexport interface TreeSelectFlatNode {\n  node: TreeNodeData;\n  level: number;\n  parent: string | null;\n  hasChildren: boolean;\n  expanded: boolean;\n  isLastChild: boolean;\n  lineGuides: boolean[];\n}\n\nfunction flattenTo(\n  acc: TreeSelectFlatNode[],\n  data: TreeNodeData[],\n  expandedState: TreeExpandedState,\n  parent: string | null,\n  level: number,\n  parentGuides: boolean[]\n): void {\n  for (let i = 0; i < data.length; i++) {\n    const node = data[i];\n    const isLast = i === data.length - 1;\n    const hasLoadedChildren = Array.isArray(node.children);\n    const hasAsyncChildren = !!node.hasChildren && !hasLoadedChildren;\n    const hasChildren = hasLoadedChildren || hasAsyncChildren;\n    const expanded = expandedState[node.value] || false;\n\n    acc.push({\n      node,\n      level,\n      parent,\n      hasChildren,\n      expanded,\n      isLastChild: isLast,\n      lineGuides: parentGuides,\n    });\n\n    if (expanded && hasLoadedChildren) {\n      const childGuides = level >= 2 ? [...parentGuides, !isLast] : [];\n      flattenTo(acc, node.children!, expandedState, node.value, level + 1, childGuides);\n    }\n  }\n}\n\nexport function flattenTreeSelectData(\n  data: TreeNodeData[],\n  expandedState: TreeExpandedState\n): TreeSelectFlatNode[] {\n  const result: TreeSelectFlatNode[] = [];\n  flattenTo(result, data, expandedState, null, 1, []);\n  return result;\n}\n"],"mappings":";;AAaA,SAAS,UACP,KACA,MACA,eACA,QACA,OACA,cACM;CACN,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,OAAO,KAAK;EAClB,MAAM,SAAS,MAAM,KAAK,SAAS;EACnC,MAAM,oBAAoB,MAAM,QAAQ,KAAK,QAAQ;EACrD,MAAM,mBAAmB,CAAC,CAAC,KAAK,eAAe,CAAC;EAChD,MAAM,cAAc,qBAAqB;EACzC,MAAM,WAAW,cAAc,KAAK,UAAU;EAE9C,IAAI,KAAK;GACP;GACA;GACA;GACA;GACA;GACA,aAAa;GACb,YAAY;EACd,CAAC;EAED,IAAI,YAAY,mBAAmB;GACjC,MAAM,cAAc,SAAS,IAAI,CAAC,GAAG,cAAc,CAAC,MAAM,IAAI,CAAC;GAC/D,UAAU,KAAK,KAAK,UAAW,eAAe,KAAK,OAAO,QAAQ,GAAG,WAAW;EAClF;CACF;AACF;AAEA,SAAgB,sBACd,MACA,eACsB;CACtB,MAAM,SAA+B,CAAC;CACtC,UAAU,QAAQ,MAAM,eAAe,MAAM,GAAG,CAAC,CAAC;CAClD,OAAO;AACT"}