import{defineProperty as e}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import t,{forwardRef as o,useRef as a,useEffect as i,useCallback as s,useMemo as r}from"react";import{camelCase as n}from"es-toolkit";import l from"classnames";import{ButtonColor as c,ButtonType as d,ButtonInputType as u}from"./ButtonConstants.js";import{getParentBackgroundColorNotTransparent as m,TRANSPARENT_COLOR as p}from"./helper/dom-helpers.js";import f from"./Button.module.scss.js";import{useButtonLoading as v}from"./helper/useButtonLoading.js";import{SIZES as g}from"../../../../packages/shared/dist/constants/sizes.js";import{getStyle as y}from"../../../../packages/shared/dist/utils/typesciptCssModulesHelper.js";import h from"../../../icon/dist/Icon/Icon.js";import b from"../../../loader/dist/Loader/Loader.js";import{NOOP as k}from"../../../../packages/shared/dist/utils/function-utils.js";import{withStaticProps as j}from"../../../../packages/shared/dist/types/withStaticProps.js";import{useMergeRef as N}from"../../../../packages/shared/dist/hooks/useMergeRef.js";import{getTestId as B}from"../../../../packages/shared/dist/tests/test-ids-utils.js";import{ComponentDefaultTestId as C,ComponentVibeId as T}from"../../../../packages/shared/dist/tests/constants.js";var E=j(o((function(o,c){var d=o.className,u=o.children,g=o.kind,j=void 0===g?"primary":g,E=o.onClick,x=void 0===E?k:E,F=o.name,S=o.size,I=void 0===S?"medium":S,P=o.color,L=void 0===P?"primary":P,O=o.disabled,z=void 0!==O&&O,M=o.rightIcon,R=void 0===M?null:M,A=o.leftIcon,w=void 0===A?null:A,D=o.success,U=void 0!==D&&D,H=o.successText,_=void 0===H?"":H,q=o.successIcon,G=void 0===q?null:q,J=o.style,K=o.loading,Q=void 0!==K&&K,V=o.loaderClassName,W=o.active,X=void 0!==W&&W,Y=o.activeButtonClassName,Z=o.id,$=o.marginRight,ee=void 0!==$&&$,te=o.marginLeft,oe=void 0!==te&&te,ae=o.type,ie=void 0===ae?"button":ae,se=o.onMouseDown,re=void 0===se?k:se,ne=o.ariaLabel,le=o.rightFlat,ce=void 0!==le&&le,de=o.leftFlat,ue=void 0!==de&&de,me=o.preventClickAnimation,pe=void 0!==me&&me,fe=o.noSidePadding,ve=void 0!==fe&&fe,ge=o.onFocus,ye=void 0===ge?k:ge,he=o.onBlur,be=void 0===he?k:he,ke=o.ariaLabeledBy,je=o.defaultTextColorOnPrimaryColor,Ne=void 0===je?p:je,Be=o.ariaHasPopup,Ce=o.ariaExpanded,Te=o.ariaControls,Ee=o["aria-describedby"],xe=o["aria-hidden"],Fe=o["aria-pressed"],Se=o.blurOnMouseUp,Ie=void 0===Se||Se,Pe=o["data-testid"],Le=o.insetFocus,Oe=void 0!==Le&&Le,ze=o.tabIndex,Me=a(null),Re=N(c,Me),Ae=v({isLoading:Q}).loading;i((function(){if(("on-primary-color"===L||"fixed-light"===L)&&"primary"===j&&Me.current){var e=Me.current;e.style.color=m(e,Ne)}}),[j,Me,L,Ne]);var we=s((function(){var e=Me.current;!z&&e&&Ie&&e.blur()}),[z,Me,Ie]),De=s((function(e){z||Ae||U?e.preventDefault():x&&x(e)}),[x,z,Ae,U]),Ue=s((function(e){z||Ae||U?e.preventDefault():re&&re(e)}),[re,z,Ae,U]),He=r((function(){var t,o=U?"positive":L;return l(d,f.button,y(f,n("size-"+I)),y(f,n("kind-"+j)),y(f,n("color-"+o)),(e(e(e(e(e(e(e(e(e(e(t={},f.success,U),y(f,n("color-"+o+"-active")),X),Y,X),f.marginRight,ee),f.marginLeft,oe),f.rightFlat,ce),f.leftFlat,ue),f.preventClickAnimation,pe),f.noSidePadding,ve),f.disabled,z),e(t,f.insetFocusStyle,Oe)))}),[U,L,d,I,j,X,Y,ee,oe,ce,ue,pe,ve,z,Oe]),_e=r((function(){return{ref:Re,type:ie,className:He,name:F,onMouseUp:we,style:J,onClick:De,id:Z,onFocus:ye,onBlur:be,tabIndex:z||xe?-1:ze,"data-testid":Pe||B(C.BUTTON,Z),"data-vibe":T.BUTTON,onMouseDown:Ue,"aria-disabled":z,"aria-busy":Ae,"aria-labelledby":ke,"aria-label":ne,"aria-haspopup":Be,"aria-expanded":Ce,"aria-controls":Te,"aria-describedby":Ee,"aria-hidden":xe,"aria-pressed":Fe}}),[Re,ie,He,F,we,J,De,Z,ye,be,ze,Pe,Ue,z,Ae,ke,ne,Be,Ce,Te,Ee,xe,Fe]),qe=s((function(e){if("function"==typeof e)switch(I){case"xxs":case"xs":return 16;default:return 20}}),[I]),Ge=r((function(){return t.Children.toArray(u).some(Boolean)}),[u]),Je=r((function(){return t.createElement(t.Fragment,null,w?t.createElement(h,{iconType:"font",icon:w,iconSize:qe(w),className:l(e({},f.leftIcon,Ge)),ignoreFocusStyle:!0}):null,u,R?t.createElement(h,{iconType:"font",icon:R,iconSize:qe(R),className:l(e({},f.rightIcon,Ge)),ignoreFocusStyle:!0}):null)}),[u,Ge,qe,w,R]);return Ae?t.createElement("button",Object.assign({},_e,{key:Z+"-loading"}),t.createElement("span",{className:l(f.loader,V)},t.createElement(b,{className:f.loaderSvg}),t.createElement("span",{"aria-hidden":!0,className:f.textPlaceholder},Je))):U?t.createElement("button",Object.assign({},_e,{key:Z+"-success"}),t.createElement("span",{className:f.successContent},G?t.createElement(h,{iconType:"font",icon:G,iconSize:qe(G),className:l(e({},f.leftIcon,!!_)),ignoreFocusStyle:!0}):null,_),t.createElement("span",{"aria-hidden":"true",className:f.textPlaceholder},Je)):t.createElement("button",Object.assign({},_e,{key:Z+"-button"}),Je)})),{sizes:g,colors:c,kinds:d,types:u,inputTags:u});export{E as default};
//# sourceMappingURL=Button.js.map
