{"version":3,"file":"shared.quantityInput.min.js","names":["m","$","bindQuantityInput","input","subtractBtn","increaseBtn","onChange","isOutOfStock","dataset","toLowerCase","initialQuantity","parseInt","value","maxQuantity","max","isNaN","disabled","min","addEventListener","e","newValue","target","Math","currentAmount","setValue","trigger","window","ooooby","jQuery"],"sources":["shared.quantityInput.js"],"mappings":"CAAC,SAAUA,EAAGC,GACZD,EAAEE,kBAAoB,CACdC,EACAC,EACAC,EACAC,EAAW,QAEX,MAAMC,EAA6D,SAA9CJ,EAAMK,QAAQD,cAAcE,cAC3CC,EAAkBC,SAASR,EAAMS,OAEvC,IAAIC,EAAcF,SAASR,EAAMW,KACjCD,EAAcE,MAAMF,GAAe,GAAKA,EACpCN,IACFM,EAAcH,GAGhBN,EAAYY,SAA+B,IAApBN,EACvBL,EAAYW,SAAWT,GAAgBG,IAAoBG,EAC3DV,EAAMW,IAAMD,EACZV,EAAMc,IAAM,EACO,GAAfJ,IACFV,EAAMa,UAAW,GAGnBb,EAAMe,iBAAiB,QAASC,IAC9B,IAAIC,EAAWT,SAASQ,EAAEE,OAAOT,OACjCQ,EAAWL,MAAMK,GAAY,EAAIA,EACjCA,EAAWE,KAAKL,IAAIK,KAAKR,IAAIM,EAAU,GAAIP,GAE3CR,EAAYW,SAAYT,GAAgBa,IAAaV,GAAoBU,IAAaP,EACtFT,EAAYY,SAAwB,IAAbI,EACvBD,EAAEE,OAAOT,MAAQQ,EACjBd,GAAYA,EAASc,EAAS,IAGhCf,EAAYa,iBAAiB,SAAS,KACpC,MAAMK,EAAgBZ,SAASR,EAAMS,OACrCY,EAASD,EAAgB,EAAE,IAG7BnB,EAAYc,iBAAiB,SAAS,KACpC,MAAMK,EAAgBZ,SAASR,EAAMS,OACrCY,EAASD,EAAgB,EAAE,IAG7B,MAAMC,EAAYJ,IAChBA,EAAWE,KAAKL,IAAIK,KAAKR,IAAIM,EAAU,GAAIP,GAE3CR,EAAYW,SAAYT,GAAgBa,IAAaV,GAAoBU,IAAaP,EACtFT,EAAYY,SAAwB,IAAbI,EACvBjB,EAAMS,MAAQQ,EACdd,GAAYA,EAASc,GACrBnB,EAAEE,GAAOsB,QAAQ,SAAS,EAG5B,MAAO,CAAED,WAAS,CAE5B,CAzDA,CAyDEE,OAAOC,OAASD,OAAOC,QAAU,CAAC,EAAGC","ignoreList":[],"sourcesContent":["(function (m, $) {\n m.bindQuantityInput = (\n input,\n subtractBtn,\n increaseBtn,\n onChange = null\n ) => {\n const isOutOfStock = input.dataset.isOutOfStock?.toLowerCase() === \"true\";\n const initialQuantity = parseInt(input.value);\n\n let maxQuantity = parseInt(input.max);\n maxQuantity = isNaN(maxQuantity) ? 60 : maxQuantity;\n if (isOutOfStock) {\n maxQuantity = initialQuantity\n }\n \n subtractBtn.disabled = initialQuantity === 0;\n increaseBtn.disabled = isOutOfStock || initialQuantity === maxQuantity;\n input.max = maxQuantity;\n input.min = 0;\n if (maxQuantity == 0) {\n input.disabled = true;\n }\n \n input.addEventListener(\"blur\", (e) => {\n let newValue = parseInt(e.target.value);\n newValue = isNaN(newValue) ? 0 : newValue;\n newValue = Math.min(Math.max(newValue, 0), maxQuantity);\n\n increaseBtn.disabled = (isOutOfStock && newValue === initialQuantity) || newValue === maxQuantity;\n subtractBtn.disabled = newValue === 0;\n e.target.value = newValue;\n onChange && onChange(newValue);\n })\n \n increaseBtn.addEventListener(\"click\", () => {\n const currentAmount = parseInt(input.value);\n setValue(currentAmount + 1);\n });\n \n subtractBtn.addEventListener(\"click\", () => {\n const currentAmount = parseInt(input.value);\n setValue(currentAmount - 1);\n });\n \n const setValue = (newValue) => {\n newValue = Math.min(Math.max(newValue, 0), maxQuantity);\n\n increaseBtn.disabled = (isOutOfStock && newValue === initialQuantity) || newValue === maxQuantity;\n subtractBtn.disabled = newValue === 0;\n input.value = newValue;\n onChange && onChange(newValue);\n $(input).trigger('change');\n }\n\n return { setValue }\n };\n}(window.ooooby = window.ooooby || {}, jQuery));"]}