import{defineProperty as e}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import t,{forwardRef as o,useRef as i,useEffect as a,useCallback as r,useMemo as s}from"react";import{camelCase as n}from"es-toolkit";import l from"classnames";import{ButtonColor as d,ButtonType as c,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 y}from"../../../../shared/dist/constants/sizes.js";import g from"../../../icon/dist/Icon/Icon.js";import h from"../../../loader/dist/Loader/Loader.js";import{withStaticProps as b}from"../../../../shared/dist/types/withStaticProps.js";import{useMergeRef as j}from"../../../../shared/dist/hooks/useMergeRef.js";import{getStyle as N}from"../../../../shared/dist/utils/typesciptCssModulesHelper.js";import{getTestId as B}from"../../../../shared/dist/tests/test-ids-utils.js";import{ComponentDefaultTestId as C,ComponentVibeId as T}from"../../../../shared/dist/tests/constants.js";import{NOOP as E}from"../../../../shared/dist/utils/function-utils.js";var k=b(o((function(o,d){var c=o.className,u=o.children,y=o.kind,b=void 0===y?"primary":y,k=o.onClick,x=void 0===k?E:k,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,ie=o.type,ae=void 0===ie?"button":ie,re=o.onMouseDown,se=void 0===re?E:re,ne=o.ariaLabel,le=o.rightFlat,de=void 0!==le&&le,ce=o.leftFlat,ue=void 0!==ce&&ce,me=o.preventClickAnimation,pe=void 0!==me&&me,fe=o.noSidePadding,ve=void 0!==fe&&fe,ye=o.onFocus,ge=void 0===ye?E:ye,he=o.onBlur,be=void 0===he?E:he,je=o.ariaLabeledBy,Ne=o.defaultTextColorOnPrimaryColor,Be=void 0===Ne?p:Ne,Ce=o.ariaHasPopup,Te=o.ariaExpanded,Ee=o.ariaControls,ke=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=i(null),Re=j(d,Me),Ae=v({isLoading:Q}).loading;a((function(){if(("on-primary-color"===L||"fixed-light"===L)&&"primary"===b&&Me.current){var e=Me.current;e.style.color=m(e,Be)}}),[b,Me,L,Be]);var we=r((function(){var e=Me.current;!z&&e&&Ie&&e.blur()}),[z,Me,Ie]),De=r((function(e){z||Ae||U?e.preventDefault():x&&x(e)}),[x,z,Ae,U]),Ue=r((function(e){z||Ae||U?e.preventDefault():se&&se(e)}),[se,z,Ae,U]),He=s((function(){var t,o=U?"positive":L;return l(c,f.button,N(f,n("size-"+I)),N(f,n("kind-"+b)),N(f,n("color-"+o)),(e(e(e(e(e(e(e(e(e(e(t={},f.success,U),N(f,n("color-"+o+"-active")),X),Y,X),f.marginRight,ee),f.marginLeft,oe),f.rightFlat,de),f.leftFlat,ue),f.preventClickAnimation,pe),f.noSidePadding,ve),f.disabled,z),e(t,f.insetFocusStyle,Oe)))}),[U,L,c,I,b,X,Y,ee,oe,de,ue,pe,ve,z,Oe]),_e=s((function(){return{ref:Re,type:ae,className:He,name:F,onMouseUp:we,style:J,onClick:De,id:Z,onFocus:ge,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":je,"aria-label":ne,"aria-haspopup":Ce,"aria-expanded":Te,"aria-controls":Ee,"aria-describedby":ke,"aria-hidden":xe,"aria-pressed":Fe}}),[Re,ae,He,F,we,J,De,Z,ge,be,ze,Pe,Ue,z,Ae,je,ne,Ce,Te,Ee,ke,xe,Fe]),qe=r((function(e){if("function"==typeof e)switch(I){case"xxs":case"xs":return 16;default:return 20}}),[I]),Ge=s((function(){return t.Children.toArray(u).some(Boolean)}),[u]),Je=s((function(){return t.createElement(t.Fragment,null,w?t.createElement(g,{iconType:"font",icon:w,iconSize:qe(w),className:l(e({},f.leftIcon,Ge)),ignoreFocusStyle:!0}):null,u,R?t.createElement(g,{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(h,{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(g,{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:y,colors:d,kinds:c,types:u,inputTags:u});export{k as default};
//# sourceMappingURL=Button.js.map
