'use client';
import{__rest as i}from"tslib";import t from"react";import{twMerge as e}from"tailwind-merge";import{Transition as o}from"react-transition-group";import{HorizontalPositions as n,Sizes as r,BaseColors as a}from"../../../lib/constants.js";import{borderRadius as s,border as l,boxShadow as m}from"../../../lib/shape.js";import{sizing as c}from"../../../lib/sizing.js";import{spacing as d}from"../../../lib/spacing.js";import{fontWeight as g}from"../../../lib/font.js";import{makeClassName as f}from"../../../lib/utils.js";import{iconSizes as p,getButtonColors as u,getButtonProportions as h}from"./styles.js";import b from"../../../assets/LoadingSpinner.js";const x=f("Button"),j=({loading:i,iconSize:o,iconPosition:r,Icon:a,transitionState:s})=>{const l=r===n.Left?e(d.twoXs.negativeMarginLeft,d.xs.marginRight):e(d.twoXs.negativeMarginRight,d.xs.marginLeft),m=e(c.none.width,c.none.height),g={default:m,entering:m,entered:o,exiting:o,exited:m};return i?t.createElement(b,{className:e(x("icon"),"animate-spin",l,g.default,g[s]),style:{transition:"width 150ms"}}):t.createElement(a,{className:e(x("icon"),o,l),"aria-hidden":"true"})},w=t.forwardRef(((c,d)=>{const{icon:f,iconPosition:b=n.Left,size:w=r.SM,color:S=a.Blue,variant:v="primary",disabled:z,loading:C=!1,loadingText:E,children:N,className:y}=c,R=i(c,["icon","iconPosition","size","color","variant","disabled","loading","loadingText","children","className"]),B=f,L=C||z,P=void 0!==B||C,I=C&&E,M=e(p[w].height,p[w].width),T="light"!==v?e(s.md.all,l.sm.all,m.sm):"",X=u(v,S),k=h(v)[w];return t.createElement(o,{in:C,timeout:50},(i=>t.createElement("button",Object.assign({ref:d,className:e(x("root"),"flex-shrink-0 inline-flex justify-center items-center group","focus:outline-none focus:ring-2 focus:ring-offset-2",g.md,T,k.paddingX,k.paddingY,k.fontSize,X.textColor,X.bgColor,X.borderColor,X.focusRingColor,L?"opacity-50":e(u(v,S).hoverTextColor,u(v,S).hoverBgColor,u(v,S).hoverBorderColor),y),disabled:L},R),P&&b!==n.Right?t.createElement(j,{loading:C,iconSize:M,iconPosition:b,Icon:B,transitionState:i}):null,t.createElement("span",{className:e(x("text"),"text-sm whitespace-nowrap")},I?E:N),P&&b===n.Right?t.createElement(j,{loading:C,iconSize:M,iconPosition:b,Icon:B,transitionState:i}):null)))}));w.displayName="Button";export{j as ButtonIconOrSpinner,w as default};
