"use strict";var core=require("@gem-sdk/core"),React=require("react");const useHandleQuantity=(e,t,a)=>{let u=core.useIsSyncProduct(),r=core.useProduct(),s=a?.defaultQtyValue??1,[c,n]=React.useState(""),i=React.useCallback(a=>{let s=a.detail,c=r?.id;u&&s&&c==s.productId&&e!=s.quantity&&t(s.quantity)},[u,r?.id,e,t]);React.useEffect(()=>(window.addEventListener("set-product-quantity",i),()=>{window.removeEventListener("set-product-quantity",i)}),[i]);let d=e=>{let a=e.target.value,u=1>Number(a)||isNaN(Number(a))?1:Number(a);t(u),n(`${u}`)},l=e=>{isNaN(Number(e.target.value))||""===e.target.value||n(parseInt(e.target.value).toString())};return React.useEffect(()=>{t(parseFloat(`${s}`)),n(`${s}`)},[t,s]),React.useEffect(()=>{n(`${e}`)},[e]),{value:c,onBlurInput:d,onChangeInput:l}};exports.useHandleQuantity=useHandleQuantity;
