import{d as U,r as n,o as W,U as q,W as F,D as K,G as v,A as s,k as f,K as c,u as i,y as b,J as w,O,a0 as z,a5 as j,N as y,a1 as G,Q as H,B as x}from"./vendor-vue-CcL5gLKJ.js";/* empty css                                                                  */import{u as J,c as Q,_ as $,j as X,d as Y}from"./index-96Zm5C3V.js";import"./vendor-misc-BtWKXjYI.js";/* empty css                                                                       */import{A as Z}from"./AuthLayout-N355QFDc.js";import{u as ee}from"./vendor-i18n-xZjp_O9P.js";const te={class:"space-y-6"},ae={class:"text-center"},se={class:"text-2xl font-bold text-gray-900 dark:text-white"},oe={class:"mt-2 text-sm text-gray-500 dark:text-dark-400"},re={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 E=q(),S=F(),{t}=ee(),C=J(),u=Q(),d=n(!0),o=n(""),T=n(!1),g=n(""),_=n(""),I=n(""),h=n(!1),p=n(""),D=n("/dashboard");function L(){const e=typeof window<"u"?window.location.hash:"",r=e.startsWith("#")?e.slice(1):e;return new URLSearchParams(r)}function R(e){return!e||!e.startsWith("/")||e.startsWith("//")||e.includes("://")||e.includes(`
`)||e.includes("\r")?"/dashboard":e}async function A(){var e,r;if(p.value="",!!_.value.trim()){h.value=!0;try{const a=await X(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=((r=(e=l.response)==null?void 0:e.data)==null?void 0:r.message)||l.message||t("auth.linuxdo.completeRegistrationFailed")}finally{h.value=!1}}}return W(async()=>{var N,P;const e=L(),r=e.get("access_token")||"",a=e.get("refresh_token")||"",l=e.get("expires_in")||"",B=R(e.get("redirect")||E.query.redirect||"/dashboard"),k=e.get("error"),M=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=R(e.get("redirect")),!g.value){o.value=t("auth.linuxdo.invalidPendingToken"),u.showError(o.value),d.value=!1;return}T.value=!0,d.value=!1;return}o.value=M||k,u.showError(o.value),d.value=!1;return}if(!r){o.value=t("auth.linuxdo.callbackMissingToken"),u.showError(o.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(r),u.showSuccess(t("auth.loginSuccess")),await S.replace(B)}catch(m){const V=m;o.value=((P=(N=V.response)==null?void 0:N.data)==null?void 0:P.detail)||V.message||t("auth.loginFailed"),u.showError(o.value),d.value=!1}}),(e,r)=>{const a=G("router-link");return x(),K(i(Z),null,{default:v(()=>[s("div",te,[s("div",ae,[s("h2",se,c(i(t)("auth.linuxdo.callbackTitle")),1),s("p",oe,c(d.value?i(t)("auth.linuxdo.callbackProcessing"):i(t)("auth.linuxdo.callbackHint")),1)]),f(y,{name:"fade"},{default:v(()=>[T.value?(x(),b("div",re,[s("p",ne,c(i(t)("auth.linuxdo.invitationRequired")),1),s("div",null,[O(s("input",{"onUpdate:modelValue":r[0]||(r[0]=l=>_.value=l),type:"text",class:"input w-full",placeholder:i(t)("auth.invitationCodePlaceholder"),disabled:h.value,onKeyup:j(A,["enter"])},null,40,ie),[[z,_.value]])]),f(y,{name:"fade"},{default:v(()=>[p.value?(x(),b("p",le,c(p.value),1)):w("",!0)]),_:1}),s("button",{class:"btn btn-primary w-full",disabled:h.value||!_.value.trim(),onClick:A},c(h.value?i(t)("auth.linuxdo.completing"):i(t)("auth.linuxdo.completeRegistration")),9,ce)])):w("",!0)]),_:1}),f(y,{name:"fade"},{default:v(()=>[o.value?(x(),b("div",ue,[s("div",de,[s("div",_e,[f($,{name:"exclamationCircle",size:"md",class:"text-red-500"})]),s("div",he,[s("p",ve,c(o.value),1),f(a,{to:"/login",class:"btn btn-primary"},{default:v(()=>[H(c(i(t)("auth.linuxdo.backToLogin")),1)]),_:1})])])])):w("",!0)]),_:1})])]),_:1})}}}),Se=Y(fe,[["__scopeId","data-v-1256bdd7"]]);export{Se as default};
