import{_ as A,o as M,r as i,c,b as u,j as N,e as t,Q as $,t as m,f as z,k as p,l as F,v as K,L as V,p as D,g as b,a6 as E,a7 as I,a8 as j,H,J as L,K as U}from"./_plugin-vue_export-helper-Dvd-Cb1u.js";const G={class:"app-shell"},J={key:0,class:"global-status",style:{display:"block"}},O={class:"view-root"},Q={class:"surface surface--tight",style:{"max-width":"560px",margin:"0 auto",width:"100%"}},Y={class:"view-header",style:{"text-align":"center"}},q={class:"view-lede"},W={key:0,class:"section-block"},X={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=$({show:!1,message:"",type:"info"}),d=i(!0),n=i(!1),l=i(""),x=i(null),v=i(null),f=i(""),y=i("");let g=null;const T=p(()=>v.value?.token_type||"your enrollment"),P=p(()=>d.value?"Preparing your secure enrollment…":h.value?`Finish up ${T.value}. You may edit the name below if needed, and it will be saved to your passkey.`:"This authentication link is no longer valid."),h=p(()=>!!(l.value&&v.value));function r(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();x.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 E?e.data?.detail||"The authentication link is invalid or expired.":I(e);y.value=s}}async function _(){if(!h.value||n.value)return;n.value=!0,r("Starting passkey registration…","info");let e;try{const s=f.value.trim()||null;e=await H.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=j.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 R(),!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)=>(u(),c("div",G,[o.show?(u(),c("div",J,[t("div",{class:z(["status",o.type])},m(o.message),3)])):N("",!0),t("main",O,[t("div",Q,[t("header",Y,[s[1]||(s[1]=t("h1",null,"🔑 Registration",-1)),t("p",q,m(P.value),1)]),d.value?(u(),c("section",W,[...s[2]||(s[2]=[t("div",{class:"section-body center"},[t("p",null,"Loading reset details…")],-1)])])):h.value?(u(),c("section",Z,[t("div",ee,[t("label",se,[s[3]||(s[3]=t("span",null,"👤 Name",-1)),F(t("input",{type:"text","onUpdate:modelValue":s[0]||(s[0]=a=>f.value=a),disabled:n.value,maxlength:"64",onKeyup:V(_,["enter"])},null,40,te),[[K,f.value]])]),t("button",{class:"btn-primary",disabled:n.value,onClick:_},m(n.value?"Registering…":"Register Passkey"),9,ae)])])):(u(),c("section",X,[t("div",{class:"section-body center"},[t("div",{class:"button-row center",style:{"justify-content":"center"}},[t("button",{class:"btn-secondary",onClick:k},"Return to sign-in")])])]))])])]))}},oe=A(ne,[["__scopeId","data-v-4830d223"]]);L(oe).mount("#app");U();
