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