import{slicedToArray as e,defineProperty as o,toConsumableArray as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as i}from"../../../_virtual/_tslib.js";import{camelCase as n}from"es-toolkit";import{getStyle as a}from"../../helpers/typesciptCssModulesHelper.js";import{getTestId as r,ComponentDefaultTestId as s}from"../../tests/testIds.js";import l from"classnames";import c,{useState as d,useRef as m,useCallback as u,useMemo as p}from"react";import{SplitButtonSecondaryContentPosition as f,ENTER_KEYS as g,DEFAULT_DIALOG_SHOW_TRIGGER as v,DEFAULT_DIALOG_HIDE_TRIGGER as y,DIALOG_MOVE_BY as b,SECONDARY_BUTTON_ARIA_LABEL as k,SECONDARY_BUTTON_WRAPPER_CLASSNAME as N}from"./SplitButtonConstants.js";import{withStaticPropsWithoutForwardRef as C}from"../../types/withStaticProps.js";import"../../utils/colors-vars-map.js";import{NOOP as T}from"../../utils/function-utils.js";import{isInsideClass as D}from"../../utils/dom-utils.js";import h from"../../hooks/useKeyEvent/index.js";import S from"../../hooks/useEventListener/index.js";import{Button as P}from"@vibe/button/mockedClassNames";import{DropdownChevronDown as I}from"@vibe/icons";import{DialogContentContainer as B,DialogTriggerEventEnum as E,Dialog as j,DialogAnimationTypeEnum as O}from"@vibe/dialog/mockedClassNames";import _ from"./SplitButton.module.scss.js";import{ComponentVibeId as z}from"../../tests/constants.js";var L=C((function(f){var C=f.secondaryDialogContent,L=f.onSecondaryDialogDidShow,A=void 0===L?T:L,w=f.onSecondaryDialogDidHide,x=void 0===w?T:w,R=f.shouldCloseOnClickInsideDialog,H=f.zIndex,U=void 0===H?null:H,F=f.secondaryDialogClassName,K=void 0===F?"":F,M=f.secondaryDialogPosition,W=void 0===M?"bottom-start":M,Y=f.dialogContainerSelector,V=f.dialogPaddingSize,X=void 0===V?"medium":V,q=f.disabled,G=f.loading,J=f.kind,Q=void 0===J?"primary":J,Z=f.color,$=void 0===Z?"primary":Z,ee=f.className,oe=f.leftIcon,te=f.rightIcon,ie=f.onClick,ne=f.children,ae=f.marginLeft,re=f.marginRight,se=f.active,le=f.id,ce=f["data-testid"],de=i(f,["secondaryDialogContent","onSecondaryDialogDidShow","onSecondaryDialogDidHide","shouldCloseOnClickInsideDialog","zIndex","secondaryDialogClassName","secondaryDialogPosition","dialogContainerSelector","dialogPaddingSize","disabled","success","loading","kind","color","className","leftIcon","rightIcon","onClick","children","marginLeft","marginRight","active","id","data-testid"]),me=d(!1),ue=e(me,2),pe=ue[0],fe=ue[1],ge=d(!1),ve=e(ge,2),ye=ve[0],be=ve[1],ke=d(!1),Ne=e(ke,2),Ce=Ne[0],Te=Ne[1],De=m(null),he=m(null),Se=u((function(){return be(!0)}),[be]),Pe=u((function(){return be(!1)}),[be]),Ie=u((function(e){return!q&&!D(e.target,N)}),[q]),Be=u((function(e){Ie(e)&&Te(!0)}),[Te,Ie]),Ee=u((function(){return Te(!1)}),[Te]),je=u((function(e){Ie(e)&&Te(!0)}),[Te,Ie]),Oe=u((function(){fe(!0),A()}),[fe,A]),_e=u((function(e,o){fe(!1),x(),"esckey"===o&&he.current.focus()}),[fe,x]);S({eventName:"mouseenter",callback:Se,ref:De}),S({eventName:"mouseleave",callback:Pe,ref:De}),S({eventName:"mousedown",callback:Be,ref:De}),S({eventName:"mouseup",callback:Ee,ref:De}),S({eventName:"transitionend",callback:Ee,ref:De}),h({keys:g,ref:De,callback:je});var ze=p((function(){return l(_.button,a(_,n("kind-"+Q)),a(_,n("color-"+$)),o(o(o(o(o({},_.mainActive,se),_.active,Ce),_.splitContentOpen,pe),_.hovered,ye),_.disabled,q),ee)}),[ee,Q,$,se,Ce,pe,ye,q]),Le=p((function(){return q?[]:v}),[q]),Ae=p((function(){return R?[].concat(t(y),[E.CONTENT_CLICK]):y}),[R]),we=u((function(){var e="function"==typeof C?C():C;return c.createElement(B,{type:B.types.POPOVER,size:X},e)}),[C,X]),xe=p((function(){return"bottom"===W?"":"bottom-start"===W?"bottom":"top"}),[W]);return c.createElement("div",{className:ze,ref:De,id:le,"data-testid":ce||r(s.SPLIT_BUTTON,le),"data-vibe":z.SPLIT_BUTTON},c.createElement(P,Object.assign({},de,{preventClickAnimation:!0,leftIcon:oe,rightIcon:te,rightFlat:!0,color:$,kind:Q,active:se,onClick:ie,className:_.mainButton,marginLeft:ae,onFocus:Se,onBlur:Pe,disabled:q,loading:G,"data-testid":r(s.SPLIT_BUTTON_PRIMARY_BUTTON,le)}),ne),c.createElement("div",{className:_.secondaryButtonWrapper},c.createElement(j,{wrapperClassName:K,zIndex:U,content:we,position:W,containerSelector:Y,startingEdge:xe,animationType:O.EXPAND,moveBy:b,onDialogDidShow:Oe,onDialogDidHide:_e,showTrigger:Le,hideTrigger:Ae},c.createElement(P,Object.assign({},de,{ref:he,preventClickAnimation:!0,leftFlat:!0,noSidePadding:!0,color:$,kind:Q,className:_.secondaryButton,active:pe,marginRight:re,onFocus:Se,onBlur:Pe,disabled:q,ariaLabel:k,ariaHasPopup:!0,ariaExpanded:pe,"data-testid":r(s.SPLIT_BUTTON_SECONDARY_BUTTON,le)}),c.createElement("div",{className:_.secondaryButtonIconWrapper},c.createElement(I,{"aria-hidden":"true"}))))))}),{secondaryPositions:f,secondaryDialogPositions:f,sizes:P.sizes,colors:P.colors,kinds:P.kinds,inputTags:P.inputTags,dialogPaddingSizes:B.sizes});export{L as default};
//# sourceMappingURL=SplitButton.js.map
