import{shallowRef as d,watch as k,ref as y,createVNode as u}from"vue";import w from"../Divider.mjs";import I from"../ItemGroup.mjs";import N from"../MenuItem.mjs";import E from"../SubMenu.mjs";function v(n,i,r){return(n||[]).map((e,s)=>{if(e&&typeof e=="object"){const{label:o,children:a,key:p,type:m,...l}=e,t=p??`tmp-${s}`,c=r?r.parentKeys.slice():[],h=[],f={eventKey:t,key:t,parentEventKeys:y(c),parentKeys:y(c),childrenEventKeys:y(h),isLeaf:!1};if(a||m==="group"){if(m==="group"){const g=v(a,i,r);return u(I,{key:t,...l,title:o,originItemValue:e},{default:()=>[g]})}i.set(t,f),r&&r.childrenEventKeys.push(t);const K=v(a,i,{childrenEventKeys:h,parentKeys:[].concat(c,t)});return u(E,{key:t,...l,title:o,originItemValue:e},{default:()=>[K]})}return m==="divider"?u(w,{key:t,...l},null):(f.isLeaf=!0,i.set(t,f),u(N,{key:t,...l,originItemValue:e},{default:()=>[o]}))}return null}).filter(e=>e)}function x(n){const i=d([]),r=d(!1),e=d(new Map);return k(()=>n.items,()=>{const s=new Map;r.value=!1,n.items?(r.value=!0,i.value=v(n.items,s)):i.value=void 0,e.value=s},{immediate:!0,deep:!0}),{itemsNodes:i,store:e,hasItmes:r}}export{x as default};
