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