import{a as D}from"./chunk-IKDRCVQ7.js";import{d as E}from"./chunk-2IW5LNPB.js";import{b as B}from"./chunk-YM6242MC.js";import{h as O,k as R}from"./chunk-P3JWYVN7.js";import{a as k,b as I}from"./chunk-QIWZD5HO.js";import{Ac as o,Bc as l,Kb as _,Pb as u,Ub as r,Vb as n,Wb as v,Zc as T,_b as $,bc as S,cc as f,gb as e,ma as m,mc as a,nc as p,oc as x,tb as w,ua as C,va as y,wc as b,xc as g,zb as h}from"./chunk-6JZDPQRU.js";var U=(t,c)=>({"fas fa-fw fa-spinner fa-spin":t,"far fa-fw fa-check-circle":c}),F=t=>({"grey-text":t}),P=(t,c)=>({"far fa-fw fa-circle":t,"fas fa-fw fa-spinner fa-spin":c});function j(t,c){t&1&&(r(0,"p",7),a(1),o(2,"translate"),n()),t&2&&(e(),p(l(2,1,"restart.please_wait_while_server_restarts")))}function M(t,c){if(t&1&&(r(0,"div",8),a(1),n()),t&2){let i=f();e(),p(i.error)}}function V(t,c){if(t&1&&(r(0,"div",9)(1,"div",11)(2,"span"),v(3,"i",12),a(4),o(5,"translate"),n()(),r(6,"div",11)(7,"span",12),v(8,"i",12),a(9),o(10,"translate"),n()()()),t&2){let i=f();e(3),_("ngClass",g(9,U,!i.uiOnline,i.uiOnline)),e(),x(" ",l(5,5,"restart.ui_online")," "),e(3),_("ngClass",b(12,F,!i.uiOnline)),e(),_("ngClass",g(14,P,!i.uiOnline,i.uiOnline)),e(),x(" ",l(10,7,"restart.service_ready")," ")}}function z(t,c){if(t&1){let i=$();r(0,"p",15)(1,"button",16),S("click",function(){C(i);let d=f(2);return y(d.viewLogs())}),a(2),o(3,"translate"),n()()}t&2&&(e(2),p(l(3,1,"menu.tooltip_view_logs")))}function A(t,c){if(t&1&&(r(0,"div",10)(1,"p"),a(2),o(3,"translate"),n(),r(4,"p",13),a(5),o(6,"translate"),r(7,"span",14),a(8),n()(),h(9,z,4,3,"p",15),n()),t&2){let i=f();e(2),p(l(3,4,"restart.server_is_taking_long_time_to_restart")),e(3),x(" ",l(6,6,"restart.label_restart_command_executed"),": "),e(3),p(i.resp.command||"End Process"),e(),u(i.uiOnline?9:-1)}}var Y=(()=>{class t{$api=m(R);$router=m(E);$settings=m(B);$toastr=m(O);$translate=m(k);$ws=m(D);checkTimeout;checkDelay;resp={};timeout=!1;error=!1;uiOnline=!1;io;constructor(){}ngOnInit(){this.io=this.$ws.connectToNamespace("status"),this.io.connected.subscribe(()=>{this.io.socket.emit("monitor-server-status"),this.$settings.getAppSettings().catch(()=>{})}),this.$router.parseUrl(this.$router.url).queryParams.restarting?(this.uiOnline=!0,this.checkIfServerUp()):this.$api.put("/server/restart",{}).subscribe({next:s=>{this.resp=s,this.checkIfServerUp(),s.restartingUI||(this.uiOnline=!0)},error:s=>{console.error(s),this.error=this.$translate.instant("restart.toast_server_restart_error"),this.$toastr.error(this.$translate.instant("restart.toast_server_restart_error"),this.$translate.instant("toast.title_error"))}})}checkIfServerUp(){this.checkDelay=setTimeout(()=>{this.io.socket.on("homebridge-status",i=>{this.uiOnline=!0,(i.status==="up"||i.status==="pending")&&(this.$toastr.success(this.$translate.instant("restart.toast_server_restarted"),this.$translate.instant("toast.title_success")),this.$router.navigate(["/"]))})},7e3),this.checkTimeout=setTimeout(()=>{this.$toastr.warning(this.$translate.instant("restart.toast_server_restart_timeout"),this.$translate.instant("toast.title_warning"),{timeOut:1e4}),this.timeout=!0},4e4)}viewLogs(){this.$router.navigate(["/logs"])}ngOnDestroy(){this.io.end(),clearTimeout(this.checkDelay),clearTimeout(this.checkTimeout)}static \u0275fac=function(s){return new(s||t)};static \u0275cmp=w({type:t,selectors:[["ng-component"]],decls:15,vars:10,consts:[[1,"d-flex","justify-content-between"],[1,"primary-text","m-0"],[1,"my-4","align-items-center",2,"max-width","1000px","margin","auto"],[1,"w-100","text-center","primary-text","mb-5"],[1,"fas","fa-fw","fa-power-off",2,"font-size","75px"],[1,"text-center"],[1,"primary-text","mb-4"],[1,"grey-text"],[1,"alert","alert-error","my-4"],[1,"justify-content-center","my-4"],[1,"alert","alert-warning","my-4"],[1,"restart-progress-box","primary-text"],[3,"ngClass"],[1,"grey-text","mb-0"],[1,"font-monospace"],[1,"mt-2","mb-0"],[1,"btn","btn-primary","mb-0",3,"click"]],template:function(s,d){s&1&&(r(0,"div",0)(1,"h3",1),a(2),o(3,"translate"),n()(),r(4,"div",2)(5,"div",3),v(6,"i",4),n(),r(7,"div",5)(8,"h4",6),a(9),o(10,"translate"),n(),h(11,j,3,3,"p",7)(12,M,2,1,"div",8)(13,V,11,17,"div",9)(14,A,10,8,"div",10),n()()),s&2&&(e(2),p(l(3,6,"menu.restart.title")),e(7),p(l(10,8,"restart.title_restart")),e(2),u(d.error?-1:11),e(),u(d.error?12:-1),e(),u(d.error?-1:13),e(),u(d.timeout?14:-1))},dependencies:[T,I],styles:[".restart-progress-box[_ngcontent-%COMP%]{font-size:22px;font-weight:300;margin-top:15px}"]})}return t})();export{Y as a};
