import{_ as C,O as E,r as i,c as h,a4 as b,o as F,b as c,d as u,f as N,e as t,t as m,g as $,h as z,v as K,L as V,m as D,H as x,a5 as I,a6 as U,G,J as H,K as J}from"./_plugin-vue_export-helper-nhjnO_bd.js";const L={class:"app-shell"},O={key:0,class:"global-status",style:{display:"block"}},j={class:"view-root"},Y={class:"surface surface--tight",style:{"max-width":"560px",margin:"0 auto",width:"100%"}},q={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=E({show:!1,message:"",type:"info"}),d=i(!0),n=i(!1),l=i(""),T=i(null),g=i(null),f=i(""),y=i("");let p=null;const P=h(()=>g.value?.token_type||"your enrollment"),R=h(()=>d.value?"Preparing your secure enrollment…":v.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.");h(()=>b());const v=h(()=>!!(l.value&&g.value));function r(e,s="info",a=3e3){o.show=!0,o.message=e,o.type=s,p&&clearTimeout(p),a>0&&(p=setTimeout(()=>{o.show=!1},a))}async function S(){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 B(){if(l.value)try{g.value=await x("/auth/api/token-info",{method:"GET",headers:{Authorization:`Bearer ${l.value}`}}),f.value=g.value.display_name}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.":U(e);y.value=s}}async function _(){if(!v.value||n.value)return;n.value=!0,r("Starting passkey registration…","info");let e;try{const s=f.value.trim()||null;e=await G.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 A(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 A(e){if(!e?.session_token)throw new Error("Registration response missing session_token");return await x("/auth/api/set-session",{method:"POST",headers:{Authorization:`Bearer ${e.session_token}`}})}function k(){const e=b.value||"/auth/";window.location.pathname!==e&&history.replaceState(null,"",e),window.location.reload()}function M(){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 F(async()=>{if(l.value=M(),await S(),!l.value){const e="Reset link is missing or malformed.";y.value=e,r(e,"error",0),d.value=!1;return}await B(),d.value=!1}),(e,s)=>(u(),c("div",L,[o.show?(u(),c("div",O,[t("div",{class:$(["status",o.type])},m(o.message),3)])):N("",!0),t("main",j,[t("div",Y,[t("header",q,[s[1]||(s[1]=t("h1",null,"🔑 Registration",-1)),t("p",Q,m(R.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)])])):v.value?(u(),c("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: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=C(ne,[["__scopeId","data-v-7ca316fc"]]);H(oe).mount("#app");J();
