import{slicedToArray as o,toConsumableArray as n}from"../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as i}from"../../_virtual/_tslib.js";import{jsx as t,jsxs as e}from"react/jsx-runtime";import{useState as s,useRef as a,useCallback as l,useMemo as r}from"react";import c from"classnames";import{SplitButtonSecondaryContentPosition as d,ENTER_KEYS as u,EMPTY_ARR as m,DEFAULT_DIALOG_SHOW_TRIGGER as g,DEFAULT_DIALOG_HIDE_TRIGGER as p,SECONDARY_BUTTON_WRAPPER_CLASSNAME as f,DIALOG_MOVE_BY as b,SECONDARY_BUTTON_ARIA_LABEL as D}from"./SplitButtonConstants.js";import{HideShowEvent as y}from"../Dialog/consts/dialog-show-hide-event.js";import{NOOP as v}from"../../utils/function-utils.js";import{isInsideClass as h}from"../../utils/dom-utils.js";import C from"../../hooks/useKeyEvent/index.js";import j from"../../hooks/useEventListener/index.js";import k from"../Button/Button.js";import O from"../Dialog/Dialog.js";import S from"../Icon/Icons/components/DropdownChevronDown.js";import T from"../DialogContentContainer/DialogContentContainer.js";import"./SplitButton.scss.js";import{DialogPosition as N}from"../../constants/positions.js";import{AnimationType as I}from"../../constants/dialog.js";var P=function(N){var P=N.secondaryDialogContent,_=N.onSecondaryDialogDidShow,z=void 0===_?v:_,B=N.onSecondaryDialogDidHide,w=void 0===B?v:B,E=N.shouldCloseOnClickInsideDialog,x=N.zIndex,M=void 0===x?null:x,A=N.secondaryDialogClassName,L=N.secondaryDialogPosition,R=void 0===L?d.BOTTOM_START:L,H=N.dialogContainerSelector,F=N.dialogPaddingSize,K=void 0===F?T.sizes.MEDIUM:F,U=N.disabled,V=N.success,X=N.loading,q=N.kind,G=N.color,J=N.className,Q=N.leftIcon,W=N.rightIcon,Y=N.onClick,Z=N.children,$=N.marginLeft,oo=N.marginRight,no=N.active,io=i(N,["secondaryDialogContent","onSecondaryDialogDidShow","onSecondaryDialogDidHide","shouldCloseOnClickInsideDialog","zIndex","secondaryDialogClassName","secondaryDialogPosition","dialogContainerSelector","dialogPaddingSize","disabled","success","loading","kind","color","className","leftIcon","rightIcon","onClick","children","marginLeft","marginRight","active"]),to=s(!1),eo=o(to,2),so=eo[0],ao=eo[1],lo=s(!1),ro=o(lo,2),co=ro[0],uo=ro[1],mo=s(!1),go=o(mo,2),po=go[0],fo=go[1],bo=a(null),Do=l((function(){return uo(!0)}),[uo]),yo=l((function(){return uo(!1)}),[uo]),vo=l((function(o){return!U&&!h(o.target,f)}),[U]),ho=l((function(o){vo(o)&&fo(!0)}),[fo,vo]),Co=l((function(){return fo(!1)}),[fo]),jo=l((function(o){vo(o)&&fo(!0)}),[fo,vo]),ko=l((function(){ao(!0),z()}),[ao,z]),Oo=l((function(){ao(!1),w()}),[ao,w]);j({eventName:"mouseenter",callback:Do,ref:bo}),j({eventName:"mouseleave",callback:yo,ref:bo}),j({eventName:"mousedown",callback:ho,ref:bo}),j({eventName:"mouseup",callback:Co,ref:bo}),j({eventName:"transitionend",callback:Co,ref:bo}),C({keys:u,ref:bo,callback:jo});var So=!(V||X),To=r((function(){return c("l3-style-split-button","l3-style-split-button--kind-".concat(q),"l3-style-split-button--color-".concat(G),{"l3-style-split-button--main-active":no,"l3-style-split-button--active":po,"l3-style-split-button--split-content-open":so,"l3-style-split-button--hovered":co,"l3-style-split-button--disabled":U},J)}),[J,q,G,no,po,so,co,U]),No=r((function(){return U?m:g}),[U]),Io=r((function(){return E?[].concat(n(p),[y.CONTENT_CLICK]):p}),[E]),Po=l((function(){var o="function"==typeof P?P():P;return t(T,Object.assign({type:T.types.POPOVER,size:K},{children:o}))}),[P,K]),_o=r((function(){return R===d.BOTTOM_MIDDLE?"":R===d.BOTTOM_START?"bottom":"top"}),[R]);return e("div",Object.assign({className:To,ref:bo,role:"button"},{children:[t(k,Object.assign({},io,{preventClickAnimation:!0,leftIcon:Q,rightIcon:W,rightFlat:!0,color:G,kind:q,active:no,onClick:Y,className:"l3-style-split-button__main-button",marginLeft:$,onFocus:Do,onBlur:yo,disabled:U},{children:Z})),So&&t("div",Object.assign({className:f},{children:t(O,Object.assign({wrapperClassName:A,zIndex:M,content:Po,position:R,containerSelector:H,startingEdge:_o,animationType:I.EXPAND,moveBy:b,onDialogDidShow:ko,onDialogDidHide:Oo,showTrigger:No,hideTrigger:Io},{children:t(k,Object.assign({},io,{preventClickAnimation:!0,leftFlat:!0,noSidePadding:!0,color:G,kind:q,className:"l3-style-split-button__secondary-button",active:so,marginRight:oo,onFocus:Do,onBlur:yo,disabled:U,ariaLabel:D,ariaHasPopup:!0,ariaExpanded:so},{children:t("div",Object.assign({className:"l3-style-split-button__secondary-button-icon-wrapper"},{children:t(S,{"aria-hidden":"true"})}))}))}))}))]}))};Object.assign(P,{secondaryPositions:d,secondaryDialogPositions:d,sizes:k.sizes,colors:k.colors,kinds:k.kinds,inputTags:k.inputTags,dialogPaddingSizes:T.sizes}),P.defaultProps=Object.assign(Object.assign({},k.defaultProps),{onSecondaryDialogDidShow:v,onSecondaryDialogDidHide:v,zIndex:null,secondaryDialogClassName:"",secondaryDialogPosition:N.BOTTOM_START,dialogPaddingSize:T.sizes.MEDIUM});var _=P;export{_ as default};
