import{slicedToArray as o,defineProperty as e,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 g,ENTER_KEYS as f,DEFAULT_DIALOG_SHOW_TRIGGER as v,DEFAULT_DIALOG_HIDE_TRIGGER as D,DIALOG_MOVE_BY as y,SECONDARY_BUTTON_ARIA_LABEL as C,SECONDARY_BUTTON_WRAPPER_CLASSNAME as k}from"./SplitButtonConstants.js";import{withStaticPropsWithoutForwardRef as N}from"../../types/withStaticProps.js";import"../../utils/colors-vars-map.js";import{HideShowEvent as b,AnimationType as T}from"../Dialog/DialogConstants.js";import{NOOP as h}from"../../utils/function-utils.js";import{isInsideClass as S}from"../../utils/dom-utils.js";import j from"../../hooks/useKeyEvent/index.js";import P from"../../hooks/useEventListener/index.js";import I from"../Dialog/Dialog.js";import B from"../DialogContentContainer/DialogContentContainer.js";import E from"./SplitButton.module.scss.js";import{ComponentVibeId as O}from"../../tests/constants.js";import _ from"../../../components/button/dist/Button/Button.js";import z from"../../../packages/icons/dist/react/DropdownChevronDown.js";var L=N((function(g){var N=g.secondaryDialogContent,L=g.onSecondaryDialogDidShow,w=void 0===L?h:L,A=g.onSecondaryDialogDidHide,x=void 0===A?h:A,R=g.shouldCloseOnClickInsideDialog,H=g.zIndex,U=void 0===H?null:H,F=g.secondaryDialogClassName,K=void 0===F?"":F,M=g.secondaryDialogPosition,W=void 0===M?"bottom-start":M,Y=g.dialogContainerSelector,V=g.dialogPaddingSize,X=void 0===V?"medium":V,q=g.disabled,G=g.loading,J=g.kind,Q=void 0===J?"primary":J,Z=g.color,$=void 0===Z?"primary":Z,oo=g.className,eo=g.leftIcon,to=g.rightIcon,io=g.onClick,no=g.children,ao=g.marginLeft,ro=g.marginRight,so=g.active,lo=g.id,co=g["data-testid"],mo=i(g,["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"]),uo=d(!1),po=o(uo,2),go=po[0],fo=po[1],vo=d(!1),Do=o(vo,2),yo=Do[0],Co=Do[1],ko=d(!1),No=o(ko,2),bo=No[0],To=No[1],ho=m(null),So=m(null),jo=u((function(){return Co(!0)}),[Co]),Po=u((function(){return Co(!1)}),[Co]),Io=u((function(o){return!q&&!S(o.target,k)}),[q]),Bo=u((function(o){Io(o)&&To(!0)}),[To,Io]),Eo=u((function(){return To(!1)}),[To]),Oo=u((function(o){Io(o)&&To(!0)}),[To,Io]),_o=u((function(){fo(!0),w()}),[fo,w]),zo=u((function(o,e){fo(!1),x(),"esckey"===e&&So.current.focus()}),[fo,x]);P({eventName:"mouseenter",callback:jo,ref:ho}),P({eventName:"mouseleave",callback:Po,ref:ho}),P({eventName:"mousedown",callback:Bo,ref:ho}),P({eventName:"mouseup",callback:Eo,ref:ho}),P({eventName:"transitionend",callback:Eo,ref:ho}),j({keys:f,ref:ho,callback:Oo});var Lo=p((function(){return l(E.button,a(E,n("kind-"+Q)),a(E,n("color-"+$)),e(e(e(e(e({},E.mainActive,so),E.active,bo),E.splitContentOpen,go),E.hovered,yo),E.disabled,q),oo)}),[oo,Q,$,so,bo,go,yo,q]),wo=p((function(){return q?[]:v}),[q]),Ao=p((function(){return R?[].concat(t(D),[b.CONTENT_CLICK]):D}),[R]),xo=u((function(){var o="function"==typeof N?N():N;return c.createElement(B,{type:B.types.POPOVER,size:X},o)}),[N,X]),Ro=p((function(){return"bottom"===W?"":"bottom-start"===W?"bottom":"top"}),[W]);return c.createElement("div",{className:Lo,ref:ho,id:lo,"data-testid":co||r(s.SPLIT_BUTTON,lo),"data-vibe":O.SPLIT_BUTTON},c.createElement(_,Object.assign({},mo,{preventClickAnimation:!0,leftIcon:eo,rightIcon:to,rightFlat:!0,color:$,kind:Q,active:so,onClick:io,className:E.mainButton,marginLeft:ao,onFocus:jo,onBlur:Po,disabled:q,loading:G,"data-testid":r(s.SPLIT_BUTTON_PRIMARY_BUTTON,lo)}),no),c.createElement("div",{className:E.secondaryButtonWrapper},c.createElement(I,{wrapperClassName:K,zIndex:U,content:xo,position:W,containerSelector:Y,startingEdge:Ro,animationType:T.EXPAND,moveBy:y,onDialogDidShow:_o,onDialogDidHide:zo,showTrigger:wo,hideTrigger:Ao},c.createElement(_,Object.assign({},mo,{ref:So,preventClickAnimation:!0,leftFlat:!0,noSidePadding:!0,color:$,kind:Q,className:E.secondaryButton,active:go,marginRight:ro,onFocus:jo,onBlur:Po,disabled:q,ariaLabel:C,ariaHasPopup:!0,ariaExpanded:go,"data-testid":r(s.SPLIT_BUTTON_SECONDARY_BUTTON,lo)}),c.createElement("div",{className:E.secondaryButtonIconWrapper},c.createElement(z,{"aria-hidden":"true"}))))))}),{secondaryPositions:g,secondaryDialogPositions:g,sizes:_.sizes,colors:_.colors,kinds:_.kinds,inputTags:_.inputTags,dialogPaddingSizes:B.sizes});export{L as default};
//# sourceMappingURL=SplitButton.js.map
