import{slicedToArray as t,defineProperty as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o,jsxs as n}from"react/jsx-runtime";import{forwardRef as i,useRef as l,useState as s,useMemo as r,useEffect as a,useCallback as c}from"react";import u from"classnames";import d from"../../hooks/useResizeObserver.js";import f from"../../hooks/useMergeRefs.js";import{NOOP as p}from"../../utils/function-utils.js";import m from"../Icon/Icon.js";import y from"../Loader/Loader.js";import{ButtonColor as b,ButtonType as v,getActualSize as g,BUTTON_ICON_SIZE as h,ButtonInputType as T}from"./ButtonConstants.js";import{getParentBackgroundColorNotTransparent as I,TRANSPARENT_COLOR as O}from"./helper/dom-helpers.js";import{getTestId as j}from"../../tests/testIds.js";import{isIE11 as k}from"../../utils/user-agent-utils.js";import{ComponentDefaultTestId as N}from"../../tests/constants.js";import"./Button.scss.js";import{SIZES as C}from"../../constants/sizes.js";var P,F,M,x,z=k()?32:6,R=i((function(i,p){var T=i.className,O=i.children,k=i.kind,C=i.onClick,P=i.name,F=i.size,M=i.color,x=i.disabled,R=i.rightIcon,B=i.leftIcon,S=i.success,L=i.successText,_=i.successIcon,A=i.style,U=i.loading,D=i.active,w=i.id,E=i.marginRight,Y=i.marginLeft,H=i.type,V=i.onMouseDown,q=i.ariaLabel,G=i.rightFlat,J=i.leftFlat,K=i.preventClickAnimation,Q=i.noSidePadding,W=i.onFocus,X=i.onBlur,Z=i.ariaLabeledBy,$=i.defaultTextColorOnPrimaryColor,tt=i.ariaHasPopup,et=i.ariaExpanded,ot=i.ariaControls,nt=i.blurOnMouseUp,it=i.dataTestId,lt=i.insetFocus,st=l(null),rt=s(!1),at=t(rt,2),ct=at[0],ut=at[1],dt=r((function(){return function(t){var e=t.borderBoxSize,o=e.blockSize,n=Math.max(e.inlineSize,z),i=Math.max(o,z);st.current&&(st.current.style.setProperty("--element-width","".concat(n,"px")),st.current.style.setProperty("--element-height","".concat(i,"px")),ut(!0))}}),[st]);d({ref:st,callback:dt,debounceTime:200}),a((function(){if(M===b.ON_PRIMARY_COLOR&&k===v.PRIMARY&&st.current){var t=st.current;t.style.color=I(t,$)}}),[k,st,M,$]);var ft=c((function(){var t=st.current;!x&&t&&nt&&t.blur()}),[x,st,nt]),pt=c((function(t){x||U||S?t.preventDefault():C&&C(t)}),[C,x,U,S]),mt=c((function(t){x||U||S?t.preventDefault():V&&V(t)}),[V,x,U,S]),yt=r((function(){var t,o=S?b.POSITIVE:M;return u(T,"l3-style-button","l3-style-button--size-".concat(g(F)),"l3-style-button--kind-".concat(k),"l3-style-button--color-".concat(o),(e(t={"has-style-size":ct,"l3-style-button--loading":U},"l3-style-button--color-".concat(o,"-active"),D),e(t,"l3-style-button--margin-right",E),e(t,"l3-style-button--margin-left",Y),e(t,"l3-style-button--right-flat",G),e(t,"l3-style-button--left-flat",J),e(t,"l3-style-button--prevent-click-animation",K),e(t,"l3-style-button--no-side-padding",Q),e(t,"l3-style-button--disabled",x),e(t,"inset-focus-style",lt),t))}),[S,M,T,F,k,ct,U,D,E,Y,G,J,K,Q,x,lt]),bt=f({refs:[p,st]}),vt=r((function(){return{ref:bt,type:H,className:yt,name:P,onMouseUp:ft,style:A,onClick:pt,id:w,onFocus:W,onBlur:X,"data-testid":it||j(N.BUTTON,w),onMouseDown:mt,"aria-disabled":x,"aria-busy":U,"aria-labelledby":Z,"aria-label":q,"aria-haspopup":tt,"aria-expanded":et,"aria-controls":ot}}),[x,bt,H,yt,P,ft,A,pt,w,W,X,it,mt,Z,q,U,tt,et,ot]),gt=r((function(){if("function"==typeof B)return h}),[B]),ht=r((function(){if("function"==typeof R)return h}),[R]),Tt=r((function(){if("function"==typeof _)return h}),[_]);return U?o("button",Object.assign({},vt,{children:o("span",Object.assign({className:"l3-style-button__loader"},{children:o(y,{svgClassName:"l3-style-button-loader-svg"})}))})):n("button",Object.assign({},vt,S?{children:[_?o(m,{iconType:null==m?void 0:m.type.ICON_FONT,clickable:!1,icon:_,iconSize:Tt,className:u({"l3-style-button--left-icon":!!L}),ignoreFocusStyle:!0}):null,L]}:{children:[B?o(m,{iconType:null==m?void 0:m.type.ICON_FONT,clickable:!1,icon:B,iconSize:gt,className:u({"l3-style-button--left-icon":!!O}),ignoreFocusStyle:!0}):null,O,R?o(m,{iconType:null==m?void 0:m.type.ICON_FONT,clickable:!1,icon:R,iconSize:ht,className:u({"l3-style-button--right-icon":!!O}),ignoreFocusStyle:!0}):null]}))}));Object.assign(R,{sizes:C,colors:b,kinds:v,types:T,inputTags:T,defaultTestId:N.BUTTON}),R.defaultProps={className:void 0,name:void 0,style:void 0,id:void 0,dataTestId:void 0,kind:null===(P=R.kinds)||void 0===P?void 0:P.PRIMARY,onClick:p,size:null===(F=R.sizes)||void 0===F?void 0:F.MEDIUM,color:null===(M=R.colors)||void 0===M?void 0:M.PRIMARY,disabled:!1,rightIcon:null,leftIcon:null,success:!1,successText:"",successIcon:null,loading:!1,active:!1,marginRight:!1,marginLeft:!1,type:null===(x=R.types)||void 0===x?void 0:x.BUTTON,onMouseDown:p,rightFlat:!1,leftFlat:!1,preventClickAnimation:!1,noSidePadding:!1,onFocus:p,onBlur:p,defaultTextColorOnPrimaryColor:O,ariaHasPopup:void 0,blurOnMouseUp:!0,ariaExpanded:void 0,ariaControls:void 0,ariaLabel:void 0,ariaLabeledBy:void 0,insetFocus:!1};var B=R;export{B as default};
