import{useInteraction as e}from"@gem-sdk/core";let useStockCounterInteraction=t=>{let{uid:o,element:n}=t,{trigger:r}=e(),c=e=>{r({event:"gp:rollback:stock-change",selector:`[data-id="${o}"]`,element:n?.current}),r({event:"gp:rollback:out-of-stock",selector:`[data-id="${o}"]`,element:n?.current}),r({event:"gp:out-of-stock",selector:`[data-id="${o}"]`,data:e,element:n?.current})},a=e=>{r({event:"gp:rollback:stock-change",selector:`[data-id="${o}"]`,element:n?.current}),r({event:"gp:rollback:out-of-stock",selector:`[data-id="${o}"]`,element:n?.current}),r({event:"gp:stock-change",selector:`[data-id="${o}"]`,data:e,element:n?.current})},l=(e=0)=>{e<=0?c(e):a(e)},d=(e=0)=>{let t=()=>{l(e),window.removeEventListener("gp:flow-actions-loaded",t)};window.interactionLoaded?l(e):window.addEventListener("gp:flow-actions-loaded",t)};return{dispatchStockCounterInteraction:d}};export{useStockCounterInteraction};
