const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./bootstrapIm-BS8HLnlI.js","./index-6Jqoo2rk.js","./index-DvVyieJS.css","./iconTsx-Cr8T7ZIv.js","./transition-DuxZkCEv.js","./bootstrapIm-BNOFSc0R.css"])))=>i.map(i=>d[i]);
import{c as d,x as i,o as A,y as w,b as m,n as C,J as O,cu as r,t as x,L as D,bw as N,F as B,_ as b}from"./index-6Jqoo2rk.js";import{B as E}from"./bootstrapIm-BS8HLnlI.js";import{G as S}from"./animations-O3syBkMX.js";import{I as R,g as K}from"./getInputPasskeyResponse-RiY9Fe0r.js";import{t as k}from"./toast-B3QB1-N7.js";const T=x('<svg xmlns=http://www.w3.org/2000/svg class=preloader-circular viewBox="25 25 50 50"><circle class=preloader-path cx=50 cy=50 r=20 fill=none stroke-miterlimit=10>'),I="Login.ContinueOnLanguage";let M,L=!1;function F(){return M||(M=i.managers.apiManager.getConfig().then(async a=>{if(a.suggested_lang_code===r.getLastRequestedLangCode())return;const[s]=await Promise.all([r.getStrings(a.suggested_lang_code,[I]),r.getCacheLangPackAndApply()]);return{config:a,strings:s}}))}function J(a){const s=[];a.forEach(e=>{const o=r.strings.get(e.key);o&&(s.push(o),r.strings.set(e.key,e))});const c=r.format(I,!0);return s.forEach(e=>r.strings.set(e.key,e)),c}function W(){const[a,s]=d(!1),[c,e]=d(!1),[o,y]=d("");let g;const u=()=>s(!1);i.addEventListener("language_apply",u,{once:!0}),A(()=>i.removeEventListener("language_apply",u)),w(async()=>{if(L)return;const t=await F();if(!t)return;g=t.config.suggested_lang_code;const n=J(t.strings);await D({text:[n]}),y(n),s(!0)});const f=()=>{L=!0,e(!0),r.getLangPackAndApply(g)};return m(S,{get when(){return a()},get children(){return m(E,{class:"btn-primary btn-secondary btn-primary-transparent primary",get disabled(){return c()},onClick:f,get children(){return[C(()=>o()),m(O,{get when(){return c()},get children(){return T()}})]}})}})}let _;function Y(a={}){if(!R)return null;const[s,c]=d(!1),[e,o]=d(!1);let y,g;const u=t=>(t&&(_=void 0),_||(_=Promise.all([i.managers.apiManager.getBaseDcId(),i.managers.appAccountManager.initPasskeyLogin()])),_.then(([n,l])=>{g=n||void 0,y=l.options.data,c(!0)})),f=async()=>{o(!0);try{const t=await N.getUserIds(),n=await navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(JSON.parse(y).publicKey)}),l=K(n),[h,v]=l.response.user_handle.split(":").map(p=>parseInt(p)),P=t.indexOf(v);if(P!==-1){B(P+1);return}await i.managers.apiManager.setBaseDcId(h),await i.managers.appAccountManager.finishPasskeyLogin(l,g===h?void 0:g),b(()=>import("./bootstrapIm-BS8HLnlI.js").then(p=>p.b),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(p=>p.bootstrapIm())}catch(t){if(t.type==="SESSION_PASSWORD_NEEDED"){b(async()=>{const{navigateAuth:n}=await import("./bootstrapIm-BS8HLnlI.js").then(l=>l.a);return{navigateAuth:n}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(({navigateAuth:n})=>n({name:"password"}));return}else t.type==="PASSKEY_CREDENTIAL_NOT_FOUND"?k({langPackKey:"Login.Passkey.Error.NotFound"}):k({langPackKey:"Login.Passkey.Error"});await u(!0),o(!1)}};return w(()=>{u()}),m(S,{get when(){return s()},get children(){return m(E,{class:"btn-primary btn-secondary btn-primary-transparent primary",get disabled(){return e()||a.disabled},onClick:f,text:"Login.Passkey"})}})}export{W as L,Y as P};
//# sourceMappingURL=passkeyLoginButton-DtpAPUgF.js.map
