(()=>{var Z=Object.defineProperty;var N=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var M=(s,e,t)=>e in s?Z(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,v=(s,e)=>{for(var t in e||(e={}))ee.call(e,t)&&M(s,t,e[t]);if(N)for(var t of N(e))te.call(e,t)&&M(s,t,e[t]);return s};var q=(s,e,t)=>new Promise((i,n)=>{var r=o=>{try{c(t.next(o))}catch(d){n(d)}},a=o=>{try{c(t.throw(o))}catch(d){n(d)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(r,a);c((t=t.apply(s,e)).next())});var m,S,x;function se(){m.dataset.navState="displayed",m.classList.remove("state-off"),m.classList.add("state-on"),S.classList.add("a-show")}function I(){m.dataset.navState="hidden",m.classList.remove("state-on"),m.classList.add("state-off"),S.classList.add("a-hide"),S.classList.remove("a-show"),setTimeout(()=>{S.classList.remove("a-hide")},300)}function C(){console.log("HUD init"),m=document.querySelector(".hud .nav-toggle"),S=document.querySelector(".hud .navigation"),x=document.querySelector(".hud .reload-screen"),m.addEventListener("click",s=>{s.currentTarget.dataset.navState!="displayed"?se():I()}),x.addEventListener("click",s=>{Screens.reload()})}var y=class{constructor(e,t,i){this.screens={},this.routesMap={},this.currentScreen=null,this.eventsHandlers={switch:[],reload:[],reinit:[]},this.screensContainer=document.querySelector(e),this.loader=document.querySelector(t),this.errorScreen=document.querySelector(i),console.log("Screens Init")}add(e,t){if(typeof t!="object")return console.error("Screens: screens must be object");if(typeof(t==null?void 0:t.alias)=="undefined")return console.error("Screens: undefined alias");if(typeof(t==null?void 0:t.renderer)!="function")return console.error("Screens: renderer must be function");this.screens[t.alias]=v({route:e},t),this.routesMap[e]=t.alias}switch(e){var i;if(this.runSwitchHandlers(e),this.hideErrorScreen(),this.showLoader(),(i=this.currentScreen)==null||i.DOMObject.remove(),typeof this.screens[e]=="undefined"){console.error(`Screens: "${e}" not found`);return}this.currentScreen=this.screens[e];let t=document.createElement("div");t.classList.add("screen"),t.id=e,t.dataset.alias=e,t.innerHTML=this.currentScreen.renderer(),this.currentScreen.DOMObject=t,this.screensContainer.append(this.currentScreen.DOMObject),this.currentScreen.initer(this)}reload(){this.currentScreen&&(this.runReloadHandlers(this.currentScreen.alias),this.switch(this.currentScreen.alias))}reinit(){this.currentScreen&&(this.currentScreen.initer(this),this.runReinitHandlers())}routing(){setInterval(()=>{let e=document.location.hash.split("#!")[1];if(typeof e=="undefined"||e=="")return;let t=typeof this.routesMap[e]=="undefined"?"not-found-screen":this.routesMap[e];(!this.currentScreen||this.currentScreen.alias!=t)&&this.switch(t)},50)}ready(){this.currentScreen!=null&&(this.currentScreen.DOMObject||(this.currentScreen.DOMObject=document.getElementsById(this.currentScreen.alias)),this.hideLoader(),this.currentScreen.DOMObject.classList.add("a-show"))}error(e,t){var i;(i=this.currentScreen)==null||i.DOMObject.remove(),this.errorScreen.querySelector(".error-title").innerHTML=e,this.errorScreen.querySelector(".error-text").innerHTML=t,this.showErrorScreen()}hideLoader(){this.loader.classList.remove("a-show")}showLoader(){this.loader.classList.add("a-show")}showErrorScreen(){this.errorScreen.classList.add("a-show")}hideErrorScreen(){this.errorScreen.classList.remove("a-show")}getScreens(){return this.screens}getRoutesMap(){return this.routesMap}onSwitch(e){this.eventsHandlers.switch.push(e)}onReaload(e){this.eventsHandlers.reload.push(e)}onReinit(e){this.eventsHandlers.reinit.push(e)}runSwitchHandlers(e){for(let t of this.eventsHandlers.switch)t(this,e)}runReloadHandlers(e){for(let t of this.eventsHandlers.reload)t(this,e)}runReinitHandlers(){for(let e of this.eventsHandlers.reinit)e(this)}};function ie(s,e,t,i){return`
<div class="toast toast-${s}" role="alert">
<div class="toast-content">
<h4 class="toast-title">${e} ${t}</h4>
<p class="toast-text">${i}</p>
</div>
<button class="btn-icon toast-close" type="button" aria-label="Close">\u2715</button>
</div>
`}function ne(s,e){if(e!=null&&e.alone&&document.querySelectorAll(".toast").forEach(t=>t.close()),s.close=function(){this.classList.add("a-hide"),setTimeout(()=>{this.remove()},300)},s.querySelector(".toast-close").addEventListener("click",t=>{s.close()}),s.show=function(){document.querySelector("body").append(s),setTimeout(()=>{s.classList.add("a-show")},10)},Screens.onSwitch((t,i)=>{setTimeout(()=>{s==null||s.close()},1e4)}),s.addEventListener("mouseover",t=>s.ishovered=!0),s.addEventListener("mouseout",t=>s.ishovered=!1),e!=null&&e.lifetime){console.log(e);let t=setInterval(()=>{s.ishovered||(s.close(),clearInterval(t))},e==null?void 0:e.lifetime)}return s}function _(s,e,t,i,n){let r=document.createElement("div");return r.innerHTML=ie(s,e,t,i),ne(r.childNodes[1],n)}function re(s,e,t){return typeof t=="undefined"&&(t={}),typeof t.lifetime=="undefined"&&(t.lifetime=4e3),typeof t.alone=="undefined"&&(t.alone=!0),_("success",'<i class="ph ph-check-circle"></i>',s,e,t)}function ae(s,e,t){return _("info",'<i class="ph ph-info"></i>',s,e,t)}function oe(s,e,t){return _("warning",'<i class="ph ph-warning"></i>',s,e,t)}function j(s,e,t){return _("danger",'<i class="ph ph-warning-octagon"></i>',s,e,t)}var U={create:_,createInfo:ae,createSuccess:re,createWarning:oe,createError:j,createDanger:j};function ce(s){let e="";for(let t of s){let i="",n="";t.route&&(i=`<a class="list-action" href="${t.route}">`,n="</a>"),e+=`
<li class="list-item ${t.is_active?"list-item-active":""}">
${i}${t.content}${n}
</li>
`}return`
<div class="sidebar block">
<ul class="list list-nav">
${e}
</ul>
</div>
`}function le(s,e,t,i){let n='<tr class="table-row">',r=0;for(let o in e)n+=`<th scope="col">${e[o]}</th>`,r++;n+="</tr>";let a="";for(let o of t){a+='<tr class="table-row">';for(let d in e)a+=`<td>${o[d]}</td>`;a+="</tr>"}let c="";return typeof i!="undefined"&&(c=`
<tfoot class="table-foot">
<tr class="table-row">
<td colspan="${r}">
${i}
</td>
</tr>
</tfoot>
`),`
<table class="table devices-lists">
<caption class="table-caption">${s}</caption>
<thead class="table-head">${n}</thead>
<tbody class="table-body">${a}</tbody>
${c}
</table>
`}function P(s,e,t){let i=document.createElement(s);for(let[n,r]of Object.entries(e))n==="class"?i.className=r:n==="dataset"?Object.assign(i.dataset,r):i.setAttribute(n,r);return i.innerHTML=typeof t!="undefined"?t:"",i}function de(s,e){return["primary","success","secondary","info","warning","error","danger"].indexOf(s)<0?console.error("createAlert()","Error of type: "+s):P("div",{class:`alert alert-${s}`},e)}function ue(s){let e={device_name:"name",device_hard_id:"device_id",device_ip:"ip",device_type:"type",ip_address:"ip",mac_address:"mac",device_mac:"mac",core_version:"firmware_core_version"},t={};for(let i in s){if(typeof e[i]!="undefined"){t[e[i]]=s[i];continue}t[i]=s[i]}return t}function pe(s,e){if((s==null?void 0:s.isLoading)==e)return!1;if(e)s.isLoading=!0,s.originalContent=s.innerHTML,s.classList.contains("with-icon")?s.originalWithIcon=!0:s.classList.add("with-icon"),s.classList.add("loading-state"),s.setAttribute("disabled","disabled"),s.innerHTML='<i class="ph-bold ph-spinner"></i> Loading';else{if(s.isLoading=!1,!s.originalContent)return!1;s.removeAttribute("disabled"),s.classList.remove("loading-state"),s.originalWithIcon||s.classList.remove("with-icon"),s.innerHTML=s.originalContent}return s}var F={template:{sidebarNav:ce,table:le,createElement:P,createAlert:de},unification:{deviceFieldsUnification:ue},states:{btnLoadingState:pe}};var w=class{constructor(e){this.core=e}actions_list(e){return this.core.api_get("/api/v1/scripts/actions/list",e)}scopes_list(e){return this.core.api_get("/api/v1/scripts/scopes/list",e)}regular_list(e){return this.core.api_get("/api/v1/scripts/regular/list",e)}scope_get_by_filename(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${i}`,t,{})}scope_create(e,t){return this.core.api_post("/api/v1/scripts/scopes/new",e,t)}scope_update(e,t){return this.core.api_post("/api/v1/scripts/scopes/update",e,t)}action_enable(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/alias/${i}/enable`,t)}action_disable(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/alias/${i}/disable`,t)}regular_enable(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/regular/alias/${i}/enable`,t)}regular_disable(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/regular/alias/${i}/disable`,t)}scope_enable(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${i}/enable`,t)}scope_disable(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${i}/disable`,t)}scope_remove(e,t){let i=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${i}/remove`,t)}run(e,t){return this.core.api_post("/api/v1/scripts/actions/run",e,t)}};var $=class{constructor(e){this.core=e}list(e){return this.core.api_get("/api/v1/devices/list",e)}scanning_setup(e){return this.core.api_get("/api/v1/devices/scanning/setup",e)}scanning_all(e){return this.core.api_get("/api/v1/devices/scanning/all",e)}setup_new_device(e,t){return this.core.api_post("/api/v1/devices/setup/new-device",e,t)}info(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${i}/info`,t)}get(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${i}`,t)}status(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${i}/status`,t)}action(e,t){return this.core.api_post("/api/v1/devices/action",e,t)}remove(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${i}/remove`,t)}reboot(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${i}/reboot`,t)}};var L=class{constructor(e){this.core=e}list(e){return this.core.api_get("/api/v1/areas/list",e)}inner_list(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${i}/list`,t)}new_area(e,t){return this.core.api_post("/api/v1/areas/new-area",e,t)}remove(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${i}/remove`,t)}place_in_area(e,t){return this.core.api_post("/api/v1/areas/place-in-area",e,t)}update_display_name(e,t){return this.core.api_post("/api/v1/areas/update-display-name",e,t)}update_alias(e,t){return this.core.api_post("/api/v1/areas/update-alias",e,t)}devices(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${i}/devices`,t)}unassign_from_area(e,t){let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${i}/unassign-from-area`,t)}types_list(e){return this.core.api_get("/api/v1/areas/types/list",e)}reboot_devices(e,t){if(e==null)return this.core.api_get("/api/v1/areas/reboot_devices",t);let i=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${i}/reboot_devices`,t)}};function J(s){if(!s||typeof s!="object")return"";let e=new URLSearchParams;Object.entries(s).forEach(([i,n])=>{n!=null&&e.append(i,String(n))});let t=e.toString();return t?`?${t}`:""}function fe(s,e){let t=String(s||"").replace(/\/+$/,""),i=String(e||"").replace(/^\/+/,"");return`${t}/${i}`}function he(s){try{return{ok:!0,data:JSON.parse(s)}}catch(e){return{ok:!1,error:e}}}var T=class{constructor(e){this.base_url=(e==null?void 0:e.base_url)||"",this.token=(e==null?void 0:e.token)||"",this.timeout_ms=Number.isFinite(e==null?void 0:e.timeout_ms)?e.timeout_ms:15e3,this.default_headers=(e==null?void 0:e.default_headers)||{},this.on_unauthorized=typeof(e==null?void 0:e.on_unauthorized)=="function"?e.on_unauthorized:null,this.proxy_path=(e==null?void 0:e.proxy_path)||"",this.scripts=new w(this),this.devices=new $(this),this.areas=new L(this)}set_base_url(e){this.base_url=e||""}set_token(e){this.token=e||""}set_proxy_path(e){this.proxy_path=e||""}_wrap_path(e,t){if(!this.proxy_path)return t?`${e}${J(t)}`:e;let i=v({path:e},t||{});return`${this.proxy_path}${J(i)}`}request(e,t,i,n,r){let a=typeof n=="function"?n:()=>{},c=fe(this.base_url,t),o=new AbortController,d=Number.isFinite(r==null?void 0:r.timeout_ms)?r.timeout_ms:this.timeout_ms,u=setTimeout(()=>o.abort(),d),b=v(v({},this.default_headers),(r==null?void 0:r.headers)||{});this.token&&(b.Authorization=`Bearer ${this.token}`);let O;i!=null&&(b["Content-Type"]="application/json",O=JSON.stringify(i)),fetch(c,{method:e,headers:b,body:O,signal:o.signal}).then(l=>q(this,null,function*(){clearTimeout(u);let f={url:c,method:e,status_code:l.status,headers:l.headers},p=yield l.text(),R=he(p),h=R.ok?R.data:p;if(!l.ok){let g={type:"http_error",message:`HTTP ${l.status}`,status_code:l.status,raw:h};if((l.status===401||l.status===403)&&this.on_unauthorized)try{this.on_unauthorized({error:g,meta:f})}catch(k){}return a(g,null,f)}if(R.ok&&h&&typeof h=="object"){let g=h.status;if(g===!1||g==="error"){let k={type:"api_error",message:h.message||"API error",status_code:l.status,raw:h,field:h.field};return a(k,null,f)}}return a(null,h,f)})).catch(l=>{clearTimeout(u);let p=l&&(l.name==="AbortError"||String(l).includes("AbortError"))?{type:"timeout",message:`Timeout after ${d}ms`}:{type:"network_error",message:(l==null?void 0:l.message)||"Network error",details:l};return a(p,null,{url:c,method:e,status_code:0,headers:null})})}get(e,t,i){return this.request("GET",e,null,t,i)}post(e,t,i,n){return this.request("POST",e,t,i,n)}api_get(e,t,i,n){return this.get(this._wrap_path(e,i),t,n)}api_post(e,t,i,n,r){return this.post(this._wrap_path(e,n),t,i,r)}};function E(s){return Helper.template.sidebarNav([{content:'<span class="list-label"><i class="ph ph-cpu"></i> Devices</span>',route:"/#!/devices",is_active:s=="devices"},{content:'<span class="list-label"><i class="ph ph-magnifying-glass"></i> Scanning</span>',route:"/#!/devices/scanning",is_active:s=="scanning"},{content:'<span class="list-label"><i class="ph ph-play"></i> Actions</span>',route:"/#!/devices/actions",is_active:s=="actions"}])}function H(s,e,t){Helper.states.btnLoadingState(e,!0);let i=e.dataset.deviceId,n=e.dataset.deviceName,r=e.dataset.deviceAlias;s.devices.reboot(i,(a,c,o)=>{Helper.states.btnLoadingState(e,!1),console.log("Reboot done",a,c,o),t==null||t.close(),c?(setTimeout(()=>Screens.reinit(),8e3),Toasts.createSuccess("Reboot successful",`Device: ${n}<br>
Alias: <b>${r}</b>`).show()):Toasts.createError("Reboot failed",`Device: ${n}<br>
Alias: <b>${r}</b>`).show()})}function B(s,e){return console.log(s),Modals.create("device-popup",{title:`Device ${s.name}`,body:t=>{let i="";for(let n in s)i+=`
<tr class="table-row">
<th>${n}: </th>
<td>${s[n]}</td>
</tr>
`;return`
<div class="block">
<table class="table" style="border: 0">
<tbody class="table-body">
${i}
</tbody>
</table>
</div>
`},actions:t=>{let i=Helper.template.createElement("button",{class:"btn btn-primary"},"Close"),n=Helper.template.createElement("button",{class:"btn btn-warning with-icon"},'<i class="ph ph-arrow-clockwise"></i> Reboot'),r=Helper.template.createElement("button",{class:"btn btn-danger with-icon"},'<i class="ph ph-trash"></i> Remove');return i.addEventListener("click",a=>{t.close()}),n.dataset.deviceId=s.id,n.dataset.deviceName=s.name,n.dataset.deviceAlias=s.alias,n.addEventListener("click",a=>{n.getAttribute("disabled")||H(e,a.currentTarget,t)}),r.addEventListener("click",a=>{r.getAttribute("disabled")||(Helper.states.btnLoadingState(r,!0),confirmPopup("Are you sure you want to remove this device?",()=>{e.devices.remove(s.id,(c,o,d)=>{Helper.states.btnLoadingState(r,!1),console.log("Was removed"),t.close(),Screens.reinit(),setTimeout(()=>{Toasts.createSuccess("Removed",`
Device: ${s.name}<br>
Alias: <b>${s.alias}</b><br>
IP: <b>${s.ip}</b>
`).show()},300)})},()=>{Helper.states.btnLoadingState(r,!1),console.log("CANCELED")}))}),[i,n,r]}})}function me(s){let e=[];for(let t of s.devices){t=Helper.unification.deviceFieldsUnification(t);let i=t.connection_state=="active"?'<span class="badge badge-success">Online</span>':'<span class="badge badge-warning">Offline</span>';e.push({deviceName:t.name,alias:t.alias,status:i,ip:`<code class="code">${t.ip}</code>`,actions:`
<button
class="btn btn-secondary btn-small details-btn"
data-device='${JSON.stringify(t)}'
type="button"
>Details</button>
<button
class="btn btn-warning btn-small reboot-btn"
data-device-id="${t.id}"
data-device-name="${t.name}"
data-device-alias="${t.alias}"
type="button"
>Reboot</button>
`})}return e}function ve(s,e,t){s.currentScreen.DOMObject.querySelector(".devices-container").innerHTML=Helper.template.table("Devices list",{deviceName:"Device name",alias:"Device alias",status:"Status",ip:"IP",actions:"Actions"},e,`<span class="table-meta">Total: <span class="total">${t}</span> devices</span>`)}function be(s,e){s.currentScreen.DOMObject.querySelectorAll(".reboot-btn").forEach(t=>{t.addEventListener("click",i=>{i.currentTarget.getAttribute("disabled")||H(e,i.currentTarget)})}),s.currentScreen.DOMObject.querySelectorAll(".details-btn").forEach(t=>{t.addEventListener("click",i=>{let n=JSON.parse(i.currentTarget.dataset.device);B(n,e).show()})})}function z(s){return{alias:"devices",renderer:()=>`
<div class="container">
<div class="row g-6">
<div class="col sidebar-container">
${E("devices")}
</div>
<div class="col devices-container"></div>
</div>
</div>
`,initer:e=>{s.devices.list((t,i,n)=>{if(console.log("sh_api.devices.list",t,i,n),n.status_code!=200)return e.error("Server API ERROR","");ve(e,me(i.data),i.data.total),be(e,s),e.ready()})}}}function W(s,e){return s=Helper.unification.deviceFieldsUnification(s),Modals.create("device-setup",{title:`Setup new device ${s.ip}`,body:t=>{let i="";for(let r in s)r[0]!="_"&&(i+=`
<tr class="table-row">
<th>${r}: </th>
<td>${s[r]}</td>
</tr>
`);return`
<div class="row g-6">
<div class="col device-info">
${`
<div class="block">
<table class="table" style="border: 0">
<tbody class="table-body">
${i}
</tbody>
</table>
</div>
`}
</div>
<div class="col setup-form w-100">
<div class="block form-group">
<label class="label">
Device alias
<i class="ph ph-asterisk"></i>
<input type="text" name="alias" class="input" placeholder="Input alias">
</label>
</div>
<div class="block form-group">
<label class="label">
Device name
<i class="ph ph-asterisk"></i>
<input type="text" name="name" class="input" placeholder="Input name">
</label>
</div>
<div class="block form-group">
<label class="label">
About device
<i class="ph ph-note-pencil"></i>
<textarea class="input" name="description" placeholder="Input description"></textarea>
</label>
</div>
<div class="alert-container"></div>
</div>
</div>
`},actions:t=>{let i=Helper.template.createElement("button",{class:"btn btn-primary"},"Cancel");i.addEventListener("click",r=>{t.close()});let n=Helper.template.createElement("button",{class:"btn btn-success with-icon"},'<i class="ph ph-gear"></i> Setup');return n.addEventListener("click",r=>{if(r.currentTarget.getAttribute("disabled"))return!1;let a={device_ip:s.ip},c=document.querySelector("#device-setup .setup-form");if(c.querySelectorAll("input[type='text']").forEach(u=>{u.dispatchEvent(new Event("input",{bubbles:!0}))}),c.querySelectorAll(".label.error").length)return!1;let o=c.querySelectorAll("input"),d=c.querySelector("textarea");for(let u of o)a[u.getAttribute("name")]=u.value;a[d.getAttribute("name")]=d.value,Helper.states.btnLoadingState(n,!0),e.devices.setup_new_device(a,(u,b,O)=>{var l,f;if(Helper.states.btnLoadingState(n,!1),(u==null?void 0:u.type)=="api_error"){if(console.error("ERR! sh_api.devices.setup_new_device",u.raw),(l=u.raw)!=null&&l.failed_fields)for(let p of u.raw.failed_fields)t.querySelector(`[name="${p}"]`).parentNode.classList.add("error");if((f=u.raw)!=null&&f.msg){let p=t.querySelector(".setup-form .alert-container");p.innerHTML="",p==null||p.append(Helper.template.createAlert("error",u.raw.msg))}return!1}if(!b)return!1;o.forEach(p=>p.value=""),d.value="",t.close(),Screens.reinit(),setTimeout(()=>{Toasts.createSuccess("Setup successful",`Added new device <b>ID ${s.device_id}</b>`).show()},300)})}),[i,n]},onready:t=>{t.querySelector(".setup-form").querySelectorAll("input").forEach(n=>{n.addEventListener("input",r=>{var a;r.currentTarget.value.length?(r.currentTarget.parentNode.classList.remove("error"),(a=r.currentTarget.parentNode.parentNode.querySelector(".input-info.error"))==null||a.remove()):(r.currentTarget.parentNode.classList.add("error"),r.currentTarget.parentNode.parentNode.querySelector(".input-info.error")||r.currentTarget.parentNode.parentNode.append(Helper.template.createElement("div",{class:"input-info error"},'<i class="ph ph-warning-circle"></i> Field cannot be empty')))})})}})}function ge(s){let e=[];for(let t of s.devices)t=Helper.unification.deviceFieldsUnification(t),e.push({deviceId:t.device_id,deviceName:t.name,deviceType:t.type,status:`<span class="badge badge-primary">${t.status}</span>`,ip:`<code class="code">${t.ip}</code>`,mac:`<code class="code">${t.mac}</code>`,wifiSignal:t.wifi_signal,actions:t.status=="setup"?`
<button
class="btn btn-secondary btn-small setup-btn"
data-device='${JSON.stringify(t)}'
type="button"
>Setup</button>
`:""});return e}function Se(s,e,t){s.currentScreen.DOMObject.querySelector(".devices-container").innerHTML=Helper.template.table("Found devices",{deviceId:"Device ID",deviceName:"Device name",deviceType:"Type",status:"Status",ip:"IP",mac:"Mac",wifiSignal:"Signal",actions:"Actions"},e,`<span class="table-meta">Total: <span class="total">${t}</span> devices</span>`)}function _e(s,e){s.currentScreen.DOMObject.querySelectorAll(".setup-btn").forEach(t=>{t.addEventListener("click",i=>{let n=JSON.parse(i.currentTarget.dataset.device);W(n,e).show()})})}function Y(s){return{alias:"devices-scanning",renderer:()=>`
<div class="container">
<div class="row g-6">
<div class="col sidebar-container">
${E("scanning")}
</div>
<div class="col devices-container"></div>
</div>
</div>
`,initer:e=>{s.devices.scanning_all((t,i,n)=>{if(console.log("sh_api.devices.scanning_all",t,i),n.status_code!=200)return e.error("Server API ERROR","");Se(e,ge(i.data),i.data.devices.length),_e(e,s),e.ready()})}}}var D={list:z,scanning:Y};function G(s){return Helper.template.sidebarNav([{content:'<span class="list-label"><i class="ph ph-cpu"></i> Scopes</span>',route:"/#!/scripts/scopes",is_active:s=="scopes"},{content:'<span class="list-label"><i class="ph ph-play"></i> Actions</span>',route:"/#!/scripts/actions",is_active:s=="actions"},{content:'<span class="list-label"><i class="ph ph-magnifying-glass"></i> Regular</span>',route:"/#!/scripts/regular",is_active:s=="regular"}])}function ye(s){let e=[];for(let t of s.scopes){let i=t.state=="enabled"?'<span class="badge badge-success">Enabled</span>':'<span class="badge badge-primary">Disabled</span>',n=t.state=="disabled"?`<button
class="btn btn-success btn-small change-state-btn"
data-scope='${JSON.stringify(t)}'
type="button"
data-value="enable"
>Enable</button>`:`<button
class="btn btn-warning btn-small change-state-btn"
data-scope='${JSON.stringify(t)}'
type="button"
data-value="disable"
>Disable</button>`;e.push({name:t.name,filename:`${t.filename}<br><code><small>${t.path}</small></code>`,state:i,actions:`
${n}
`})}return e}function we(s,e,t){console.log("renderingScopesTable",e),s.currentScreen.DOMObject.querySelector(".scopes-container").innerHTML=Helper.template.table("Scopes list",{name:"Scope name",filename:"Filename",state:"Status",actions:"Actions"},e,`<span class="table-meta">Total: <span class="total">${t}</span> scopes</span>`)}function $e(s,e){s.currentScreen.DOMObject.querySelectorAll(".change-state-btn").forEach(t=>{t.addEventListener("click",i=>{let n=i.currentTarget;if(n.getAttribute("disabled"))return;let r=n.dataset.value=="enable"?"scope_enable":"scope_disable",a=JSON.parse(n.dataset.scope);Helper.states.btnLoadingState(n,!0),e.scripts[r](a.name,(c,o,d)=>{Helper.states.btnLoadingState(n,!1),o?(setTimeout(()=>Screens.reinit(),250),a.state,Toasts.createSuccess("Request Success",`State of <b>${a.name}</b> was changed`).show()):Toasts.createError("Request failed","Scope state not changed").show()})})})}function K(s){return{title:"Scripts Scopes",alias:"scripts-scopes",renderer:()=>`
<div class="container">
<div class="row g-6">
<div class="col sidebar-container">
${G("scopes")}
</div>
<div class="col scopes-container w-100"></div>
</div>
</div>
`,initer:e=>{s.scripts.scopes_list((t,i,n)=>{if(console.log("sh_api.scripts.scopes_list",t,i,n),n.status_code!=200)return e.error("Server API ERROR","");we(e,ye(i.data),i.data.total),$e(e,s),e.ready()})}}}var Q={scopes:K};function V(s,e){s.add("/",{alias:"home",renderer:()=>'<h2 class="mt-4">Hello world</h2>',initer:t=>{setTimeout(()=>t.ready(),1e3),setTimeout(()=>t.error("Error","Just testing"),2e3)}}),s.add("-",{alias:"not-found-screen",renderer:()=>'<h2 class="mt-4">404 NOT FOUND</h2>',initer:t=>{t.ready()}}),s.add("/devices",D.list(e)),s.add("/devices/scanning",D.scanning(e)),s.add("/scripts/scopes",Q.scopes(e))}function Le(s,e,t){return`
<div class="modal" aria-hidden="true" id="${s}">
<div class="modal-backdrop"></div>
<div class="modal-panel" role="dialog" aria-modal="true" aria-labelledby="modal-title-basic">
<header class="modal-header">
<h4 class="modal-title" id="modal-title-basic">${e}</h4>
<button class="btn-icon modal-close" type="button" aria-label="Close">\u2715</button>
</header>
<div class="modal-body"></div>
<footer class="modal-footer">${t}</footer>
</div>
</div>
`}function Te(s,e){return s.show=function(){document.querySelector("body").append(s),setTimeout(()=>{this.classList.add("a-show")},10)},s.close=function(){this.classList.add("a-hide"),setTimeout(()=>{this.remove()},300)},s.querySelector(".modal-close").addEventListener("click",t=>{s.close()}),typeof e=="function"&&e(s),s}function Ee(s,e){let t=e.title||"",i=e.footer||"",n=document.createElement("div");n.innerHTML=Le(s,t,i);let r=n.childNodes[1],a=r.querySelector(".modal-body"),c=r.querySelector(".modal-footer");if(typeof e.actions=="function"){let o=e.actions(r);if(typeof o[0]=="object"){let d=document.createElement("div");d.classList.add("actions");for(let u of o)d.append(u);c.append(d)}}if(typeof e.body=="function"){let o=e.body(r);typeof o=="object"?a.append(o):typeof o=="string"&&(a.innerHTML=o)}return Te(r,e==null?void 0:e.onready)}var X={create:Ee};function A(s,e,t){Modals.create("confirm-popup",{title:"Requires confirmation",body:i=>`
<p>${s}</p>
`,actions:i=>{let n=Helper.template.createElement("button",{class:"btn btn-primary"},"NO"),r=Helper.template.createElement("button",{class:"btn btn-warning"},"YES");return n.addEventListener("click",a=>{i.close(),t()}),r.addEventListener("click",a=>{i.close(),e()}),[n,r]}}).show()}document.addEventListener("DOMContentLoaded",s=>{console.log("App init"),window.Toasts=U,window.Helper=F,window.Modals=X,window.confirmPopup=A,C();let e=new T({base_url:"http://shswebclient.local",token:"YOUR_TOKEN",timeout_ms:3e3,on_unauthorized:({error:i})=>console.log("auth problem:",i),proxy_path:"/proxy.php"}),t=new y(".screens",".load-screen",".error-screen");V(t,e),console.log(t.getScreens()),t.onSwitch((i,n)=>{I()}),t.routing(),window.Screens=t});})();
//# sourceMappingURL=main.js.map