import x from"../../_util/omit.mjs";import{filterEmpty as D}from"../../_util/props-util/index.mjs";import{isTreeNode as N,getPosition as G}from"../util.mjs";import{camelize as O}from"../../_util/util.mjs";function C(e,l){return e??l}function K(e){const{title:l,_title:d,key:s,children:c}=e||{},o=l||"title";return{title:o,_title:d||[o],key:s||"key",children:c||"children"}}function B(e){function l(d=[]){return D(d).map(c=>{if(!N(c))return null;const o=c.children||{},v=c.key,a={};for(const[P,E]of Object.entries(c.props))a[O(P)]=E;const{isLeaf:f,checkable:p,selectable:n,disabled:i,disableCheckbox:t}=a,u={isLeaf:f||f===""||void 0,checkable:p||p===""||void 0,selectable:n||n===""||void 0,disabled:i||i===""||void 0,disableCheckbox:t||t===""||void 0},r={...a,...u},{title:y=o.title?.(r),icon:m=o.icon?.(r),switcherIcon:g=o.switcherIcon?.(r),...b}=a,T=o.default?.(),h={...b,title:y,icon:m,switcherIcon:g,key:v,isLeaf:f,...u},k=l(T);return k.length&&(h.children=k),h})}return l(e)}function I(e,l,d){const{_title:s,key:c,children:o}=K(d),v=new Set(l===!0?[]:l),a=[];function f(p,n=null){return p.map((i,t)=>{const u=G(n?n.pos:"0",t),r=C(i[c],u);let y;for(let g=0;g<s.length;g+=1){const b=s[g];if(i[b]!==void 0){y=i[b];break}}const m={...x(i,[...s,c,o]),title:y,key:r,parent:n,pos:u,children:null,data:i,isStart:[...n?n.isStart:[],t===0],isEnd:[...n?n.isEnd:[],t===p.length-1]};return a.push(m),l===!0||v.has(r)?m.children=f(i[o]||[],m):m.children=[],m})}return f(e),a}function w(e,l,d){let s={};typeof d=="object"?s=d:s={externalGetKey:d},s=s||{};const{childrenPropName:c,externalGetKey:o,fieldNames:v}=s,{key:a,children:f}=K(v),p=c||f;let n;o?typeof o=="string"?n=t=>t[o]:typeof o=="function"&&(n=t=>o(t)):n=(t,u)=>C(t[a],u);function i(t,u,r,y){const m=t?t[p]:e,g=t?G(r.pos,u):"0",b=t?[...y,t]:[];if(t){const T=n(t,g),h={node:t,index:u,pos:g,key:T,parentPos:r.node?r.pos:null,level:r.level+1,nodes:b};l(h)}m&&m.forEach((T,h)=>{i(T,h,{node:t,pos:g,level:r?r.level+1:-1},b)})}i(null)}function z(e,{initWrapper:l,processEntity:d,onProcessFinished:s,externalGetKey:c,childrenPropName:o,fieldNames:v}={},a){const f=c||a,p={},n={};let i={posEntities:p,keyEntities:n};return l&&(i=l(i)||i),w(e,t=>{const{node:u,index:r,pos:y,key:m,parentPos:g,level:b,nodes:T}=t,h={node:u,nodes:T,index:r,key:m,pos:y,level:b},k=C(m,y);p[y]=h,n[k]=h,h.parent=p[g],h.parent&&(h.parent.children=h.parent.children||[],h.parent.children.push(h)),d&&d(h,i)},{externalGetKey:f,childrenPropName:o,fieldNames:v}),s&&s(i),i}function R(e,{expandedKeysSet:l,selectedKeysSet:d,loadedKeysSet:s,loadingKeysSet:c,checkedKeysSet:o,halfCheckedKeysSet:v,dragOverNodeKey:a,dropPosition:f,keyEntities:p}){const n=p[e];return{eventKey:e,expanded:l.has(e),selected:d.has(e),loaded:s.has(e),loading:c.has(e),checked:o.has(e),halfChecked:v.has(e),pos:String(n?n.pos:""),parent:n.parent,dragOver:a===e&&f===0,dragOverGapTop:a===e&&f===-1,dragOverGapBottom:a===e&&f===1}}function q(e){const{data:l,expanded:d,selected:s,checked:c,loaded:o,loading:v,halfChecked:a,dragOver:f,dragOverGapTop:p,dragOverGapBottom:n,pos:i,active:t,eventKey:u}=e,r={dataRef:l,...l,expanded:d,selected:s,checked:c,loaded:o,loading:v,halfChecked:a,dragOver:f,dragOverGapTop:p,dragOverGapBottom:n,pos:i,active:t,eventKey:u,key:u};return"props"in r||Object.defineProperty(r,"props",{get(){return e}}),r}export{z as convertDataToEntities,q as convertNodePropsToEventData,B as convertTreeToData,K as fillFieldNames,I as flattenTreeData,C as getKey,R as getTreeNodeProps,w as traverseDataNodes};
