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A,OAAKE,UAAU,iCAAiCC,QAASA,IAAMR,EAAYvB,EAAiBC,EAAiBW,EAAAA,MAC7GgB,EAAAA,cAAA,OAAKE,UAAU,yCACXF,EAAAA,cAAA,SAAOI,GAAIhC,EACPiC,KAAK,SACL,6BACAC,aAAchC,EACdiC,IAAI,IACJL,UAAU,oCACV,cAAYM,EAAAA,EAAAA,GAAU,8BACtBC,OAAQA,IAAMd,EAAYvB,EAAiBC,MAEnD2B,EAAAA,cAAA,OAAKE,UAAU,iCAAiCC,QAASA,IAAMR,EAAYvB,EAAiBC,EAAiBiB,EAAAA,OAEhHf,GACGyB,EAAAA,cAAA,OAAKE,UAAU,8BAA6BM,EAAAA,EAAAA,GAAU,kCAEnD,C","sources":["webpack:///./Scripts/Components/ProductQuantity.js"],"sourcesContent":["import React, { Fragment, useState } from 'react';\nimport { translate } from '../Services/translation';\nimport { INCREASE_QTY, DECREASE_QTY } from \"../constants\"\n\n\nconst ProductQuantity = ({\n quantityFieldId,\n packingQuantity,\n defaultQuantity\n}) => {\n const [showQuantityWarning, setShowQuantityWarning] = useState(false);\n\n const toggleQuantityWarning = (show) => {\n setShowQuantityWarning(show || !showQuantityWarning);\n }\n\n const checkMultiple = (multipleQty, currentQty, el, updateType) => {\n if (currentQty === multipleQty) {\n el.value = currentQty;\n }\n else if (currentQty % multipleQty !== 0) {\n if (updateType === DECREASE_QTY) {\n let decreasedValue = Math.floor(currentQty / multipleQty) * multipleQty;\n el.value = parseFloat(decreasedValue.toFixed(1));\n }\n else if (updateType === INCREASE_QTY) {\n let increasedValue = Math.ceil(currentQty / multipleQty) * multipleQty;\n el.value = parseFloat(increasedValue.toFixed(1));\n }\n else {\n toggleQuantityWarning(true);\n let changedValue = Math.ceil(currentQty / multipleQty) * multipleQty;\n el.value = parseFloat(changedValue.toFixed(1));\n setTimeout(() => setShowQuantityWarning(false), 5000);\n }\n }\n }\n\n const updateValue = (quantityFieldId, packingQuantity, updateType) => {\n const el = document.getElementById(quantityFieldId);\n packingQuantity = parseFloat(packingQuantity);\n if (el) {\n let amountValue = el.value;\n let currentQty = parseFloat(amountValue).toFixed(1);\n if (updateType === INCREASE_QTY) {\n currentQty++;\n } else if (updateType === DECREASE_QTY && currentQty > 0) {\n currentQty--;\n }\n currentQty = isNaN(currentQty) || currentQty < packingQuantity ? packingQuantity : currentQty;\n if (updateType == null) {\n currentQty = isNaN(amountValue) ? packingQuantity : amountValue;\n }\n else if (currentQty >= packingQuantity) {\n el.value = currentQty;\n }\n checkMultiple(packingQuantity, currentQty, el, updateType);\n }\n }\n\n return (\n <Fragment>\n <div className=\"product__buy-quantity-wrapper\">\n <div className=\"product__buy-quantity-decrease\" onClick={() => updateValue(quantityFieldId, packingQuantity, DECREASE_QTY)}></div>\n <div className=\"product__buy-quantity-input-container\">\n <input id={quantityFieldId}\n type=\"number\"\n data-buy-quantity-input\n defaultValue={defaultQuantity}\n min=\"1\"\n className=\"product__buy-quantity form__input\"\n aria-label={translate('code.productquantity.label')}\n onBlur={() => updateValue(quantityFieldId, packingQuantity)} />\n </div>\n <div className=\"product__buy-quantity-increase\" onClick={() => updateValue(quantityFieldId, packingQuantity, INCREASE_QTY)}></div>\n </div>\n {showQuantityWarning &&\n <div className=\"product-quantity--warning\">{translate('code.product.quantity.changed')}</div>\n }\n </Fragment>\n );\n};\nexport default ProductQuantity;"],"names":["ProductQuantity","quantityFieldId","packingQuantity","defaultQuantity","showQuantityWarning","setShowQuantityWarning","useState","checkMultiple","multipleQty","currentQty","el","updateType","value","DECREASE_QTY","decreasedValue","Math","floor","parseFloat","toFixed","INCREASE_QTY","increasedValue","ceil","changedValue","setTimeout","updateValue","document","getElementById","amountValue","isNaN","React","Fragment","className","onClick","id","type","defaultValue","min","translate","onBlur"],"sourceRoot":""}