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