import{c as m,a as p,w as g,r as u,i as b,j as s,L as h,g as f,B as l,u as _,t as j}from"./index-42f456b7.js";import{D as x}from"./DeviceImage-718ed8c8.js";import{V as v,M as k,O}from"./vendor-links-d48b9c68.js";import{T as A}from"./ReactTableCom-7debd434.js";import"./index-4552832e.js";import"./persist-df9114c1.js";const w={"device-image":"_device-image_29lej_1"},y=d=>{const{t:r}=_("ota"),{device:o,state:a,checkOTA:i,updateOTA:n}=d,c=(a==null?void 0:a.update)??{};switch(c.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:`${c.progress}%`},children:[c.progress,"%"]})}),s.jsx("div",{children:r("remaining_time",{remaining:j(c.remaining)})})]});case"available":return s.jsx(l,{className:"btn btn-danger btn-sm",onClick:n,item:o.friendly_name,prompt:!0,children:r("update")});default:return s.jsx(l,{className:"btn btn-primary btn-sm",onClick:i,item:o.friendly_name,children:r("check")})}};class D extends u.Component{constructor(){super(...arguments),this.checkAllOTA=()=>{const{checkOTA:r}=this.props;this.getAllOtaDevices().forEach(({device:a})=>r(a.friendly_name))}}getAllOtaDevices(){const{devices:r,deviceStates:o,bridgeInfo:{config:a}}=this.props;return Object.values(r).filter(i=>{var n;return((n=i==null?void 0:i.definition)==null?void 0:n.supports_ota)&&!b(i,a)}).map(i=>{const n=o[i.friendly_name]??{};return{id:i.friendly_name,device:i,state:n}})}render(){const{checkOTA:r,updateOTA:o,t:a}=this.props,i={checkOTA:r,updateOTA:o},n=this.getAllOtaDevices(),c=[{Header:a("zigbee:pic"),Cell:({row:{original:{device:e,state:t}}})=>s.jsx(x,{className:w["device-image"],device:e,deviceStatus:t,disabled:!1}),disableSortBy:!0},{Header:a("zigbee:friendly_name"),accessor:({device:e})=>e.friendly_name,Cell:({row:{original:{device:e}}})=>s.jsx(h,{to:f(e.ieee_address),children:e.friendly_name})},{Header:a("zigbee:manufacturer"),accessor:({device:e})=>{var t;return[e.manufacturer,(t=e.definition)==null?void 0:t.vendor].join(" ")},Cell:({row:{original:{device:e}}})=>s.jsx(v,{device:e})},{Header:a("zigbee:model"),accessor:({device:e})=>{var t;return[e.model_id,(t=e.definition)==null?void 0:t.model].join(" ")},Cell:({row:{original:{device:e}}})=>s.jsx(k,{device:e})},{Header:a("zigbee:firmware_build_date"),accessor:({device:e})=>e.date_code},{Header:a("zigbee:firmware_version"),accessor:({device:e})=>e.software_build_id,Cell:({row:{original:{device:e}}})=>s.jsx(O,{device:e})},{Header:()=>s.jsx(l,{className:"btn btn-danger btn-sm",onClick:this.checkAllOTA,prompt:!0,children:a("check_all")}),accessor:({state:e})=>((e==null?void 0:e.update)??{}).state+"",id:"check_all",Cell:({row:{original:{device:e,state:t}}})=>s.jsx(y,{device:e,state:t,...i})}];return s.jsx("div",{className:"card",children:s.jsx("div",{className:"table-responsive",children:s.jsx(A,{id:"otaDevices",columns:c,data:n,initialState:{sortBy:[{id:"check_all",desc:!1}]}})})})}}const C=["devices","deviceStates","bridgeInfo"],B=m(C,p)(g(["ota","zigbee","common"])(D));export{B as ConnectedOtaPage};
