import{a as H}from"./chunk-L6NJZVPU.js";import"./chunk-J36J6JDY.js";import{a as D,c as O,f as F}from"./chunk-MYV7LOMK.js";import{Aa as k,B as s,Bb as I,Cc as L,Ec as W,Gb as _,Hb as T,Jb as C,Ka as p,La as l,Lb as y,Pa as d,Qa as c,Ra as f,Rb as b,X as n,Zb as E,_b as w,ac as M,ba as U,bb as h,cb as m,cc as A,fc as P,h as u,mc as x,nc as R,oc as N,pa as a,qa as r,sc as B,vc as V}from"./chunk-IA4I4FFG.js";import"./chunk-TZKEAXTW.js";import"./chunk-2AGRZFDF.js";import"./chunk-RJD74PWK.js";import"./chunk-7Y4TN2QM.js";import"./chunk-JJB3Y43V.js";import"./chunk-YUNOCBLG.js";import"./chunk-VGMJM2GZ.js";import"./chunk-2NIBOUWM.js";import"./chunk-I547WOKC.js";import"./chunk-BJ43HUSB.js";import"./chunk-7NPRN4HX.js";import"./chunk-NMFL75IO.js";import{k as g}from"./chunk-24IZEI4V.js";var G=class v{constructor(){this.api=s(O);this.navCtrl=s(y);this.loading=s(B);this.initAppService=s(H);this.settings=s(F);this.route=s(I)}ngOnInit(){return g(this,null,function*(){this.apiServerUrl=this.settings.currentSettings[this.settings.API_SERVER_URL],this.authToken=this.settings.currentSettings[this.settings.DEVICE_CONFIG].token_config;let e=yield u(this.route.queryParams),i=e.url,t=e.token;i&&t&&(this.apiServerUrl=i,this.authToken=t,setTimeout(this.save,500))})}save(e=1){return g(this,null,function*(){let i;(i=yield this.loading.getTop())||(i=yield this.loading.create({message:"Cargando..."}),yield i.present()),D.serverBaseUrl=this.apiServerUrl,this.settings.loadAppDevice(this.authToken.trim()).then(()=>g(this,null,function*(){yield this.settings.setValue(this.settings.API_SERVER_URL,this.apiServerUrl),yield this.initAppService.initapp(),i.dismiss()})).catch(t=>g(this,null,function*(){if(e<6&&/Http failure response for/.test(t))e=this.changeUrl(e),this.save(e);else throw t}))})}changeUrl(e){switch(e){case 1:if(e++,/\/user\.html.+/.test(this.apiServerUrl)){this.apiServerUrl=this.apiServerUrl.replace(/\/user\.html.+/,"");break}e=this.changeUrl(e);break;case 2:if(e++,!/http/.test(this.apiServerUrl)){this.apiServerUrl="http://"+this.apiServerUrl;break}e=this.changeUrl(e);break;case 3:if(e++,!/https/.test(this.apiServerUrl)){this.apiServerUrl=this.apiServerUrl.replace("http","https");break}e=this.changeUrl(e);break;case 4:e++;break;case 5:e++,this.apiServerUrl=this.apiServerUrl.replace("https","http");break;case 6:e++,this.apiServerUrl=this.apiServerUrl.replace(/http:\/\/(.+)(?=\/)(.+)$/,"http://$1:81$2");break}return e}static{this.\u0275fac=function(i){return new(i||v)}}static{this.\u0275cmp=U({type:v,selectors:[["app-token-config"]],decls:24,vars:17,consts:[["color","primary"],["name","apiUrl","type","url",1,"ion-text-right",3,"ngModelChange","ngModel"],["type","text",1,"ion-text-right",3,"ngModelChange","ngModel"],["size","large","expand","full","color","medium",3,"click"],["color","medium"]],template:function(i,t){i&1&&(a(0,"ion-header")(1,"ion-toolbar",0)(2,"ion-title"),p(3),h(4,"translate"),r()()(),a(5,"ion-content")(6,"ion-item")(7,"ion-label"),p(8),h(9,"translate"),r(),a(10,"ion-input",1),f("ngModelChange",function(o){return c(t.apiServerUrl,o)||(t.apiServerUrl=o),o}),r()(),a(11,"ion-item")(12,"ion-label"),p(13),h(14,"translate"),r(),a(15,"ion-input",2),f("ngModelChange",function(o){return c(t.authToken,o)||(t.authToken=o),o}),r()()(),a(16,"ion-footer")(17,"ion-button",3),k("click",function(){return t.save()}),p(18),h(19,"translate"),r(),a(20,"ion-text",4)(21,"h6"),p(22),h(23,"translate"),r()()()),i&2&&(n(3),l(m(4,7,"DEVICE_CONFIG")),n(5),l(m(9,9,"API_SERVER_URL")),n(2),d("ngModel",t.apiServerUrl),n(3),l(m(14,11,"AUTH_TOKEN")),n(2),d("ngModel",t.authToken),n(3),l(m(19,13,"SAVE")),n(4),l(m(23,15,"WIZARD_ON_SAVE_INFO")))},dependencies:[x,b,P,V,E,A,w,R,N,M,W,C,_,T,L],encapsulation:2})}};export{G as TokenConfigPage};
