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