import{a as H}from"./chunk-MLQR3MDZ.js";import"./chunk-VYHY3B4N.js";import{a as D,c as O,f as F}from"./chunk-XLWMYK7F.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 b,Pa as d,Qa as c,Ra as f,Rb as E,X as n,Zb as y,_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-RBLFZ2PJ.js";import"./chunk-IPY3USQV.js";import"./chunk-NJFOIAJX.js";import"./chunk-SCFRQ6PW.js";import"./chunk-6P64VPBS.js";import"./chunk-2VLWLWMI.js";import"./chunk-J5EEBZ33.js";import"./chunk-4WFVMWDK.js";import"./chunk-K7C27B2F.js";import"./chunk-DVVH2KKN.js";import"./chunk-NV3QH4JK.js";import"./chunk-LRFGNCHE.js";import"./chunk-PVMEIX5M.js";import"./chunk-42C7ZIID.js";import{k as g}from"./chunk-24IZEI4V.js";var G=class v{constructor(){this.api=s(O);this.navCtrl=s(b);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,E,P,V,y,A,w,R,N,M,W,C,_,T,L],encapsulation:2})}};export{G as TokenConfigPage};
