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