const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./qr-code-styling-Cv6uVwgT.js","./_commonjsHelpers-DsqdWQfm.js"])))=>i.map(i=>d[i]);
import{i as C,v as k,k as L,a as E,x as g,y as H,o as q,b as s,n as Q,w as N,t as D,_ as O,bw as U,af as b,E as V}from"./index-6Jqoo2rk.js";import{u as z,s as u,B as K}from"./bootstrapIm-BS8HLnlI.js";import{L as F,P as W}from"./passkeyLoginButton-DtpAPUgF.js";import{p as X}from"./putPreloader-WBjcuDFX.js";import{M as f}from"./mediaHeader-B5k-4_FU.js";import{b as Z}from"./bytesCmp-DgkPox5J.js";import{b as j}from"./bytesToBase64-DpAjjkph.js";import{f as G}from"./base64ToBytes-B7rMxzcy.js";import{p as J}from"./paintQrCode-u2FNs0A8.js";import{A as Y}from"./AuthCard-Cghujz7c.js";import"./iconTsx-Cr8T7ZIv.js";import"./transition-DuxZkCEv.js";import"./animations-O3syBkMX.js";import"./getInputPasskeyResponse-RiY9Fe0r.js";import"./toast-B3QB1-N7.js";const ee=D("<ol>"),te=D("<li><span>"),A=3,I=240;function ye(re){const{managers:c,navigate:S,toIm:P}=z();let p,m,n=!1,h,_;const M=["Login.QR.Help1","Login.QR.Help2","Login.QR.Help3"],x=(()=>{const t=ee();return C(t,()=>M.map((r,i)=>(()=>{const e=te(),a=e.firstChild;return C(a,i+1),C(e,()=>k(r),null),L(o=>{const d=u.qrDescriptionItem,l=u.qrDescriptionMarker;return d!==o._v$&&E(e,o._v$=d),l!==o._v$2&&E(a,o._v$2=l),o},{_v$:void 0,_v$2:void 0}),e})())),L(()=>E(t,u.qrDescription)),t})(),w=()=>{n=!0};g.addEventListener("user_auth",w,{once:!0});async function T(t){if(!_)return;const r=j(t),i="tg://login?token="+G(r,!0),e=window.getComputedStyle(document.documentElement),a=e.getPropertyValue("--light-filled-primary-color").trim(),o=e.getPropertyValue("--primary-text-color").trim(),d=e.getPropertyValue("--primary-color").trim(),{canvas:l}=await J({data:i,size:I,host:p,background:a,foreground:o,logoColor:d,canvasClass:u.qrCanvas,QRCodeStylingCtor:_});m?(m.style.animation="hide-icon .4s forwards",l.style.display="none",l.style.animation="grow-icon .4s forwards",setTimeout(()=>{l.style.display=""},150),setTimeout(()=>{l.style.animation=""},500),m=void 0):Array.from(p.children).slice(0,-1).forEach($=>$.remove()),h=t}const R=()=>{n||!h||T(h)};g.addEventListener("theme_changed",R);const y={ignoreErrors:!0};let v;async function B(t,r){try{const i=await U.getUserIds();let e=await c.apiManager.invokeApi("auth.exportLoginToken",{api_id:b.id,api_hash:b.hash,except_ids:i.map(a=>a.toUserId())},{ignoreErrors:!0});if(e._==="auth.loginTokenMigrateTo"&&(y.dcId||(y.dcId=e.dc_id,c.apiManager.setBaseDcId(e.dc_id)),e=await c.apiManager.invokeApi("auth.importLoginToken",{token:e.token},y)),e._==="auth.loginTokenSuccess"){const a=e.authorization;return await c.apiManager.setUser(a.user),P(),!0}if((!v||!Z(v,e.token))&&(v=e.token,_=t,await T(e.token)),r){const a=Date.now()/1e3,o=e.expires-a-await c.timeManager.getServerTimeOffset();await V(o>A?1e3*A:1e3*o|0)}}catch(i){switch(i.type){case"SESSION_PASSWORD_NEEDED":S({name:"password"}),n=!0;break;case"AUTH_TOKEN_EXPIRED":return console.warn("SignQRCard: AUTH_TOKEN_EXPIRED"),!1;default:console.error("SignQRCard: default error:",i),n=!0;break}return!0}return!1}return H(async()=>{c.appStateManager.pushToState("authState",{_:"authStateSignQr"}),m=X(p,!0);const[{default:t}]=await Promise.all([O(()=>import("./qr-code-styling-Cv6uVwgT.js").then(r=>r.q),__vite__mapDeps([0,1]),import.meta.url)]);if(!n)for(;!n&&!(await B(t,!0)||n););}),q(()=>{n=!0,g.removeEventListener("user_auth",w),g.removeEventListener("theme_changed",R)}),s(Y,{get class(){return u.pageSignQR},inputWrapper:!1,get header(){return s(f,{get children(){return[s(f.Sticker,{ref(t){const r=p;typeof r=="function"?r(t):p=t},get class(){return u.qrContainer},size:I}),s(f.Title,{get children(){return k("Login.QR.Title")}}),s(f.Subtitle,{class:"secondary",get children(){return k("Login.QR.Subtitle")}})]}})},get children(){return[x,s(K,{class:"btn-primary btn-secondary btn-primary-transparent primary",onClick:()=>{n=!0,S({name:"signIn"})},text:"Login.QR.Cancel"}),Q(()=>Q(()=>N()===1)()&&s(F,{})),s(W,{})]}})}export{ye as default};
//# sourceMappingURL=SignQRCard-DbHlRBGd.js.map
