import{G as E,g as w,aj as x}from"./entry.4a1e3e7a.js";function T(){var d;const t=w(),a=E([]),u=()=>{a.value=[]},o=t.$router,c=(d=o==null?void 0:o.currentRoute)==null?void 0:d.value,r=e=>({message:e.detail||e.title||e,type:"error"}),i=e=>{e.forEach(s=>{t.$store.dispatch("notifications/add",r(s))})},A=e=>{t.$store.commit("order/setOrderLoaded",!1),t.$store.dispatch("order/loadOrder").then(()=>{const s=t.$store.state.order.currentStep,n=s==="cart"?`/${s}/`:`/checkout/${s}/`;o.push(n),i(e)})},S=async()=>{const e=t.$store.state.csAuth.loggedIn;t.$store.commit("csAuth/resetState"),await t.$store.dispatch("csAuth/getSession"),e&&!t.$store.state.csAuth.loggedIn?(t.$store.commit("order/resetState"),t.$store.commit("cart/resetCart"),await o.push("/").then(()=>{i(["You've been logged out. Please log in again."])})):(a.value.push({message:"Something went wrong. Please try again.",type:"warning"}),setTimeout(u,3e3))};return{alerts:a,handleError:async e=>{var s,n,p,l,h,g,m,f,$;(n=(s=e.response)==null?void 0:s.data)!=null&&n.errors&&((p=c==null?void 0:c.path)!=null&&p.match(/checkout/))&&e.response.status===409?A(e.response.data.errors):((l=e.response)==null?void 0:l.status)===400||((h=e.response)==null?void 0:h.status)===418?await S():(m=(g=e.response)==null?void 0:g.data)!=null&&m.errors?e.response.data.errors.forEach(v=>{a.value.push(r(v))}):(f=e.response)!=null&&f.statusText?a.value.push(r(($=e.response)==null?void 0:$.statusText)):(console.error(e),x(e.message||e))},errorMessage:r,clearAlerts:u}}export{T as u};