import{shallowRef as i,watch as d,toRaw as s}from"vue";import{convertChildrenToData as p}from"../utils/legacyUtil.mjs";function f(n,{id:l,pId:r,rootPId:o}){const u={},c=[];return n.map(a=>{const e={...a},t=e[l];return u[t]=e,e.key=e.key||t,e}).forEach(a=>{const e=a[r],t=u[e];t&&(t.children=t.children||[],t.children.push(a)),(e===o||!t&&o===null)&&c.push(a)}),c}function y(n,l,r){const o=i();return d([r,n,l],()=>{const u=r.value;n.value?o.value=r.value?f(s(n.value),{id:"id",pId:"pId",rootPId:null,...u!==!0?u:{}}):s(n.value).slice():o.value=p(s(l.value))},{immediate:!0,deep:!0}),o}export{y as default};
