import{useInteraction as e}from"@gem-sdk/core";let t=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})},d=(e=0)=>{e<=0?c(e):a(e)};return{dispatchStockCounterInteraction:(e=0)=>{let t=()=>{d(e),window.removeEventListener("gp:flow-actions-loaded",t)};window.interactionLoaded?d(e):window.addEventListener("gp:flow-actions-loaded",t)}}};export{t as useStockCounterInteraction};
