"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("../../_virtual/jsx-runtime.js"),q=require("react"),L=require("../../icons/AlertTriangle.js"),N=require("../../icons/Minus.js"),O=require("../../icons/Plus.js"),w=require("../IconButton/index.js"),a=require("../../utils/index.js"),j=require("./styles.js"),u=require("../Field/styles.js");function z({step:s=1,min:n,max:d,value:t,id:y,label:o,optionalText:I,name:x,errorText:g,assistText:p,onChange:S=a.noop,touched:E,disabled:i=!1,required:B=!0,hasError:b=!1,fullWidth:F=!1,stepperVariant:l="default",componentHeight:m="medium",iconButtonVariant:$="ghost",...c},A){const[f,M]=q.useState(!1),R=a.getId(c["data-testid"]),h=a.getId(c["data-testid"]),k=e=>{S&&S(e)},C=()=>{let e;a.isDifferentFromUndefinedOrNull(n)?t>n?t-s<n?e=n:e=t-s:e=t:e=t-s,e!==t&&k(e)},D=()=>{let e;a.isDifferentFromUndefinedOrNull(d)?t<d?t+s>d?e=d:e=t+s:e=t:e=t+s,e!==t&&k(e)};return q.useEffect(()=>{M(typeof E>"u"?b:b&&E)},[b,E]),r.jsxRuntimeExports.jsxs(j.Wrapper,{fullWidth:F,"data-testid":`${c["data-testid"]}-stepper`,children:[r.jsxRuntimeExports.jsxs(u.LabelWrapper,{disabled:i,hasLabel:!!(o!=null&&o.length),children:[o&&r.jsxRuntimeExports.jsx(u.Label,{htmlFor:y||`input-${x}`,disabled:i,children:o}),!B&&r.jsxRuntimeExports.jsx(u.Text,{children:I})]}),r.jsxRuntimeExports.jsx(j.FocusBorder,{children:r.jsxRuntimeExports.jsxs(j.Border,{hasError:f,disabled:i,stepperVariant:l,children:[r.jsxRuntimeExports.jsx(w.IconButton,{onClick:C,variant:$,size:m,icon:r.jsxRuntimeExports.jsx(N.default,{}),disabled:i||t-s<n,"aria-label":`Remove ${s}`,"aria-labelledby":"step-decrement label-text","data-testid":R("stepper-minus-button"),"data-trackid":h("stepper-minus-button")}),r.jsxRuntimeExports.jsx(j.NumberField,{buttonsDisabled:i,ref:A,id:y||x&&`input-${x}`,type:"number",value:t,min:n,max:d,name:x,disabled:!0,componentHeight:m,stepperVariant:l,hasError:f,"aria-label":c["aria-label"]||o,"aria-live":"polite","aria-labelledby":"label-number","data-testid":R("stepper-number-field"),"data-trackid":h("stepper-number-field")}),r.jsxRuntimeExports.jsx(w.IconButton,{onClick:D,variant:$,size:m,icon:r.jsxRuntimeExports.jsx(O.default,{}),disabled:i||t+s>d,"aria-label":`Add ${s}`,"aria-labelledby":"step-increment label-text","data-testid":R("stepper-plus-button"),"data-trackid":h("stepper-plus-button")})]})}),r.jsxRuntimeExports.jsxs(u.SupportingText,{children:[!!g&&f&&!i&&(l==null?void 0:l.includes("input"))&&r.jsxRuntimeExports.jsxs(u.ErrorMessage,{children:[r.jsxRuntimeExports.jsx(L.default,{width:20,height:20}),g]}),!f&&(typeof p=="string"?r.jsxRuntimeExports.jsx(u.AssistMessage,{children:p}):p)]})]})}const P=q.forwardRef(z);exports.Stepper=P;
