import{Q as $}from"./QSpace-CjYFwNTd.js";import{v as O,L as z,s as A,u as L,o as h,M as V,a as U,ac as E,j as g,e as l,f as s,h as n,w as i,O as k,l as m,K as F,g as u,t as c,a9 as w,z as b,G as y,F as R,k as j,b as C,H as S,ci as P,Q as v,A as G}from"./index-OSKNspXo.js";import{u as H,t as K}from"./aideplusStore-CSNU4tlD.js";const J={class:"full-height q-pa-md"},X={class:"row items-center"},Y={class:"q-gutter-md row"},Z={class:"row items-center no-wrap"},ee={class:"col"},te={class:"text-h6 q-mb-xs"},ae={class:"text-caption"},se={key:0,class:"text-caption q-mt-xs"},ne={__name:"aideplusDashboardComponent",setup(re){const D=z(),r=H(),{devices:f}=A(r),{resetDevices:x,disconnectWebSocket:I}=r,{t:p}=L({messages:K});h(()=>{D.dispatch("global/screenTitle",{title:p("completion.plus.ui.dashboard.title"),name:"Aide-Plus Dashboard"}),r.connectWebSocket()}),V(()=>{r.disconnectWebSocket()});function T(t){if(!t||!r.isWsConnected){console.error("Cannot restart device: invalid device name or WebSocket disconnected");return}try{const e=`server/${t}/restart`,a={command:"restart",timestamp:new Date().toISOString(),source:"MedianWeb"};console.log(`Sending MQTT restart command to ${e}`,a),r.publishToMqtt(e,a)}catch(e){console.error("Error sending restart command:",e)}}function Q(t,e,a){let o="grey";if(!t)return o;const d=new Date(e);switch(M(d)){case 0:o="positive";break;case 1:o="warning";break;case 2:o="negative";break;default:o="grey";break}return o}function q(t){const e=String(t).toLowerCase();return e==="medianweb"?"computer":e==="aideplus-proto"?"devices":e.match(/^aideplus-\d+$/)||e.startsWith("aide-plus")?"precision_manufacturing":"device_unknown"}function W(t){if(!t||t.status==="unknown")return"battery_unknown";if(t.power_source==="ac")return"battery_charging_full";if(t.percentage===null)return"battery_unknown";const e=parseInt(t.percentage);return e>=90?"battery_full":e>=60?"battery_6_bar":e>=40?"battery_4_bar":e>=20?"battery_2_bar":"battery_alert"}function B(t){let e="";return t.percentage!==null&&(e+=`${t.percentage}% `),t.power_source==="ac"?e+=p("(Charging)"):t.power_source!=="unknown"&&(e+=`(${t.power_source})`),e.trim()||p("Unknown")}const _=U(null);h(()=>{_.value=setInterval(()=>{const t=Object.keys(f.value);if(t.length>0)for(const e of t){const a=f.value[e];(a.status==="online"||a.status==="idle")&&(a.checked=Date.now())}},3e3)});const M=t=>{if(isNaN(t)||!t)return 2;const e=new Date(t),a=new Date;if(!(e.toDateString()===a.toDateString()))return 2;const d=e.getTime()<a.getTime()-5*60*1e3,N=e.getTime()<a.getTime()-1*60*1e3;return d?2:N?1:0};return E(()=>{_.value&&clearInterval(_.value),I(!0)}),(t,e)=>(l(),g("div",J,[s(y,{class:"my-card q-mb-md"},{default:i(()=>[s(k,{class:"col"},{default:i(()=>[e[1]||(e[1]=n("div",{class:"text-h6"},"AIDE PLUS Device Monitor",-1)),n("div",X,[n("div",null,[n("div",null,[e[0]||(e[0]=m(" Monitor Status: ")),n("span",{class:F(u(r).isWsConnected?"text-positive":"text-negative")},c(u(r).isWsConnected?"Connected":"Disconnected"),3)])]),s($)])]),_:1}),s(w,{class:"col-auto"},{default:i(()=>[s(b,{flat:"",color:"primary",icon:"refresh",label:"Reset List",onClick:u(x)},null,8,["onClick"])]),_:1})]),_:1}),n("div",Y,[(l(!0),g(R,null,j(u(f),(a,o)=>(l(),C(y,{key:o,class:"device-card",bordered:""},{default:i(()=>[s(k,{class:"bg-grey-2"},{default:i(()=>[n("div",Z,[n("div",ee,[n("div",te,c(a.data.device),1),s(P,{color:Q(a.status,a.data.payload.timestamp,a.checked),class:"q-mr-sm"},{default:i(()=>[m(c(a.data.status),1)]),_:2},1032,["color"]),n("span",ae,[s(v,{name:"access_time",size:"xs",class:"q-mr-xs"}),m(" "+c(a.lastSeen),1)]),a.data.payload&&a.data.payload.battery?(l(),g("div",se,[s(v,{name:W(a.data.payload.battery),size:"xs",class:"q-mr-xs"},null,8,["name"]),m(" "+c(B(a.data.payload.battery)),1)])):S("",!0)]),s(v,{name:q(a.data.device),size:"md",class:"q-ml-sm"},null,8,["name"])])]),_:2},1024),s(w,{align:"right"},{default:i(()=>[s(b,{flat:"",dense:"",color:"primary",icon:"visibility",label:t.$t("View Details")},null,8,["label"]),a.status==="online"?(l(),C(b,{key:0,flat:"",dense:"",color:"warning",icon:"restart_alt",label:t.$t("Restart"),onClick:d=>T(a.data.device),disable:!u(r).isWsConnected},null,8,["label","onClick","disable"])):S("",!0)]),_:2},1024),s(G,null,{default:i(()=>[n("pre",null,"                            "+c(a)+`
                        `,1)]),_:2},1024)]),_:2},1024))),128))])]))}},le=O(ne,[["__scopeId","data-v-0f2898b5"]]);export{le as default};
//# sourceMappingURL=aideplusDashboardComponent-B0wuyjbD.js.map
