import{a as H}from"./chunk-HMGKNWXC.js";import"./chunk-OA3FUBIK.js";import{a as D,c as O,f as F}from"./chunk-MT5VNIHV.js";import{$ as U,$a as h,Ac as L,B as s,Cc as W,Eb as _,Fb as T,Hb as C,Ia as p,Ja as l,Jb as b,Na as c,Oa as v,Pa as f,Pb as E,U as n,Xb as y,Yb as w,_b as M,ab as m,ac as A,dc as P,h as u,kc as x,lc as R,mc as N,na as a,oa as r,qc as B,tc as V,ya as I,zb as k}from"./chunk-DRW4ORQZ.js";import"./chunk-BJ5K5KE7.js";import"./chunk-3ZOJ5B5W.js";import"./chunk-3ITX5V5R.js";import"./chunk-KOWO2Z3R.js";import"./chunk-ZYIC63LD.js";import"./chunk-F2T7ZI6U.js";import"./chunk-4WFVMWDK.js";import"./chunk-M2X7KQLB.js";import"./chunk-DVVH2KKN.js";import"./chunk-NV3QH4JK.js";import"./chunk-LRFGNCHE.js";import"./chunk-OZYWYLNK.js";import"./chunk-42C7ZIID.js";import{k as d}from"./chunk-24IZEI4V.js";var g=class g{constructor(){this.api=s(O);this.navCtrl=s(b);this.loading=s(B);this.initAppService=s(H);this.settings=s(F);this.route=s(k)}ngOnInit(){return d(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 d(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(()=>d(this,null,function*(){yield this.settings.setValue(this.settings.API_SERVER_URL,this.apiServerUrl),yield this.initAppService.initapp(),i.dismiss()})).catch(t=>d(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}};g.\u0275fac=function(i){return new(i||g)},g.\u0275cmp=U({type:g,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 v(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 v(t.authToken,o)||(t.authToken=o),o}),r()()(),a(16,"ion-footer")(17,"ion-button",3),I("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),c("ngModel",t.apiServerUrl),n(3),l(m(14,11,"AUTH_TOKEN")),n(2),c("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});var G=g;export{G as TokenConfigPage};
