const g={id:"id",children:"children",pid:"pid"},y={children:"children",label:"name",value:"id",isLeaf:"leaf",emitPath:!1},f=t=>Object.assign({},g,t),b=(t,i={})=>{i=f(i);const{children:e}=i,n=[...t];for(let r=0;r<n.length;r++)n[r][e]&&n.splice(r+1,0,...n[r][e]);return n},A=(t,i,e={})=>{e=f(e);const n=[],r=[...t],a=new Set,{children:s}=e;for(;r.length;){const c=r[0];if(a.has(c))n.pop(),r.shift();else if(a.add(c),c[s]&&r.unshift(...c[s]),n.push(c),i(c))return n}return null},v=(t,i,e={})=>{const n=(e=f(e)).children;return function r(a){return a.map(s=>({...s})).filter(s=>(s[n]=s[n]&&r(s[n]),i(s)||s[n]&&s[n].length))}(t)},O=(t,i)=>t.map(e=>p(e,i)),p=(t,{children:i="children",conversion:e})=>{const n=Array.isArray(t[i])&&t[i].length>0,r=e(t)||{};return n?{...r,[i]:t[i].map(a=>p(a,{children:i,conversion:e}))}:{...r}},m=(t,i,e={})=>{t.forEach(n=>{const r=i(n,e)||n;n.children&&m(n.children,i,r)})},S=(t,i,e,n)=>{if(!Array.isArray(t))return console.warn("data must be an array"),[];const r=i||"id",a=e||"parentId",s=n||"children",c={},o={},h=[];for(const l of t){const d=l[a];c[d]==null&&(c[d]=[]),o[l[r]]=l,c[d].push(l)}for(const l of t)o[l[a]]==null&&h.push(l);for(const l of h)u(l);function u(l){if(c[l[r]]!==null&&(l[s]=c[l[r]]),l[s])for(const d of l[s])u(d)}return h},w=(t,i,e,n,r)=>{i=i||"id",e=e||"parentId",r=r||Math.min(...t.map(c=>c[e]))||0;const a=JSON.parse(JSON.stringify(t)),s=a.filter(c=>{const o=a.filter(h=>c[i]===h[e]);return o.length>0&&(c.children=o),c[e]===r});return s!==""?s:t};export{w as a,A as b,b as c,y as d,m as e,v as f,S as h,O as t};
