import{c as _,v as c,dm as V,dp as W,n as x,af as E,cZ as H,y as O,o as U,b as r,i as g,w as P,k as z,cK as Q,W as j,t as v,A as K,b7 as Z,cu as q,bw as G}from"./index-6Jqoo2rk.js";import{u as J,B as M,s as C}from"./bootstrapIm-BS8HLnlI.js";import{C as X,T as Y}from"./telInputField-Fj4gE689.js";import{L as D,P as R}from"./passkeyLoginButton-DtpAPUgF.js";import{M as m}from"./mediaHeader-B5k-4_FU.js";import{f as tt}from"./focusWhenConnected-14rkj1jb.js";import{A as et}from"./AuthCard-Cghujz7c.js";import"./iconTsx-Cr8T7ZIv.js";import"./transition-DuxZkCEv.js";import"./animations-O3syBkMX.js";import"./getInputPasskeyResponse-RiY9Fe0r.js";import"./base64ToBytes-B7rMxzcy.js";import"./toast-B3QB1-N7.js";const nt=v('<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>'),at=v("<div class=input-wrapper>"),rt=v('<svg xmlns=http://www.w3.org/2000/svg viewBox="0 0 160 160"><use href=#logo>');function bt(ot){const{managers:i,navigate:b,toIm:N}=J();let o=!1;const[d,w]=_(!1),[S,T]=_(!1),[B,h]=_(c("Login.Next"));let f,k;const l=new X({onCountryChange:(t,e)=>{f=t,k=e,e&&(a.value=a.lastValue="+"+e.country_code,setTimeout(()=>{u.focus(),V(u,!0)},0))}}),a=new Y({onInput:t=>{W.loadLottieWorkers();const{country:e,code:n}=t||{},s=e?e.name||e.default_name:"";s!==l.value&&(!f||!e||!n||f!==e&&k.country_code!==n.country_code)&&l.override(e,n,s),T(!!(e||a.value.length-1>1))}}),u=a.input;u.addEventListener("keypress",t=>{if(S()&&!d()&&t.key==="Enter")return I()});function I(t){t&&j(t),w(!0),h([x(()=>c("PleaseWait")),nt()]);const e=a.value;i.apiManager.invokeApi("auth.sendCode",{phone_number:e,api_id:E.id,api_hash:E.hash,settings:{_:"codeSettings",pFlags:{}}}).then(async n=>{if(n._==="auth.sentCodeSuccess"){const{authorization:s}=n;if(s._==="auth.authorization"){await i.apiManager.setUser(s.user),N();return}}b({name:"authCode",payload:Object.assign(n,{phone_number:e})})}).catch(n=>{w(!1),n.type==="PHONE_NUMBER_INVALID"?(a.setError(),H(a.label,c("Login.PhoneLabelInvalid")),u.classList.add("error"),h(c("Login.Next"))):(console.error("auth.sendCode error:",n),h(n.type))})}function F(){i.apiManager.invokeApi("help.getNearestDc").then(t=>{if(o)return t;const e=Z.getFromCache("langPack");e&&!e.countries?.hash&&q.getLangPackAndApply(e.lang_code).then(()=>{o||a.simulateInputEvent()});const n=new Set([1,2,3,4,5]),s=[t.this_dc];let A;return t.nearest_dc!==t.this_dc&&(A=i.apiManager.getNetworkerVoid(t.nearest_dc).then(()=>{s.push(t.nearest_dc)})),(A||Promise.resolve()).then(()=>{if(o)return;s.forEach(p=>n.delete(p));const $=[...n],y=async()=>{if(o)return;const p=$.shift();if(!p)return;if((await G.get(P()))[`dc${p}_auth_key`])return y();setTimeout(()=>{o||i.apiManager.getNetworkerVoid(p).finally(y)},3e3)};y()}),t}).then(t=>{o||!l.value.length&&!a.value.length&&l.selectCountryByIso2(t.country)})}let L;return O(()=>{i.appStateManager.pushToState("authState",{_:"authStateSignIn"}),K||(L=tt(u,()=>!o)),F()}),U(()=>{o=!0,L?.()}),r(et,{get class(){return C.pageSignIn},get header(){return r(m,{get children(){return[r(m.Sticker,{get class(){return C.logoContainer},size:120,get element(){return(()=>{const t=rt();return z(()=>Q(t,"class",C.logo)),t})()}}),r(m.Title,{get children(){return c("Login.Title")}}),r(m.Subtitle,{class:"secondary",get children(){return c("Login.StartText")}})]}})},inputWrapper:!1,get children(){return[(()=>{const t=at();return g(t,()=>l.container,null),g(t,()=>a.container,null),g(t,r(M,{class:"btn-primary btn-color-primary",get disabled(){return!S()||d()},onClick:I,get children(){return B()}}),null),g(t,(()=>{const e=x(()=>P()===1);return()=>e()&&r(D,{})})(),null),t})(),r(M,{class:"btn-primary btn-secondary btn-primary-transparent primary",get disabled(){return d()},onClick:()=>b({name:"signQR"}),text:"Login.QR.Login"}),r(R,{get disabled(){return d()}})]}})}export{bt as default};
//# sourceMappingURL=SignInCard-ujsrWVXw.js.map
