import{u as f,j as s,r as g,c as h,a as _,w as x,i as j,L as y,g as k,f as b,B as m,b as p,t as v}from"./index-731ec1e3.js";import{D as w}from"./DeviceImage-f74d9d0a.js";import{V as A,M as N}from"./vendor-links-6dfec9d6.js";import{T as O}from"./ReactTableCom-3dd97a7f.js";import"./index-b6b836d5.js";import"./persist-df5c7828.js";const T={"device-image":"_device-image_29lej_1"},C=({device:u,deviceState:r,...t})=>{const{t:o}=f("ota");let i;if(u!==void 0&&(i=u.power_source),i!=="Battery")return null;let n,l,c;if(r!==void 0&&((r==null?void 0:r.battery)!==void 0&&(n=r.battery),(r==null?void 0:r.battery_state)!==void 0&&(l=r.battery_state),(r==null?void 0:r.battery_low)!==void 0&&(c=r.battery_low)),n!==void 0&&n<=50||l!==void 0&&l==="low"||c!==void 0&&c===!0)return s.jsx(g.Fragment,{children:s.jsx("i",{title:o("ota:battery_low_upd"),className:"fa fa-triangle-exclamation text-warning ms-2"})})},D=C,H=u=>{const{t:r}=f("ota"),{device:t,state:o,checkOTA:i,scheduleOTA:n,unscheduleOTA:l,updateOTA:c}=u,d=(o==null?void 0:o.update)??{};switch(d.state){case"updating":return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"progress",children:s.jsxs("div",{className:"progress-bar progress-bar-striped progress-bar-animated",style:{width:`${d.progress}%`},children:[d.progress,"%"]})}),s.jsx("div",{children:r("remaining_time",{remaining:v(d.remaining)})})]});case"available":return s.jsxs("div",{className:"btn-group btn-group-sm",role:"group",children:[s.jsx(m,{className:"btn btn-danger btn-sm me-1",onClick:c,item:t.friendly_name,prompt:!0,children:r("update")}),s.jsx(m,{className:"btn btn-sm btn-info",onClick:n,item:t.friendly_name,title:r("schedule"),prompt:!0,children:s.jsx("i",{className:p("fa","fa-clock")})}),s.jsx(D,{device:t,deviceState:o})]});case"scheduled":return s.jsxs("div",{className:"btn-group btn-group-sm",role:"group",children:[s.jsx(m,{className:"btn btn-primary btn-sm me-1",onClick:i,item:t.friendly_name,children:r("check")}),s.jsx(m,{className:p("btn","btn-sm","btn-danger"),onClick:l,item:t.friendly_name,title:r("scheduled"),prompt:!0,children:s.jsx("i",{className:p("fa","fa-clock")})})]});default:return s.jsxs("div",{className:"btn-group btn-group-sm",role:"group",children:[s.jsx(m,{className:"btn btn-primary btn-sm me-1",onClick:i,item:t.friendly_name,children:r("check")}),s.jsx(m,{className:p("btn","btn-sm","btn-info"),onClick:n,item:t.friendly_name,title:r("schedule"),prompt:!0,children:s.jsx("i",{className:p("fa","fa-clock")})})]})}};class z extends g.Component{constructor(){super(...arguments),this.checkAllOTA=()=>{const{checkOTA:r}=this.props;this.getAllOtaDevices().forEach(({device:o})=>r(o.friendly_name))}}getAllOtaDevices(){const{devices:r,deviceStates:t,bridgeInfo:{config:o}}=this.props;return Object.values(r).filter(i=>{var n;return((n=i==null?void 0:i.definition)==null?void 0:n.supports_ota)&&!j(i,o)}).map(i=>{const n=t[i.friendly_name]??{};return{id:i.friendly_name,device:i,state:n}})}render(){const{checkOTA:r,scheduleOTA:t,unscheduleOTA:o,updateOTA:i,t:n}=this.props,l={checkOTA:r,scheduleOTA:t,unscheduleOTA:o,updateOTA:i},c=this.getAllOtaDevices(),d=[{Header:n("zigbee:pic"),Cell:({row:{original:{device:e,state:a}}})=>s.jsx(w,{className:T["device-image"],device:e,deviceStatus:a,disabled:!1}),disableSortBy:!0},{Header:n("zigbee:friendly_name"),accessor:({device:e})=>e.friendly_name,Cell:({row:{original:{device:e}}})=>s.jsx(y,{to:k(e.ieee_address),children:e.friendly_name})},{Header:n("zigbee:manufacturer"),accessor:({device:e})=>{var a;return[e.manufacturer,(a=e.definition)==null?void 0:a.vendor].join(" ")},Cell:({row:{original:{device:e}}})=>s.jsx(A,{device:e})},{Header:n("zigbee:model"),accessor:({device:e})=>{var a;return[e.model_id,(a=e.definition)==null?void 0:a.model].join(" ")},Cell:({row:{original:{device:e}}})=>s.jsx(N,{device:e})},{Header:n("zigbee:firmware_installed_version"),accessor:({state:e})=>{const a=((e==null?void 0:e.update)??{}).installed_version;return typeof a=="number"&&a?b(a):n("zigbee:firmware_installed_version_na")}},{Header:n("zigbee:firmware_available_version"),accessor:({state:e})=>{const a=((e==null?void 0:e.update)??{}).latest_version;return typeof a=="number"&&a?b(a):"N/A"}},{Header:()=>s.jsx(m,{className:"btn btn-danger btn-sm",onClick:this.checkAllOTA,prompt:!0,children:n("check_all")}),accessor:({state:e})=>((e==null?void 0:e.update)??{}).state+"",id:"check_all",Cell:({row:{original:{device:e,state:a}}})=>s.jsx(H,{device:e,state:a,...l})}];return s.jsx("div",{className:"card",children:s.jsx("div",{className:"table-responsive",children:s.jsx(O,{id:"otaDevices",columns:d,data:c,initialState:{sortBy:[{id:"check_all",desc:!1}]}})})})}}const L=["devices","deviceStates","bridgeInfo"],F=h(L,_)(x(["ota","zigbee","common"])(z));export{F as ConnectedOtaPage};
