import { GetPathOptions , Key , MergedPath , TreeMate , TreeNode } from './interface' ; export function getPath < R , G , I , T extends boolean > ( key , { includeGroup = false as any , includeSelf = true } , treeMate ) { const treeNodeMap = treeMate . treeNodeMap ; let treeNode = key === null || key === undefined ? null : treeNodeMap . get ( key ) ?? null ; const mergedPath = { keyPath : [ ] , treeNodePath : [ ] , treeNode : treeNode as TreeNode < R , G > | null } ; if ( treeNode ?. ignored ) { mergedPath . treeNode = null ; return mergedPath as any ; } while ( treeNode ) { if ( ! treeNode . ignored && ( includeGroup || ! treeNode . isGroup ) ) { mergedPath . treeNodePath . push ( treeNode as any ) ; } treeNode = treeNode . parent as any ; } mergedPath . treeNodePath . reverse ( ) ; if ( ! includeSelf ) mergedPath . treeNodePath . pop ( ) ; mergedPath . keyPath = mergedPath . treeNodePath . map ( ( treeNode ) => treeNode . key ) ; return mergedPath as any ; }