Liferay.Loader.define("@liferay/frontend-data-set-web@1.0.31/quantity_selector/QuantitySelector",["module","exports","require","@frontend-taglib-clay$clayui/icon","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=d(a("@frontend-taglib-clay$clayui/icon")),u=d(a("liferay!frontend-js-react-web$classnames")),l=d(a("liferay!frontend-js-react-web$prop-types")),r=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=i();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if(Object.prototype.hasOwnProperty.call(e,u)){var l=n?Object.getOwnPropertyDescriptor(e,u):null;l&&(l.get||l.set)?Object.defineProperty(a,u,l):a[u]=e[u]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"));function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function d(e){return e&&e.__esModule?e:{default:e}}function o({allowedQuantities:e,appendedIcon:t,appendedText:a,disabled:l,inputName:i,maxQuantity:d,minQuantity:o,multipleQuantity:p,prependedIcon:f,prependedText:s,quantity:c,size:m,style:y,updateQuantity:b}){const[g,v]=(0,r.useState)(c),[E,N]=(0,r.useState)(g+p<=d),[w,j]=(0,r.useState)(g-p>=o);function x(){E&&v(g+p)}function Q(){w&&v(g-p)}function k(e){var t;(t=parseInt(e.target.value,10))>=o&&t<=d&&t%p==0&&v(t)}let O,h;(0,r.useEffect)((()=>{v(c)}),[c,v]),(0,r.useEffect)((()=>{b&&b(g)}),[g,b]),(0,r.useEffect)((()=>{N(g+p<=d),j(g-p>=o)}),[g,d,o,p]),"large"===m&&(O="btn-lg",h="form-control-lg"),"small"===m&&(O="btn-sm",h="form-control-sm");return r.default.createElement("div",{className:"quantity-selector"},e?r.default.createElement(r.default.Fragment,null,r.default.createElement("select",{className:(0,u.default)("form-control",h),name:i,onChange:function(e){e.preventDefault(),v(e.target.value)},value:g},e.map((e=>r.default.createElement("option",{key:e,value:e},e))))):"simple"===y?r.default.createElement("div",{className:"input-group input-group-sm simple"},(f||s)&&r.default.createElement("div",{className:"input-group-item input-group-item-shrink input-group-prepend"},r.default.createElement("span",{className:"input-group-text"},f?r.default.createElement(n.default,{symbol:f}):s)),r.default.createElement("div",{className:(0,u.default)("input-group-item input-group-item-shrink",(t||a)&&"input-group-prepend")},r.default.createElement("input",{className:(0,u.default)("form-control text-center",h),disabled:l,max:d,min:o,name:i,onChange:k,step:p,type:"number",value:g})),(t||a)&&r.default.createElement("div",{className:"input-group-append input-group-item input-group-item-shrink"},r.default.createElement("span",{className:"input-group-text"},t?r.default.createElement(n.default,{symbol:t}):a))):r.default.createElement("div",{className:"input-group justify-content-center"},r.default.createElement("div",{className:"input-group-item input-group-item-shrink input-group-prepend"},r.default.createElement("button",{className:(0,u.default)("btn btn-monospaced btn-secondary",O),disabled:l||!w,onClick:Q},r.default.createElement(n.default,{symbol:"hr"}))),r.default.createElement("div",{className:"input-group-item input-group-prepend"},r.default.createElement("input",{className:(0,u.default)("form-control text-center",h),disabled:l,name:i,onChange:k,onKeyUp:function(e){38===Number(e.keyCode)?x():40===Number(e.keyCode)&&Q()},type:"text",value:g})),r.default.createElement("div",{className:"input-group-append input-group-item input-group-item-shrink"},r.default.createElement("button",{className:(0,u.default)("btn btn-monospaced btn-secondary",O),disabled:l||!E,onClick:x},r.default.createElement(n.default,{symbol:"plus"})))))}o.propTypes={allowedQuantities:l.default.arrayOf(l.default.number),appendedIcon:l.default.string,appendedText:l.default.string,disabled:l.default.bool,inputName:l.default.string,maxQuantity:l.default.number,minQuantity:l.default.number,multipleQuantity:l.default.number,prependedIcon:l.default.string,prependedText:l.default.string,quantity:l.default.number,size:l.default.oneOf(["large","medium","small"]),style:l.default.oneOf(["default","simple"]),updateQuantity:l.default.func},o.defaultProps={disabled:!1,maxQuantity:99999999,minQuantity:1,multipleQuantity:1,style:"default"};var p=o;t.default=p}}));
//# sourceMappingURL=QuantitySelector.js.map