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