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