import{defineComponent as fe,getCurrentInstance as me,computed as l,shallowRef as h,onBeforeUnmount as T,watch as ye,createVNode as n,Fragment as A}from"vue";import j from"../../_util/classNames.mjs";import w from"../../_util/isValid.mjs";import{getPropsSlot as be,isValidElement as ge}from"../../_util/props-util/index.mjs";import{objectType as he}from"../../_util/type.mjs";import{cloneElement as Me}from"../../_util/vnode.mjs";import D from"../../_util/vue-types/index.mjs";import $e from"../../vc-overflow/Overflow.mjs";import Ce from"../../vc-util/devWarning.mjs";import Ie from"./InlineSubMenuList.mjs";import z from"./PopupTrigger.mjs";import Se from"./SubMenuList.mjs";import xe from"./hooks/useDirectionStyle.mjs";import Ke,{useMeasure as Pe,useInjectKeyPath as ke}from"./hooks/useKeyPath.mjs";import{useProvideFirstLevel as Ee,useInjectMenu as Fe,useInjectForceRender as Oe,useProvideForceRender as _e,MenuContextProvider as L}from"./hooks/useMenuContext.mjs";let B=0;const Ne=()=>({icon:D.any,title:D.any,disabled:Boolean,level:Number,popupClassName:String,popupOffset:Array,internalPopupClose:Boolean,eventKey:String,expandIcon:Function,theme:String,mode:String,onMouseenter:Function,onMouseleave:Function,onTitleClick:Function,originItemValue:he()}),Je=fe({compatConfig:{MODE:3},name:"ASubMenu",inheritAttrs:!1,props:Ne(),slots:Object,setup(t,{slots:v,attrs:P,emit:M}){Ee(!1);const m=Pe(),y=me(),s=typeof y.vnode.key=="symbol"?String(y.vnode.key):y.vnode.key;Ce(typeof y.vnode.key!="symbol","SubMenu",`SubMenu \`:key="${String(s)}"\` not support Symbol type`);const o=w(s)?s:`sub_menu_${++B}_$$_not_set_key`,i=t.eventKey??(w(s)?`sub_menu_${++B}_$$_${s}`:o),{parentEventKeys:G,parentInfo:b,parentKeys:$}=ke(),p=l(()=>[...$.value,o]),U=h([]),k={eventKey:i,key:o,parentEventKeys:G,childrenEventKeys:U,parentKeys:$};b.childrenEventKeys?.value.push(i),T(()=>{b.childrenEventKeys&&(b.childrenEventKeys.value=b.childrenEventKeys?.value.filter(e=>e!=i))}),Ke(i,o,k);const{prefixCls:r,activeKeys:E,disabled:W,changeActiveKeys:C,mode:q,inlineCollapsed:H,openKeys:J,overflowDisabled:I,onOpenChange:F,registerMenuInfo:Q,unRegisterMenuInfo:X,selectedSubMenuKeys:Y,expandIcon:Z,theme:ee}=Fe(),u=l(()=>t.mode||q.value),g=s!=null,O=!m&&(Oe()||!g);_e(O),(m&&g||!m&&!g||O)&&(Q(i,k),T(()=>{X(i)}));const _=l(()=>`${r.value}-submenu`),c=l(()=>W.value||t.disabled),ne=h(),te=h(),N=l(()=>J.value.includes(o)),f=l(()=>!I.value&&N.value),oe=l(()=>Y.value.includes(o)),R=h(!1);ye(E,()=>{R.value=!!E.value.find(e=>e===o)},{immediate:!0});const le=e=>{c.value||(M("titleClick",e,o),u.value==="inline"&&F(o,!N.value))},ue=e=>{c.value||(C(p.value),M("mouseenter",e))},ae=e=>{c.value||(C([]),M("mouseleave",e))},ie=xe(l(()=>p.value.length)),se=e=>{u.value!=="inline"&&F(o,e)},re=()=>{C(p.value)},S=i&&`${i}-popup`,ce=l(()=>j(r.value,`${r.value}-${t.theme||ee.value}`,t.popupClassName)),ve=(e,a)=>{if(!a)return H.value&&!$.value.length&&e&&typeof e=="string"?n("div",{class:`${r.value}-inline-collapsed-noicon`},[e.charAt(0)]):n("span",{class:`${r.value}-title-content`},[e]);const d=ge(e)&&e.type==="span";return n(A,null,[Me(typeof a=="function"?a(t.originItemValue):a,{class:`${r.value}-item-icon`},!1),d?e:n("span",{class:`${r.value}-title-content`},[e])])},x=l(()=>u.value!=="inline"&&p.value.length>1?"vertical":u.value),de=l(()=>u.value==="horizontal"?"vertical":u.value),pe=l(()=>x.value==="horizontal"?"vertical":x.value),V=()=>{const e=_.value,a=t.icon??v.icon?.(t),d=t.expandIcon||v.expandIcon||Z.value,K=ve(be(v,t,"title"),a);return n("div",{style:ie.value,class:`${e}-title`,tabindex:c.value?null:-1,ref:ne,title:typeof K=="string"?K:null,"data-menu-id":o,"aria-expanded":f.value,"aria-haspopup":!0,"aria-controls":S,"aria-disabled":c.value,onClick:le,onFocus:re},[K,u.value!=="horizontal"&&d?d({...t,isOpen:f.value}):n("i",{class:`${e}-arrow`},null)])};return()=>{if(m)return g?v.default?.():null;const e=_.value;let a=()=>null;if(!I.value&&u.value!=="inline"){const d=u.value==="horizontal"?[0,8]:[10,0];a=()=>n(z,{mode:x.value,prefixCls:e,visible:!t.internalPopupClose&&f.value,popupClassName:ce.value,popupOffset:t.popupOffset||d,disabled:c.value,onVisibleChange:se},{default:()=>[V()],popup:()=>n(L,{mode:pe.value},{default:()=>[n(Se,{id:S,ref:te},{default:v.default})]})})}else a=()=>n(z,null,{default:V});return n(L,{mode:de.value},{default:()=>[n($e.Item,{component:"li",...P,role:"none",class:j(e,`${e}-${u.value}`,P.class,{[`${e}-open`]:f.value,[`${e}-active`]:R.value,[`${e}-selected`]:oe.value,[`${e}-disabled`]:c.value}),onMouseenter:ue,onMouseleave:ae,"data-submenu-id":o},{default:()=>n(A,null,[a(),!I.value&&n(Ie,{id:S,open:f.value,keyPath:p.value},{default:v.default})])})]})}}});export{Je as default,Ne as subMenuProps};
