Liferay.Loader.define("commerce-frontend-js@4.0.75/components/quantity_selector/InputQuantitySelector",["module","exports","require","@frontend-taglib-clay$clayui/form","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$react","../../utilities/quantities","./RulesPopover"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=_interopRequireWildcard(r("@frontend-taglib-clay$clayui/form")),a=r("@liferay/frontend-js-react-web"),u=_interopRequireDefault(r("liferay!frontend-js-react-web$classnames")),i=r("frontend-js-web"),l=_interopRequireWildcard(r("liferay!frontend-js-react-web$react")),o=r("../../utilities/quantities"),c=_interopRequireDefault(r("./RulesPopover"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var u=n?Object.getOwnPropertyDescriptor(e,a):null;u&&(u.get||u.set)?Object.defineProperty(r,a,u):r[a]=e[a]}return r.default=e,t&&t.set(e,r),r}const getErrors=(e,t,r,n)=>{const a=[];return(!e||e<t)&&a.push("min"),r&&e>r&&a.push("max"),n>1&&e%n&&a.push("multiple"),a},e=(0,l.forwardRef)((({alignment:e,className:t,disabled:r,max:s,min:f,name:d,onUpdate:p,quantity:m,step:y},b)=>{const[g,_]=(0,l.useState)(!1),[j,q]=(0,l.useState)((()=>getErrors(m,f,s,y))),w=(0,a.useIsMounted)(),R=(0,l.useRef)((0,i.debounce)((e=>{w()&&q(e)}),500));(0,l.useEffect)((()=>{R.current((()=>getErrors(m,f,s,y)))}),[m,f,s,y]);const v=(0,o.getProductMaxQuantity)(s,y),h=(0,o.getMinQuantity)(f,y);return l.default.createElement(n.default.Group,{className:(0,u.default)({"has-error":j.length,"mb-0":!0})},l.default.createElement(n.ClayInput,{className:t,disabled:r,max:v,min:h,name:d,onBlur:()=>{_(!1)},onChange:({target:e})=>{const t=Number(e.value),r=getErrors(t,f,s,y);p({errors:r,value:t})},onFocus:()=>_(!0),ref:b,step:y>1?y:"",type:"number",value:String(m||"")}),g&&(y>1||f>1||j.includes("max"))&&l.default.createElement(c.default,{alignment:e,errors:j,inputRef:b,max:s||"",min:f,multiple:y}))}));e.defaultProps={max:null,min:1,step:1};var s=e;t.default=s}}));
//# sourceMappingURL=InputQuantitySelector.js.map