import*as e from"react";import{useButtonGroup as t}from"./button-group.js";import{omitThemingProps as n}from"../../../system/dist/esm/system.utils.js";import{dataAttr as a,cx as s}from"../../../utils/dist/esm/dom.js";import{Spinner as r}from"../../../spinner/dist/esm/spinner.js";import{forwardRef as i}from"../../../system/dist/esm/forward-ref.js";import{useStyleConfig as l}from"../../../system/dist/esm/use-style-config.js";import o from"../../../../lodash.mergewith/index.js";import{chakra as m}from"../../../system/dist/esm/system.js";import{mergeRefs as c}from"../../../react-utils/dist/esm/refs.js";import{__DEV__ as d}from"../../../utils/dist/esm/assertion.js";function p(e,t){if(null==e)return{};var n,a,s={},r=Object.keys(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||(s[n]=e[n]);return s}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var f=i(((r,i)=>{var d,f=t(),y=l("Button",u({},f,r)),b=n(r),{isDisabled:v=(null==f?void 0:f.isDisabled),isLoading:_,isActive:N,isFullWidth:j,children:E,leftIcon:S,rightIcon:x,loadingText:k,iconSpacing:I="0.5rem",type:w,spinner:O,spinnerPlacement:B="start",className:T,as:A}=b,C=p(b,["isDisabled","isLoading","isActive","isFullWidth","children","leftIcon","rightIcon","loadingText","iconSpacing","type","spinner","spinnerPlacement","className","as"]),D=o({},null!=(d=null==y?void 0:y._focus)?d:{},{zIndex:1}),P=u({display:"inline-flex",appearance:"none",alignItems:"center",justifyContent:"center",userSelect:"none",position:"relative",whiteSpace:"nowrap",verticalAlign:"middle",outline:"none",width:j?"100%":"auto"},y,!!f&&{_focus:D}),{ref:z,type:F}=function(t){var[n,a]=e.useState(!t),s=e.useCallback((e=>{e&&a("BUTTON"===e.tagName)}),[]),r=n?"button":void 0;return{ref:s,type:r}}(A);return e.createElement(m.button,u({disabled:v||_,ref:c(i,z),as:A,type:null!=w?w:F,"data-active":a(N),"data-loading":a(_),__css:P,className:s("chakra-button",T)},C),S&&!_&&e.createElement(h,{marginEnd:I},S),_&&"start"===B&&e.createElement(g,{className:"chakra-button__spinner--start",label:k,placement:"start"},O),_?k||e.createElement(m.span,{opacity:0},E):E,_&&"end"===B&&e.createElement(g,{className:"chakra-button__spinner--end",label:k,placement:"end"},O),x&&!_&&e.createElement(h,{marginStart:I},x))}));d&&(f.displayName="Button");var h=t=>{var{children:n,className:a}=t,r=p(t,["children","className"]),i=e.isValidElement(n)?e.cloneElement(n,{"aria-hidden":!0,focusable:!1}):n,l=s("chakra-button__icon",a);return e.createElement(m.span,u({display:"inline-flex",alignSelf:"center",flexShrink:0},r,{className:l}),i)};d&&(h.displayName="ButtonIcon");var g=t=>{var{label:n,placement:a,children:i=e.createElement(r,{color:"currentColor",width:"1em",height:"1em"}),className:l,__css:o}=t,c=p(t,["label","placement","spacing","children","className","__css"]),d=s("chakra-button__spinner",l),f=u({display:"flex",alignItems:"center",position:n?"relative":"absolute",["start"===a?"marginEnd":"marginStart"]:n?"0.5rem":0,fontSize:"1em",lineHeight:"normal"},o);return e.createElement(m.div,u({className:d},c,{__css:f}),i)};d&&(g.displayName="ButtonSpinner");export{f as Button};
//# sourceMappingURL=button.js.map
