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