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