import{d as P,U as w,a1 as v,k as A,l as g,V as l,p as L,$ as W}from"./m2W8DxR4.js";import{u as x}from"./CtM3ip2k.js";import"./BHFrVWfd.js";const k=P({__name:"[code]",async setup(U){var m,h;let r,n;const c=w(),p=L(),d=v(),{availableLocales:i}=A();function _(t){var f;const a=t;return(f=a==null?void 0:a.data)!=null&&f.message&&typeof a.data.message=="string"?a.data.message:a!=null&&a.message&&typeof a.message=="string"?a.message:null}const y=Array.isArray(c.params.code)?c.params.code[0]:c.params.code,{data:$,error:u}=([r,n]=g(()=>x(`${p.public.apiBase}utm`,{method:"POST",body:{shorten_code:y}},"$IUk-I8oFhh")),r=await r,n(),r);if(u.value){const t=_(u.value)||"Campaign not found";throw l({statusCode:404,statusMessage:t})}const e=$.value,o=(h=(m=e==null?void 0:e.data)==null?void 0:m.redirect_url)==null?void 0:h.trim();if(!(e!=null&&e.success)||!o){const t=e&&typeof e.message=="string"&&e.message||"Campaign not found";throw l({statusCode:404,statusMessage:t})}let s=o;if(!o.startsWith("/"))try{const t=new URL(o);s=`${t.pathname}${t.search}${t.hash}`||"/"}catch{s=o.startsWith("/")?o:`/${o}`}s.startsWith("/")||(s=`/${s}`);const C=(Array.isArray(i)?i.some(t=>s===`/${t}`||s.startsWith(`/${t}/`)||s.startsWith(`/${t}?`)):!1)?s:d(s);return[r,n]=g(()=>W(C,{replace:!0})),await r,n(),()=>{}}});export{k as default};
