import{_ as C,o as M,b as u,c as d,e as t,t as f,f as z,k as F,m as N,v as $,aa as V,r as i,p as D,h as b,u as E,ay as I,az as K,al as L,q as p,aA as U,J as q,L as G,M as H}from"./_plugin-vue_export-helper-DC3K5mG-.js";const J={class:"app-shell"},O={key:0,class:"global-status show"},j={class:"view-root"},Q={class:"surface surface--tight reset-container"},W={class:"view-header center"},X={class:"view-lede"},Y={key:0,class:"section-block"},Z={key:1,class:"section-block"},ee={key:2,class:"section-block"},se={class:"section-body"},te={class:"name-edit"},ae=["disabled"],ne=["disabled"],oe={__name:"ResetApp",setup(re){const o=L({show:!1,message:"",type:"info"}),h=i(!0),n=i(!1),r=i(""),T=i(null),l=i(null),m=i(""),y=i("");let g=null;const x=p(()=>l.value?.token_type||"your enrollment"),P=p(()=>h.value?"Preparing your secure enrollment…":v.value?`Finish up ${x.value}. The name entered will be stored on your passkey and on our system.`:"This authentication link is no longer valid."),v=p(()=>!!(r.value&&l.value));function c(e,s="info",a=3e3){o.show=!0,o.message=e,o.type=s,g&&clearTimeout(g),a>0&&(g=setTimeout(()=>{o.show=!1},a))}async function R(){try{const e=await D();T.value=e,e?.rp_name&&(document.title=`${e.rp_name} · Passkey Setup`)}catch(e){console.warn("Unable to load settings",e)}}async function S(){if(r.value)try{l.value=await b("/auth/api/token-info",{method:"GET",headers:{Authorization:`Bearer ${r.value}`}}),m.value=l.value.display_name,l.value.theme&&E({user:{theme:l.value.theme}})}catch(e){console.error("Failed to load token info",e);const s=e instanceof I?e.data?.detail||"The authentication link is invalid or expired.":K(e);y.value=s}}async function _(){if(!v.value||n.value)return;n.value=!0,c("Starting passkey registration…","info");let e;try{const s=m.value.trim()||null;e=await q.register(r.value,s)}catch(s){n.value=!1;const a=s?.message||"Passkey registration cancelled",w=a==="Passkey registration cancelled";c(w?a:`Registration failed: ${a}`,w?"info":"error",4e3);return}try{await B(e)}catch(s){n.value=!1;const a=s?.message||"Failed to establish session";c(a,"error",4e3);return}c("Passkey registered successfully!","success",800),setTimeout(()=>{n.value=!1,k()},800)}async function B(e){if(!e?.exchange_code)throw new Error("Registration response missing exchange_code");return await b("/auth/api/set-session",{method:"POST",headers:{Authorization:`Bearer ${e.exchange_code}`}})}function k(){const e=U.value||"/auth/";window.location.pathname!==e&&history.replaceState(null,"",e),window.location.reload()}function A(){const e=window.location.pathname.split("/").filter(Boolean);if(!e.length)return"";const s=e[e.length-1],a=e.slice(0,-1);return a.length>1||a.length===1&&a[0]!=="auth"||!s.includes(".")?"":s}return M(async()=>{if(r.value=A(),await R(),!r.value){const e="Reset link is missing or malformed.";y.value=e,c(e,"error",0),h.value=!1;return}await S(),h.value=!1}),(e,s)=>(u(),d("div",J,[o.show?(u(),d("div",O,[t("div",{class:z(["status",o.type])},f(o.message),3)])):F("",!0),t("main",j,[t("div",Q,[t("header",W,[s[1]||(s[1]=t("h1",null,"🔑 Registration",-1)),t("p",X,f(P.value),1)]),h.value?(u(),d("section",Y,[...s[2]||(s[2]=[t("div",{class:"section-body center"},[t("p",null,"Loading reset details…")],-1)])])):v.value?(u(),d("section",ee,[t("div",se,[t("label",te,[s[3]||(s[3]=t("span",null,"👤 Name",-1)),N(t("input",{type:"text","onUpdate:modelValue":s[0]||(s[0]=a=>m.value=a),disabled:n.value,maxlength:"64",onKeyup:V(_,["enter"])},null,40,ae),[[$,m.value]])]),t("button",{class:"btn-primary",disabled:n.value,onClick:_},f(n.value?"Registering…":"Register Passkey"),9,ne)])])):(u(),d("section",Z,[t("div",{class:"section-body center"},[t("div",{class:"button-row button-row--center"},[t("button",{class:"btn-secondary",onClick:k},"Return to sign-in")])])]))])])]))}},ie=C(oe,[["__scopeId","data-v-0314b491"]]);G(ie).mount("#app");H();
