import{slicedToArray as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as n}from"react/jsx-runtime";import{useState as o,useRef as i,useCallback as t,useEffect as r,useMemo as a}from"react";import s from"classnames";import{SwitchTransition as c,CSSTransition as l}from"react-transition-group";import u from"../../hooks/useEventListener/index.js";import m from"../../hooks/useAfterFirstRender/index.js";import{NOOP as d}from"../../utils/function-utils.js";import{backwardCompatibilityForProperties as p}from"../../helpers/backwardCompatibilityForProperties.js";import{getActualSize as f,CounterSize as b,CounterColor as j,CounterType as v}from"./CounterConstants.js";import"./Counter.scss.js";var g=function(d){var b=d.count,j=d.size,v=d.kind,g=d.color,h=d.maxDigits,y=d.ariaLabeledBy,L=d.ariaLabel,x=d.id,k=d.prefix,w=d.onMouseDown,N=d.noAnimation,O=p([d.className,d.wrapperClassName],void 0),A=o(!1),M=e(A,2),C=M[0],D=M[1],z=i(null),E=t((function(){D(!0)}),[D]),P=t((function(){D(!1)}),[D]);u({eventName:"animationend",callback:P,ref:z});var R=m();r((function(){R.current||E()}),[b,R,E]),r((function(){h>0||console.error("Max digits must be a positive number")}),[h]);var B=a((function(){return s("l3-style-counter","l3-style-counter--size-".concat(f(j)),"l3-style-counter--kind-".concat(v),"l3-style-counter--color-".concat(g),{"l3-style-counter--with-animation":C})}),[j,v,g,C]),F=(null==b?void 0:(""+b).length)>h?"".concat(Math.pow(10,h)-1,"+"):b+"",I=n("span",Object.assign({id:"counter-".concat(x)},{children:k+F}));return n("span",Object.assign({className:O,"aria-label":"".concat(L," ").concat(F),"aria-labelledby":y,onMouseDown:w},{children:n("div",Object.assign({className:B,"aria-label":F,ref:z},{children:N?I:n(c,Object.assign({mode:"out-in"},{children:n(l,Object.assign({classNames:"l3-style-counter--fade",addEndListener:function(e,n){e.addEventListener("transitionend",n,!1)}},{children:n("span",Object.assign({id:"counter-".concat(x)},{children:k+F}))}),F)}))}))}))};Object.assign(g,{sizes:b,colors:j,kinds:v}),g.defaultProps={ariaLabel:"",ariaLabeledBy:"",className:void 0,color:j.PRIMARY,count:0,id:"",kind:v.FILL,maxDigits:3,noAnimation:!1,onMouseDown:d,prefix:"",size:b.LARGE};var h=g;export{h as default};
