import{r as U,J as q,h as F,ad as v,g as s,Y as c,a1 as n,p as f,j as b,ae as W,a9 as z,af as K,c as w,i as y,o as O,a2 as Y,a3 as $,P as i,U as j,M as x}from"./vendor-vue-gvI8EVHg.js";/* empty css                                                                  */import{Y as H,X as J,b as X,k as G,a as Q}from"./index-DCLQfd0E.js";import"./vendor-misc-DVqRnJX7.js";/* empty css                                                                       */import{_ as Z}from"./AuthLayout.vue_vue_type_script_setup_true_lang-BlY_Nc5E.js";import{u as ee}from"./vendor-i18n-DnQQ95F5.js";const te={class:"space-y-6"},ae={class:"text-center"},se={class:"text-2xl font-bold text-gray-900 dark:text-white"},re={class:"mt-2 text-sm text-gray-500 dark:text-dark-400"},oe={key:0,class:"space-y-4"},ne={class:"text-sm text-gray-700 dark:text-gray-300"},ie=["placeholder","disabled"],le={key:0,class:"text-sm text-red-600 dark:text-red-400"},ce=["disabled"],ue={key:0,class:"rounded-xl border border-red-200 bg-red-50 p-4 dark:border-red-800/50 dark:bg-red-900/20"},de={class:"flex items-start gap-3"},_e={class:"flex-shrink-0"},he={class:"space-y-2"},ve={class:"text-sm text-red-700 dark:text-red-400"},fe=U({__name:"LinuxDoCallbackView",setup(pe){const L=Y(),S=$(),{t}=ee(),C=H(),u=J(),d=i(!0),r=i(""),T=i(!1),g=i(""),_=i(""),I=i(""),h=i(!1),p=i(""),D=i("/dashboard");function M(){const e=typeof window<"u"?window.location.hash:"",o=e.startsWith("#")?e.slice(1):e;return new URLSearchParams(o)}function P(e){return!e||!e.startsWith("/")||e.startsWith("//")||e.includes("://")||e.includes(`
`)||e.includes("\r")?"/dashboard":e}async function R(){var e,o;if(p.value="",!!_.value.trim()){h.value=!0;try{const a=await G(g.value,_.value.trim(),I.value||void 0);a.refresh_token&&localStorage.setItem("refresh_token",a.refresh_token),a.expires_in&&localStorage.setItem("token_expires_at",String(Date.now()+a.expires_in*1e3)),await C.setToken(a.access_token),u.showSuccess(t("auth.loginSuccess")),await S.replace(D.value)}catch(a){const l=a;p.value=((o=(e=l.response)==null?void 0:e.data)==null?void 0:o.message)||l.message||t("auth.linuxdo.completeRegistrationFailed")}finally{h.value=!1}}}return q(async()=>{var V,E;const e=M(),o=e.get("access_token")||"",a=e.get("refresh_token")||"",l=e.get("expires_in")||"",A=P(e.get("redirect")||L.query.redirect||"/dashboard"),k=e.get("error"),B=e.get("error_description")||e.get("error_message")||"";if(k){if(k==="invitation_required"){if(g.value=e.get("pending_oauth_token")||"",I.value=String(e.get("invite_code")||"").trim().toUpperCase(),D.value=P(e.get("redirect")),!g.value){r.value=t("auth.linuxdo.invalidPendingToken"),u.showError(r.value),d.value=!1;return}T.value=!0,d.value=!1;return}r.value=B||k,u.showError(r.value),d.value=!1;return}if(!o){r.value=t("auth.linuxdo.callbackMissingToken"),u.showError(r.value),d.value=!1;return}try{if(a&&localStorage.setItem("refresh_token",a),l){const m=parseInt(l,10);isNaN(m)||localStorage.setItem("token_expires_at",String(Date.now()+m*1e3))}await C.setToken(o),u.showSuccess(t("auth.loginSuccess")),await S.replace(A)}catch(m){const N=m;r.value=((E=(V=N.response)==null?void 0:V.data)==null?void 0:E.detail)||N.message||t("auth.loginFailed"),u.showError(r.value),d.value=!1}}),(e,o)=>{const a=j("router-link");return x(),F(n(Z),null,{default:v(()=>[s("div",te,[s("div",ae,[s("h2",se,c(n(t)("auth.linuxdo.callbackTitle")),1),s("p",re,c(d.value?n(t)("auth.linuxdo.callbackProcessing"):n(t)("auth.linuxdo.callbackHint")),1)]),f(w,{name:"fade"},{default:v(()=>[T.value?(x(),b("div",oe,[s("p",ne,c(n(t)("auth.linuxdo.invitationRequired")),1),s("div",null,[W(s("input",{"onUpdate:modelValue":o[0]||(o[0]=l=>_.value=l),type:"text",class:"input w-full",placeholder:n(t)("auth.invitationCodePlaceholder"),disabled:h.value,onKeyup:K(R,["enter"])},null,40,ie),[[z,_.value]])]),f(w,{name:"fade"},{default:v(()=>[p.value?(x(),b("p",le,c(p.value),1)):y("",!0)]),_:1}),s("button",{class:"btn btn-primary w-full",disabled:h.value||!_.value.trim(),onClick:R},c(h.value?n(t)("auth.linuxdo.completing"):n(t)("auth.linuxdo.completeRegistration")),9,ce)])):y("",!0)]),_:1}),f(w,{name:"fade"},{default:v(()=>[r.value?(x(),b("div",ue,[s("div",de,[s("div",_e,[f(X,{name:"exclamationCircle",size:"md",class:"text-red-500"})]),s("div",he,[s("p",ve,c(r.value),1),f(a,{to:"/login",class:"btn btn-primary"},{default:v(()=>[O(c(n(t)("auth.linuxdo.backToLogin")),1)]),_:1})])])])):y("",!0)]),_:1})])]),_:1})}}}),Se=Q(fe,[["__scopeId","data-v-1256bdd7"]]);export{Se as default};
