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