"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("lodash-unified"),r=require("vue"),v=e=>{let c=0;const u=r.ref(e.treeData||[]),s=r.ref(!1);r.watch(()=>e.treeData,t=>{u.value=t},{deep:!0});function o(t,l){if(!t?.length)return;const i=e.fieldNames?.value||"value";for(const n of t){if(n[i]===l[i])return n;if(n.children?.length){const a=o(n.children,l);if(a)return a}}}async function f(t,l=!1){if(!d.isFunction(e.request))return;s.value=!0,c+=1;const i=c;try{l&&(u.value=[]);const n=await e.request(t,e.params);if(i!==c)return;if(t){const a=o(u.value,t);a&&(a.children=n)}else u.value=n}finally{s.value=!1}}return r.onMounted(()=>{e.lazy||f()}),r.watch(()=>e.params,()=>{f()},{deep:!0}),{treeData:u,request:f,loading:s}};exports.useRequest=v;
