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