import{useInteraction as t}from"@gem-sdk/core";import{useCallback as e}from"react";let useDispatchInteractionEvent=a=>{let{trigger:r}=t();return e(()=>{let t=document.querySelector(`[data-id="${a}"]`);if(!t)return;let e=JSON.parse(t?.getAttribute("gp-interaction-after-submit")??"{}");Object.keys(e).length<=0||Object.entries(e).forEach(([e])=>{r({event:"gp:after-submit",selector:`[data-id="${a}"]`,data:Number(e),element:t})})},[a,r])},useDispatchCustomEvent=({product:t,currentVariant:a,quantity:r})=>e(()=>{let e=new CustomEvent("gp:add-to-cart-success",{detail:{data:{product:t,variant:a,quantity:r}}});window.dispatchEvent(e)},[t,a,r]);export{useDispatchCustomEvent,useDispatchInteractionEvent};
