"use strict";const n=require("react/jsx-runtime"),_=require("react"),X=require("./spinner-tKunS_o-.js"),J=require("./text-field-B8a-NKm4.js"),C=require("./bind-DeUYJ6m9.js"),K=require("./button-ChYUPi2k.js"),V=require("./icon-DNHpBTHs-faYHqTXU.js"),L={"purpur-quantity-selector":"_purpur-quantity-selector_pun3b_1","purpur-quantity-selector--full-width":"_purpur-quantity-selector--full-width_pun3b_25","purpur-quantity-selector--loading":"_purpur-quantity-selector--loading_pun3b_31","purpur-quantity-selector--no-gap":"_purpur-quantity-selector--no-gap_pun3b_34","purpur-quantity-selector--no-gap-disabled-left":"_purpur-quantity-selector--no-gap-disabled-left_pun3b_39","purpur-quantity-selector--no-gap-disabled-right":"_purpur-quantity-selector--no-gap-disabled-right_pun3b_43","purpur-quantity-selector--no-gap-disabled":"_purpur-quantity-selector--no-gap-disabled_pun3b_39","purpur-quantity-selector__spinner":"_purpur-quantity-selector__spinner_pun3b_50","purpur-quantity-selector__spinner--full-width":"_purpur-quantity-selector__spinner--full-width_pun3b_57","purpur-quantity-selector__spinner--separated":"_purpur-quantity-selector__spinner--separated_pun3b_61"},Y={name:"minus",svg:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M4.1 12a.9.9 0 0 1 .9-.9h14a.9.9 0 1 1 0 1.8H5a.9.9 0 0 1-.9-.9Z" clip-rule="evenodd"/></svg>',keywords:["minus"],category:"utility"},D=u=>n.jsx(V.b,{...u,svg:Y});D.displayName="IconMinus";const G={name:"plus",svg:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M12 4.1a.9.9 0 0 1 .9.9v6.1H19a.9.9 0 1 1 0 1.8h-6.1V19a.9.9 0 0 1-1.8 0v-6.1H5a.9.9 0 0 1 0-1.8h6.1V5a.9.9 0 0 1 .9-.9Z" clip-rule="evenodd"/></svg>',keywords:["plus"],category:"utility"},F=u=>n.jsx(V.b,{...u,svg:G});F.displayName="IconPlus";const W={"purpur-quantity-selector-button":"_purpur-quantity-selector-button_qjlbs_1","purpur-quantity-selector-button--gap-left":"_purpur-quantity-selector-button--gap-left_qjlbs_4","purpur-quantity-selector-button--gap-right":"_purpur-quantity-selector-button--gap-right_qjlbs_7","purpur-quantity-selector-button--no-gap-right":"_purpur-quantity-selector-button--no-gap-right_qjlbs_10","purpur-quantity-selector-button--no-gap-left":"_purpur-quantity-selector-button--no-gap-left_qjlbs_13"},T=C.c.bind(W),b="purpur-quantity-selector-button",tt=({["data-testid"]:u,disabled:m,hasGap:e,variant:f,buttonType:r,onClick:o})=>{const h=T(b,{[`${b}--gap-left`]:e&&r==="decrement",[`${b}--gap-right`]:e&&r==="increment",[`${b}--no-gap-left`]:!e&&r==="decrement",[`${b}--no-gap-right`]:!e&&r==="increment"});return n.jsx(K.Button,{"data-testid":u,className:h,size:"sm",type:"submit",variant:f,onClick:()=>o(r),iconOnly:!0,disabled:m,tabIndex:-1,children:r==="increment"?n.jsx(F,{size:"xs"}):n.jsx(D,{size:"xs"})})},B=C.c.bind(L),et=["attached","separated"],nt=["primary","secondary"],s="purpur-quantity-selector",R=_.forwardRef(({["data-testid"]:u,className:m,variant:e,buttonVariant:f,onChange:r,value:o,defaultValue:h,fullWidth:x,disabled:k,loading:v,minValue:E,maxValue:H,ariaLabelDecrement:M,ariaLabelIncrement:z,...Q},I)=>{const[O,$]=_.useState(h??0),[w,j]=_.useState(O),a=o!==void 0,l=a?o:w,S=t=>u?`${u}-${t}`:void 0,i=k||v,g=Math.max(E??0,0),q=H??Number.MAX_SAFE_INTEGER,p=l===q,d=l===g;_.useEffect(()=>{a&&$(o)},[o,a]),_.useEffect(()=>{if(!a){const t=setTimeout(()=>{$(w)},300);return()=>clearTimeout(t)}},[w,a,r]);const A=B(m,s,{[`${s}--no-gap`]:e==="attached"&&!i&&!d&&!p,[`${s}--no-gap-disabled-left`]:e==="attached"&&!i&&!p&&d,[`${s}--no-gap-disabled-right`]:e==="attached"&&!i&&!d&&p,[`${s}--no-gap-disabled`]:e==="attached"&&(i||p&&d),[`${s}--full-width`]:x,[`${s}--loading`]:v}),Z=t=>{if(!/^[0-9]*$/.test(t.target.value))return;const y=+t.target.value;y<g||y>q||(a||j(y),r(y))},P=t=>{const c=t==="increment"?l+1:l-1;c<0||(a||j(c),r(c))},N=t=>{const c=t==="increment"&&p||t==="decrement"&&d;return n.jsx(tt,{"data-testid":S("button-"+t),variant:f,buttonType:t,hasGap:e==="separated",onClick:P,disabled:i||c,"aria-label":t==="increment"?z:M})},U=n.jsxs(n.Fragment,{children:[v&&n.jsx("div",{className:B(`${s}__spinner`,{[`${s}__spinner--full-width`]:x,[`${s}__spinner--separated`]:!x&&e==="separated"}),children:n.jsx(X.Spinner,{disabled:i,size:"xs","data-testid":S("spinner")},"spinner")}),N("decrement")]});return n.jsx(J.TextField,{value:l,type:"number",ref:I,className:A,"data-testid":u,onChange:Z,beforeField:U,afterField:N("increment"),disabled:i,min:g,max:q,role:"spinbutton","aria-valuenow":l,"aria-valuemax":q,"aria-valuemin":g,...Q})});R.displayName="QuantitySelector";exports.QuantitySelector=R;exports.quantitySelectorButtonVariants=nt;exports.quantitySelectorVariants=et;
//# sourceMappingURL=quantity-selector-DPOTlMSq.js.map
