"use strict";var e=require("react"),r=require("@gem-sdk/core");exports.useCartOperations=({setting:s,showMessage:o,dispatchInteractionEvent:t,dispatchCustomEvent:c})=>{let{openCart:a}=r.useCartUI(),{storefrontToken:n}=r.useStoreFront(),{cartId:u,updateCartId:l}=r.useCartId(),i=e.useCallback((e,r)=>{e?.enableMessage&&r(e.successMessage||"","success"),a()},[a]),k=(e,r)=>{if(!e.checkoutUrl)return;let s=r?`${e.checkoutUrl}?access_token=${r}`:e.checkoutUrl;window.location.href=s},b=e=>{e?.customURL?.link&&("_blank"===e.customURL.target?window.open(e.customURL.link,"_blank"):window.location.href=e.customURL.link)},g=e.useCallback(e=>{s?.actionEffect!=="buy-now"&&l(e.id);let r={"open-cart-drawer":()=>a(),"go-to-url":()=>b(s),"buy-now":()=>k(e,n),"continue-shopping":()=>i(s,o)}[s?.actionEffect];r&&r(),t(),c()},[s,n,a,o,l,t,i,c]),w=e.useCallback(e=>{s?.enableMessage&&(e?.[0]?.code==="INVALID"?o(e[0].message||"","error"):o(s.errorMessage||"","error"))},[s,o]);return{cartId:u,handleSuccess:g,handleError:w}};
