(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=cockpit;var n=e.n(t);let r,s;function i(e,t){e.wait((()=>{e.valid&&t()}))}function o(e,t){const o={exists:null,state:null,enabled:null,wait:function(e){c.promise.then(e)},start:function(){return m("StartUnit",[e,"replace"])},stop:function(){return m("StopUnit",[e,"replace"])},restart:function(){return m("RestartUnit",[e,"replace"])},tryRestart:function(){return m("TryRestartUnit",[e,"replace"])},enable:function(){return b("EnableUnitFiles",[[e],!1,!1])},disable:function(){return b("DisableUnitFiles",[[e],!1])}};let a,d;n().event_target(o);const c=n().defer();function l(){o.exists="not-found"!=a.LoadState||"inactive"!=a.ActiveState,"activating"==a.ActiveState?o.state="starting":"deactivating"==a.ActiveState?o.state="stopping":"active"==a.ActiveState||"reloading"==a.ActiveState?o.state="running":"failed"==a.ActiveState?o.state="failed":"inactive"==a.ActiveState&&o.exists?o.state="stopped":o.state=void 0,"enabled"==a.UnitFileState||"linked"==a.UnitFileState?o.enabled=!0:"disabled"==a.UnitFileState||"masked"==a.UnitFileState?o.enabled=!1:o.enabled=void 0,o.unit=a,o.dispatchEvent("changed"),c.resolve()}function u(){o.details=d,o.service=d,o.dispatchEvent("changed")}var f;function p(){if(!a||!d)return Promise.resolve();function e(e,t){return r.call(e,"org.freedesktop.DBus.Properties","GetAll",[t]).then((e=>{let[n]=e;const s={};for(const e in n)s[e]=n[e].v;r.notify({[a.path]:{[t]:s}})})).catch((e=>console.log(e)))}return Promise.allSettled([e(a.path,"org.freedesktop.systemd1.Unit"),e(d.path,"org.freedesktop.systemd1."+t)])}function v(t,n,r,s,i){s==e&&p()}function g(e,t,n){return e.call("/org/freedesktop/systemd1","org.freedesktop.systemd1.Manager",t,n)}function m(e,t){return new Promise(((r,s)=>{const i=n().dbus("org.freedesktop.systemd1",{superuser:"try"});let o;const a=i.subscribe({interface:"org.freedesktop.systemd1.Manager",member:"JobRemoved"},((n,d,c,l)=>{let[u,f,v,g]=l;f==o&&(a.remove(),i.close(),p().then((()=>{"done"===g?r():s(new Error(`systemd job ${e} ${JSON.stringify(t)} failed with result ${g}`))})))}));g(i,e,t).then((e=>{let[t]=e;o=t})).catch((()=>{i.close(),s()}))}))}function b(e,t){const r=n().dbus("org.freedesktop.systemd1",{superuser:"try"});return g(r,e,t).then((()=>g(r,"Reload",[]))).then(p).finally(r.close)}return-1==e.indexOf(".")&&(e+=".service"),void 0===t&&(t="Service"),f=function(){s.LoadUnit(e).then((e=>{a=r.proxy("org.freedesktop.systemd1.Unit",e),a.addEventListener("changed",l),i(a,l),d=r.proxy("org.freedesktop.systemd1."+t,e),d.addEventListener("changed",u),i(d,u)})).catch((()=>{o.exists=!1,o.dispatchEvent("changed")}))},s||(r=n().dbus("org.freedesktop.systemd1"),s=r.proxy("org.freedesktop.systemd1.Manager","/org/freedesktop/systemd1"),i(s,(()=>{s.Subscribe().catch((e=>{"org.freedesktop.systemd1.AlreadySubscribed"!=e.name&&"org.freedesktop.DBus.Error.FileExists"!=e.name&&console.warn("Subscribing to systemd signals failed",e)}))}))),i(s,f),s.addEventListener("Reloading",((e,t)=>{t||p()})),s.addEventListener("JobNew",v),s.addEventListener("JobRemoved",v),o}document.addEventListener("DOMContentLoaded",(()=>{let e;function t(){function t(){function t(t){document.getElementById(t).textContent=JSON.stringify(e[t])}t("exists"),t("state"),t("enabled")}e=o(n().location.path[0]||""),e.addEventListener("changed",t),t(),document.body.removeAttribute("hidden")}function r(t){document.getElementById(t).addEventListener("click",(()=>{e[t]().catch((e=>console.error("action",t,"failed:",JSON.stringify(e))))}))}r("start"),r("stop"),r("enable"),r("disable"),n().addEventListener("locationchanged",t),t()}))})();