import{defineComponent as M,computed as $,onMounted as R,watch as w,createVNode as n}from"vue";import V from"@ant-design/icons-vue/EllipsisOutlined";import l from"../../../_util/KeyCode.mjs";import O from"../../../_util/classNames.mjs";import E from"../../../_util/hooks/useState.mjs";import{functionType as G}from"../../../_util/type.mjs";import W from"../../../_util/vue-types/index.mjs";import"../../../menu/index.mjs";import{useProvideOverride as F}from"../../../menu/src/OverrideContext.mjs";import U from"../../../vc-dropdown/Dropdown.mjs";import q from"./AddButton.mjs";import z from"../../../menu/src/Menu.mjs";import H from"../../../menu/src/MenuItem.mjs";const J={prefixCls:{type:String},id:{type:String},tabs:{type:Object},rtl:{type:Boolean},tabBarGutter:{type:Number},activeKey:{type:[String,Number]},mobile:{type:Boolean},moreIcon:W.any,moreTransitionName:{type:String},editable:{type:Object},locale:{type:Object,default:void 0},removeAriaLabel:String,onTabClick:{type:Function},popupClassName:String,getPopupContainer:G()},se=M({compatConfig:{MODE:3},name:"OperationNode",inheritAttrs:!1,props:J,emits:["tabClick"],slots:Object,setup(r,{attrs:C,slots:P}){const[u,p]=E(!1),[i,g]=E(null),N=e=>{const o=r.tabs.filter(a=>!a.disabled);let s=o.findIndex(a=>a.key===i.value)||0;const d=o.length;for(let a=0;a<d;a+=1){s=(s+e+d)%d;const m=o[s];if(!m.disabled){g(m.key);return}}},S=e=>{const{which:o}=e;if(!u.value){[l.DOWN,l.SPACE,l.ENTER].includes(o)&&(p(!0),e.preventDefault());return}switch(o){case l.UP:N(-1),e.preventDefault();break;case l.DOWN:N(1),e.preventDefault();break;case l.ESC:p(!1);break;case l.SPACE:case l.ENTER:i.value!==null&&r.onTabClick(i.value,e);break}},c=$(()=>`${r.id}-more-popup`),k=$(()=>i.value!==null?`${c.value}-${i.value}`:null),D=(e,o)=>{e.preventDefault(),e.stopPropagation(),r.editable.onEdit("remove",{key:o,event:e})};return R(()=>{w(i,()=>{const e=document.getElementById(k.value);e&&e.scrollIntoView&&e.scrollIntoView(!1)},{flush:"post",immediate:!0})}),w(u,()=>{u.value||g(null)}),F({}),()=>{const{prefixCls:e,id:o,tabs:s,locale:d,mobile:a,moreIcon:m=P.moreIcon?.()||n(V,null,null),moreTransitionName:T,editable:f,tabBarGutter:A,rtl:h,onTabClick:K,popupClassName:B}=r;if(!s.length)return null;const b=`${e}-dropdown`,x=d?.dropdownAriaLabel,y={[h?"marginRight":"marginLeft"]:A};s.length||(y.visibility="hidden",y.order=1);const L=O({[`${b}-rtl`]:h,[`${B}`]:!0}),j=a?null:n(U,{prefixCls:b,trigger:["hover"],visible:u.value,transitionName:T,onVisibleChange:p,overlayClassName:L,mouseEnterDelay:.1,mouseLeaveDelay:.1,getPopupContainer:r.getPopupContainer},{overlay:()=>n(z,{onClick:({key:t,domEvent:v})=>{K(t,v),p(!1)},id:c.value,tabindex:-1,role:"listbox","aria-activedescendant":k.value,selectedKeys:[i.value],"aria-label":x!==void 0?x:"expanded dropdown"},{default:()=>[s.map(t=>{const v=f&&t.closable!==!1&&!t.disabled;return n(H,{key:t.key,id:`${c.value}-${t.key}`,role:"option","aria-controls":o&&`${o}-panel-${t.key}`,disabled:t.disabled},{default:()=>[n("span",null,[typeof t.tab=="function"?t.tab():t.tab]),v&&n("button",{type:"button","aria-label":r.removeAriaLabel||"remove",tabindex:0,class:`${b}-menu-item-remove`,onClick:I=>{I.stopPropagation(),D(I,t.key)}},[t.closeIcon?.()||f.removeIcon?.()||"×"])]})})]}),default:()=>n("button",{type:"button",class:`${e}-nav-more`,style:y,tabindex:-1,"aria-hidden":"true","aria-haspopup":"listbox","aria-controls":c.value,id:`${o}-more`,"aria-expanded":u.value,onKeydown:S},[m])});return n("div",{class:O(`${e}-nav-operations`,C.class),style:C.style},[j,n(q,{prefixCls:e,locale:d,editable:f},null)])}}});export{se as default,J as operationNodeProps};
