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