import{objectType as e}from"../../_util/type.mjs";import{flattenChildren as t,isValidElement as n}from"../../_util/props-util/index.mjs";import r from"../../_util/vue-types/index.mjs";import i from"../../vc-util/devWarning.mjs";import a from"../../_util/KeyCode.mjs";import{cloneElement as o}from"../../_util/vnode.mjs";import s from"../../vc-overflow/index.mjs";import c from"../../tooltip/index.mjs";import{useInjectFirstLevel as l,useInjectMenu as u}from"./hooks/useMenuContext.mjs";import{useInjectKeyPath as d,useMeasure as f}from"./hooks/useKeyPath.mjs";import p from"./hooks/useDirectionStyle.mjs";import{computed as m,createVNode as h,defineComponent as g,getCurrentInstance as _,onBeforeUnmount as v,shallowRef as y,watch as b}from"vue";var x=0,S=()=>({id:String,role:String,disabled:Boolean,danger:Boolean,title:{type:[String,Boolean],default:void 0},icon:r.any,onMouseenter:Function,onMouseleave:Function,onClick:Function,onKeydown:Function,onFocus:Function,originItemValue:e()}),C=g({compatConfig:{MODE:3},name:`AMenuItem`,inheritAttrs:!1,props:S(),slots:Object,setup(e,{slots:r,emit:g,attrs:S}){let C=_(),w=f(),T=typeof C.vnode.key==`symbol`?String(C.vnode.key):C.vnode.key;i(typeof C.vnode.key!=`symbol`,`MenuItem`,`MenuItem \`:key="${String(T)}"\` not support Symbol type`);let E=`menu_item_${++x}_$$_${T}`,{parentEventKeys:D,parentKeys:O}=d(),{prefixCls:k,activeKeys:A,disabled:j,changeActiveKeys:M,rtl:N,inlineCollapsed:P,siderCollapsed:F,onItemClick:I,selectedKeys:L,registerMenuInfo:R,unRegisterMenuInfo:z}=u(),B=l(),V=y(!1),H=m(()=>[...O.value,T]);R(E,{eventKey:E,key:T,parentEventKeys:D,parentKeys:O,isLeaf:!0}),v(()=>{z(E)}),b(A,()=>{V.value=!!A.value.find(e=>e===T)},{immediate:!0});let U=m(()=>j.value||e.disabled),W=m(()=>L.value.includes(T)),G=m(()=>{let t=`${k.value}-item`;return{[`${t}`]:!0,[`${t}-danger`]:e.danger,[`${t}-active`]:V.value,[`${t}-selected`]:W.value,[`${t}-disabled`]:U.value}}),K=t=>({key:T,eventKey:E,keyPath:H.value,eventKeyPath:[...D.value,E],domEvent:t,item:{...e,...S}}),q=e=>{if(U.value)return;let t=K(e);g(`click`,e),I(t)},J=e=>{U.value||(M(H.value),g(`mouseenter`,e))},Y=e=>{U.value||(M([]),g(`mouseleave`,e))},X=e=>{if(g(`keydown`,e),e.which===a.ENTER){let t=K(e);g(`click`,e),I(t)}},Z=e=>{M(H.value),g(`focus`,e)},Q=(e,t)=>{let r=h(`span`,{class:`${k.value}-title-content`},[t]);return(!e||n(t)&&t.type===`span`)&&t&&P.value&&B&&typeof t==`string`?h(`div`,{class:`${k.value}-inline-collapsed-noicon`},[t.charAt(0)]):r},$=p(m(()=>H.value.length));return()=>{if(w)return null;let n=e.title??r.title?.(),i=t(r.default?.()),a=i.length,l=n;n===void 0?l=B&&a?i:``:n===!1&&(l=``);let u={title:l};!F.value&&!P.value&&(u.title=null,u.open=!1);let d={};e.role===`option`&&(d[`aria-selected`]=W.value);let f=e.icon??r.icon?.(e);return h(c,{...u,placement:N.value?`left`:`right`,overlayClassName:`${k.value}-inline-collapsed-tooltip`},{default:()=>[h(s.Item,{component:`li`,...S,id:e.id,style:{...S.style||{},...$.value},class:[G.value,{[`${S.class}`]:!!S.class,[`${k.value}-item-only-child`]:(f?a+1:a)===1}],role:e.role||`menuitem`,tabindex:e.disabled?null:-1,"data-menu-id":T,"aria-disabled":e.disabled,...d,onMouseenter:J,onMouseleave:Y,onClick:q,onKeydown:X,onFocus:Z,title:typeof n==`string`?n:void 0},{default:()=>[o(typeof f==`function`?f(e.originItemValue):f,{class:`${k.value}-item-icon`},!1),Q(f,i)]})]})}}});export{C as default,S as menuItemProps};