matterbridge 3.2.8-dev-20250919-0c45649 → 3.2.8-dev-20250920-80e7900
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/frontend.js +2 -6
- package/dist/matterbridge.js +6 -11
- package/frontend/build/assets/index.js +2 -2
- package/frontend/build/index.html +12 -12
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{B as e,y as o,S as lt,I as Xt,U as
|
|
1
|
+
import{B as e,y as o,S as lt,I as Xt,U as xr,V as br,X as Xe,Y as vr,Z as yr}from"./vendor_node_modules.js";import{u as jr,S as Cr}from"./vendor_notistack.js";import{D as De,a as Ne,b as Pe,B as ne,c as Z,A as Sr,I as J,C as wr,T as $,S as Mr,F as Zt,H as kr,d as er,e as _e,R as yt,P as qe,M as Ir,f as rt,g as F,L as K,h as re,i as dt,V as ct,j as $e,k as Nt,l as Dr,m as Nr,n as pe,o as Pr,p as Wr,q as jt,r as se,s as Fe,K as Ht,t as Rt,u as St,v as pt,w as it,x as ut,W as at,y as mt,z as gt,E as Le,G as $t,J as Ot,N as Tr,O as Fr,Q as st,U as Te,X as Je,Y as tr,Z as Lr,_ as Hr,$ as Rr,a0 as $r,a1 as rr,a2 as Ct,a3 as Or,a4 as Er,a5 as Vr,a6 as _r,a7 as Et,a8 as Ar,a9 as Ur,aa as zr,ab as qr,ac as Br,ad as Jr,ae as Qr,af as Vt,ag as Gr,ah as Kr,ai as Yr,aj as Xr,ak as Zr,al as eo,am as to,an as ro,ao as oo,ap as no,aq as io,ar as ao,as as so,at as lo,au as co,av as _t,aw as ot,ax as or,ay as Ie,az as nr,aA as wt,aB as Ae,aC as po,aD as uo}from"./vendor_mui.js";import{Q as mo}from"./vendor_qrcode.js";import{I as te,m as At,a as go,b as ho,c as Ut,d as fo,e as Tt,f as Ft,g as xo,h as bo,i as vo,j as yo,k as jo,l as Co,n as So,o as wo,p as zt,q as Mo,r as ko,s as Io,t as Do,u as No,v as Po,w as Wo,x as To,y as qt,z as Fo,A as Lo,B as Ho}from"./vendor_mdi.js";import{r as Ue}from"./vendor_react_table.js";import{F as Ro,v as $o,e as Oo,a as Eo,g as Vo,b as _o,c as Ao,d as Pt,A as Uo}from"./vendor_rjsf.js";import"./vendor_lodash.js";import"./vendor_emotion.js";(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))i(l);new MutationObserver(l=>{for(const g of l)if(g.type==="childList")for(const b of g.addedNodes)b.tagName==="LINK"&&b.rel==="modulepreload"&&i(b)}).observe(document,{childList:!0,subtree:!0});function a(l){const g={};return l.integrity&&(g.integrity=l.integrity),l.referrerPolicy&&(g.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?g.credentials="include":l.crossOrigin==="anonymous"?g.credentials="omit":g.credentials="same-origin",g}function i(l){if(l.ep)return;l.ep=!0;const g=a(l);fetch(l.href,g)}})();/**
|
|
2
2
|
* This file contains the types for WebSocket messages.
|
|
3
3
|
*
|
|
4
4
|
* @file frontendTypes.ts
|
|
@@ -20,4 +20,4 @@ import{B as e,y as o,S as lt,I as Xt,U as fr,V as xr,X as Xe,Y as br,Z as vr}fro
|
|
|
20
20
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
21
|
* See the License for the specific language governing permissions and
|
|
22
22
|
* limitations under the License.
|
|
23
|
-
*/var we=(r=>(r[r.Log=0]="Log",r[r.RefreshRequired=1]="RefreshRequired",r[r.RestartRequired=2]="RestartRequired",r[r.RestartNotRequired=3]="RestartNotRequired",r[r.CpuUpdate=4]="CpuUpdate",r[r.MemoryUpdate=5]="MemoryUpdate",r[r.UptimeUpdate=6]="UptimeUpdate",r[r.Snackbar=7]="Snackbar",r[r.UpdateRequired=8]="UpdateRequired",r[r.StateUpdate=9]="StateUpdate",r[r.CloseSnackbar=10]="CloseSnackbar",r[r.ShellySysUpdate=100]="ShellySysUpdate",r[r.ShellyMainUpdate=101]="ShellyMainUpdate",r))(we||{});function he(r){return r.id>=0&&r.id<=101}function Ve(r){return r.id>101&&r.src==="Matterbridge"&&r.dst==="Frontend"&&("success"in r||"error"in r)}function Uo({open:r,title:c,message:i,onConfirm:n,onCancel:s}){const h=t=>{a&&console.log("Confirmed"),t.preventDefault(),n()},y=t=>{a&&console.log("Canceled"),t.preventDefault(),s()};return e.jsxs(De,{open:r,children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:c})]})}),e.jsxs(Pe,{children:[e.jsx("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",margin:"0",marginBottom:"20px",maxHeight:"350px",maxWidth:"350px"},children:e.jsx("p",{style:{flex:1,margin:"0"},children:i})}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-around"},children:[e.jsx(ne,{onClick:h,variant:"contained",color:"primary",size:"small",children:"Confirm"}),e.jsx(ne,{onClick:y,variant:"contained",color:"primary",size:"small",children:"Cancel"})]})]})]})}const ht=[],nt=o.createContext(null);function zo({children:r}){const{enqueueSnackbar:c,closeSnackbar:i}=yr(),n=o.useCallback(b=>{a&&console.log(`UiProvider closeSnackbarMessage: message ${b}`);const D=ht.findIndex(O=>O.message===b);D!==-1&&(i(ht[D].key),ht.splice(D,1),a&&console.log(`UiProvider closeSnackbarMessage: message ${b} removed from persistMessages`))},[i]),s=o.useCallback((b,D,O)=>{a&&console.log(`UiProvider showSnackbarMessage: message ${b} timeout ${D}`);const N=c(b,{variant:"default",autoHideDuration:D==null||D>0?(D??5)*1e3:null,persist:D===0,content:u=>e.jsx(X,{sx:{margin:"0",padding:"0",width:"300px",marginRight:"30px"},children:e.jsx(Cr,{severity:O??"info",variant:"filled",sx:{color:"#fff",fontWeight:"normal",width:"100%",cursor:"pointer",padding:"0px 10px"},onClick:()=>i(u),action:e.jsx(B,{size:"small",onClick:()=>i(u),sx:{color:"#fff"},children:e.jsx(Sr,{fontSize:"small"})}),children:b},u)},u)});D===0&&(a&&console.log(`UiProvider showSnackbarMessage: message ${b} timeout ${D} - persist key ${N}`),ht.push({message:b,key:N}))},[c,i]),[h,y]=o.useState(!1),[t,l]=o.useState(""),[j,F]=o.useState(""),[f,H]=o.useState(""),V=o.useRef(null),M=o.useRef(null),E=()=>{a&&console.log(`UiProvider handle confirm action ${f}`),y(!1),V.current&&V.current(f)},p=()=>{a&&console.log(`UiProvider handle cancel action ${f}`),y(!1),M.current&&M.current(f)},U=o.useCallback((b,D,O,N,u)=>{a&&console.log(`UiProvider showConfirmCancelDialog for command ${O}`),l(b),F(D),H(O),V.current=N,M.current=u,y(!0)},[]),v=o.useMemo(()=>({showSnackbarMessage:s,closeSnackbarMessage:n,closeSnackbar:i,showConfirmCancelDialog:U}),[s,n,i,U]);return e.jsxs(nt.Provider,{value:v,children:[e.jsx(Uo,{open:h,title:t,message:j,onConfirm:E,onCancel:p}),r]})}const ir=o.createContext(null),xe=o.createContext(null);function qo({children:r}){const[c,i]=o.useState(localStorage.getItem("logFilterLevel")??"info"),[n,s]=o.useState(localStorage.getItem("logFilterSearch")??"*"),[h,y]=o.useState([]),[t,l]=o.useState(1e3),[j,F]=o.useState(!0),[f,H]=o.useState(!1),{showSnackbarMessage:V,closeSnackbarMessage:M,closeSnackbar:E}=o.useContext(nt),p=o.useRef([]),U=o.useRef(null),v=o.useRef(1),b=o.useRef(Math.floor(Math.random()*999e3)+1e3),D=o.useRef(null),O=o.useRef(null),N=o.useRef(null),u=o.useRef(c),R=o.useRef(n),C=o.useMemo(()=>window.location.href.replace(/^http/,"ws"),[]),x=o.useMemo(()=>window.location.href.includes("api/hassio_ingress"),[]),w=100,z=60,ce=50,be=300;o.useEffect(()=>{u.current=c},[c]),o.useEffect(()=>{R.current=n},[n]);const S=o.useCallback(()=>Math.floor(Math.random()*999e3)+1e3,[]),m=o.useCallback(I=>{if(U.current&&U.current.readyState===WebSocket.OPEN)try{I.id===void 0&&(I.id=b.current);const g=JSON.stringify(I);U.current.send(g),a&&console.log("WebSocket sent message:",I)}catch(g){a&&console.error(`WebSocket error sending message: ${g}`)}else a&&console.error("WebSocket message not sent, WebSocket not connected:",I)},[]),_=o.useCallback((I,g)=>{const d=`<span style="background-color: #5c0e91; color: white; padding: 1px 5px; font-size: 12px; border-radius: 3px;">${I}</span>`;y(W=>[...W,d+' <span style="color: var(--main-log-color);">'+g+"</span>"])},[]),T=o.useCallback((I,g)=>{i(I),s(g),_("WebSocket",`Filtering by log level "${I}" and log search "${g}"`)},[_]),Z=o.useCallback(I=>{a&&console.log("WebSocket addListener:",I),p.current=[...p.current,I],a&&console.log("WebSocket addListener total listeners:",p.current.length)},[]),fe=o.useCallback(I=>{a&&console.log("WebSocket removeListener:",I),p.current=p.current.filter(g=>g!==I),a&&console.log("WebSocket removeListener total listeners:",p.current.length)},[]),Me=o.useCallback(()=>{C===""||C===null||C===void 0||(_("WebSocket",`Connecting to WebSocket: ${C}`),U.current=new WebSocket(C),U.current.onmessage=I=>{f||H(!0);try{const g=JSON.parse(I.data);if(g.id===void 0)return;if(g.error&&a&&console.error("WebSocket error message:",g),g.id===b.current&&g.src==="Matterbridge"&&g.dst==="Frontend"&&g.response==="pong"){a&&console.log("WebSocket pong response message:",g,"listeners:",p.current.length),O.current&&clearTimeout(O.current),p.current.forEach(W=>W(g));return}if(g.id===we.RefreshRequired){a&&console.log("WebSocket WS_ID_REFRESH_REQUIRED message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.RestartRequired){a&&console.log("WebSocket WS_ID_RESTART_REQUIRED message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.RestartNotRequired){a&&console.log("WebSocket WS_ID_RESTART_NOT_REQUIRED message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.CpuUpdate){a&&console.log("WebSocket WS_ID_CPU_UPDATE message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.MemoryUpdate){a&&console.log("WebSocket WS_ID_MEMORY_UPDATE message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.UptimeUpdate){a&&console.log("WebSocket WS_ID_UPTIME_UPDATE message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.Snackbar&&g.params&&g.params.message){a&&console.log("WebSocket WS_ID_SNACKBAR message:",g,"listeners:",p.current.length),V(g.params.message,g.params.timeout,g.params.severity);return}else if(g.id===we.CloseSnackbar&&g.params&&g.params.message){a&&console.log("WebSocket WS_ID_CLOSE_SNACKBAR message:",g,"listeners:",p.current.length),M(g.params.message);return}else if(g.id===we.ShellySysUpdate){a&&console.log("WebSocket WS_ID_SHELLY_SYS_UPDATE message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id===we.ShellyMainUpdate){a&&console.log("WebSocket WS_ID_SHELLY_MAIN_UPDATE message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}else if(g.id!==we.Log){a&&console.log("WebSocket message:",g,"listeners:",p.current.length),p.current.forEach(W=>W(g));return}if(!g.params||!g.params.level||!g.params.time||!g.params.name||!g.params.message||["debug","info","notice","warn","error","fatal"].includes(g.params.level)&&(u.current==="info"&&g.params.level==="debug"||u.current==="notice"&&(g.params.level==="debug"||g.params.level==="info")||u.current==="warn"&&(g.params.level==="debug"||g.params.level==="info"||g.params.level==="notice")||u.current==="error"&&(g.params.level==="debug"||g.params.level==="info"||g.params.level==="notice"||g.params.level==="warn")||u.current==="fatal"&&(g.params.level==="debug"||g.params.level==="info"||g.params.level==="notice"||g.params.level==="warn"||g.params.level==="error"))||R.current!=="*"&&R.current!==""&&!g.params.message.toLowerCase().includes(R.current.toLowerCase())&&!g.params.name.toLowerCase().includes(R.current.toLowerCase())||g.params.name==="Commissioning"&&g.params.message.includes("is uncommissioned"))return;y(W=>{const ie=`<span style="color: #505050;">[${g.params?.time}]</span>`,se=ve=>{switch(ve?.toLowerCase()){case"debug":return"gray";case"info":return"#267fb7";case"notice":return"green";case"warn":return"#e9db18";case"error":return"red";case"fatal":return"#ff0000";case"spawn":return"#ff00d0";default:return"lightblue"}},J=ve=>{switch(ve?.toLowerCase()){case"warn":return"black";default:return"white"}},me=`${`<span style="background-color: ${se(g.params?.level)}; color: ${J(g.params?.level)}; padding: 1px 5px; font-size: 12px; border-radius: 3px;">${g.params?.level}</span>`} ${ie} <span style="color: #09516d;">[${g.params?.name}]</span> <span style="color: var(--main-log-color);">${g.params?.message}</span>`,oe=[...W,me];return oe.length>t?oe.slice(t/10):oe})}catch(g){console.error(`WebSocketUse error parsing message: ${g}`)}},U.current.onopen=()=>{a&&console.log(`WebSocket: Connected to WebSocket: ${C}`),_("WebSocket",`Connected to WebSocket: ${C}`),H(!0),E(),v.current=1,N.current=setTimeout(()=>{D.current=setInterval(()=>{m({id:b.current,method:"ping",src:"Frontend",dst:"Matterbridge",params:{}}),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{a&&console.error(`WebSocketUse: No pong response received from WebSocket: ${C}`),_("WebSocket",`No pong response received from WebSocket: ${C}`),H(!1)},1e3*ce)},1e3*z)},1e3*be)},U.current.onclose=()=>{a&&console.error(`WebSocket: Disconnected from WebSocket ${x?"with Ingress":""}: ${C}`),_("WebSocket",`Disconnected from WebSocket: ${C}`),H(!1),E(),N.current&&clearTimeout(N.current),O.current&&clearTimeout(O.current),D.current&&clearInterval(D.current),_("WebSocket",`Reconnecting (attempt ${v.current} of ${w}) to WebSocket${x?" (Ingress)":""}: ${C}`),x?setTimeout(q,5e3):v.current===1?q():v.current<w?setTimeout(q,1e3*v.current):_("WebSocket",`Reconnect attempts exceeded limit of ${w} retries, refresh the page to reconnect to: ${C}`),v.current=v.current+1},U.current.onerror=I=>{a&&console.error(`WebSocket: WebSocket error connecting to ${C}:`,I),_("WebSocket",`WebSocket error connecting to ${C}`)})},[C]),q=o.useCallback(()=>{a&&console.log(`WebSocket attemptReconnect ${v.current}/${w} to:`,C),Me()},[Me]);o.useEffect(()=>(Me(),()=>{U.current&&U.current.readyState===WebSocket.OPEN&&U.current.close()}),[Me]);const k=o.useMemo(()=>({messages:h,maxMessages:t,autoScroll:j,setMessages:y,setLogFilters:T,setMaxMessages:l,setAutoScroll:F}),[h,y,T]),P=o.useMemo(()=>({maxMessages:t,autoScroll:j,logFilterLevel:c,logFilterSearch:n,setMessages:y,setLogFilters:T,setMaxMessages:l,setAutoScroll:F,online:f,retry:v.current,getUniqueId:S,addListener:Z,removeListener:fe,sendMessage:m,logMessage:_}),[t,j,y,T,l,F,f,v.current,Z,fe,m,_]);return e.jsx(ir.Provider,{value:k,children:e.jsx(xe.Provider,{value:P,children:r})})}function Bo(){const{showSnackbarMessage:r,showConfirmCancelDialog:c}=o.useContext(nt),{online:i,sendMessage:n,logMessage:s,addListener:h,removeListener:y,getUniqueId:t}=o.useContext(xe),[l,j]=o.useState(!1),[F,f]=o.useState(!1),[H,V]=o.useState(!1),[M,E]=o.useState(!1),[p,U]=o.useState(null),v=o.useRef(t()),[b,D]=o.useState(null),[O,N]=o.useState(null),[u,R]=o.useState(null),[C,x]=o.useState(null),[w,z]=o.useState(null),ce=()=>{window.open("https://www.buymeacoffee.com/luligugithub","_blank")},be=()=>{window.open("https://github.com/Luligu/matterbridge/blob/main/README.md","_blank")},S=()=>{p?.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?window.open("https://github.com/Luligu/matterbridge/blob/dev/CHANGELOG.md","_blank"):window.open("https://github.com/Luligu/matterbridge/blob/main/CHANGELOG.md","_blank")},m=()=>{window.open("https://discord.gg/QX58CDe6hd","_blank")},_=()=>{window.open("https://github.com/Luligu/matterbridge","_blank")},T=()=>{n({id:v.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge",restart:!0}})},Z=()=>{n({id:v.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge@dev",restart:!0}})},fe=()=>{n({id:v.current,sender:"Header",method:"/api/checkupdates",src:"Frontend",dst:"Matterbridge",params:{}})},Me=()=>{a&&console.log("Header: handleShellySystemUpdateClick"),s("Matterbridge","Installing system updates..."),n({id:v.current,sender:"Header",method:"/api/shellysysupdate",src:"Frontend",dst:"Matterbridge",params:{}})},q=()=>{a&&console.log("Header: handleShellyMainUpdateClick"),s("Matterbridge","Installing software updates..."),n({id:v.current,sender:"Header",method:"/api/shellymainupdate",src:"Frontend",dst:"Matterbridge",params:{}})},k=()=>{a&&console.log("Header: handleShellyCreateSystemLog"),n({id:v.current,sender:"Header",method:"/api/shellycreatesystemlog",src:"Frontend",dst:"Matterbridge",params:{}})},P=()=>{a&&console.log("Header: handleShellyDownloadSystemLog"),s("Matterbridge","Downloading Shelly system log..."),r("Downloading Shelly system log...",5),window.location.href="./api/shellydownloadsystemlog"},I=()=>{p?.matterbridgeInformation.restartMode===""?n({id:v.current,sender:"Header",method:"/api/restart",src:"Frontend",dst:"Matterbridge",params:{}}):n({id:v.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},g=()=>{n({id:v.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},d=()=>{n({id:v.current,sender:"Header",method:"/api/reboot",src:"Frontend",dst:"Matterbridge",params:{}})},W=()=>{n({id:v.current,sender:"Header",method:"/api/softreset",src:"Frontend",dst:"Matterbridge",params:{}})},ie=()=>{n({id:v.current,sender:"Header",method:"/api/hardreset",src:"Frontend",dst:"Matterbridge",params:{}})},se=Q=>{D(Q.currentTarget)},J=Q=>{a&&console.log("Header: handleMenuClose",Q),D(null),Q==="download-mblog"?(s("Matterbridge","Downloading matterbridge log..."),r("Downloading matterbridge log...",5),window.location.href="./api/download-mblog"):Q==="download-mjlog"?(s("Matterbridge","Downloading matter log..."),r("Downloading matter log...",5),window.location.href="./api/download-mjlog"):Q==="view-mblog"?(s("Matterbridge","Loading matterbridge log..."),r("Loading matterbridge log...",5),window.location.href="./api/view-mblog"):Q==="view-mjlog"?(s("Matterbridge","Loading matter log..."),r("Loading matter log...",5),window.location.href="./api/view-mjlog"):Q==="view-shellylog"?(s("Matterbridge","Loading shelly system log..."),r("Loading shelly system log...",5),window.location.href="./api/shellyviewsystemlog"):Q==="download-mbstorage"?(s("Matterbridge","Downloading matterbridge storage..."),r("Downloading matterbridge storage...",5),window.location.href="./api/download-mbstorage"):Q==="download-pluginstorage"?(s("Matterbridge","Downloading matterbridge plugins storage..."),r("Downloading matterbridge plugins storage...",5),window.location.href="./api/download-pluginstorage"):Q==="download-pluginconfig"?(s("Matterbridge","Downloading matterbridge plugins config..."),r("Downloading matterbridge plugins config...",5),window.location.href="./api/download-pluginconfig"):Q==="download-mjstorage"?(s("Matterbridge","Downloading matter storage..."),r("Downloading matter storage...",5),window.location.href="./api/download-mjstorage"):Q==="download-backup"?(s("Matterbridge","Downloading backup..."),r("Downloading backup...",10),window.location.href="./api/download-backup"):Q==="update"?T():Q==="updatedev"?Z():Q==="updatecheck"?fe():Q==="shelly-sys-update"?Me():Q==="shelly-main-update"?q():Q==="shelly-create-system-log"?k():Q==="shelly-download-system-log"?P():Q==="softreset"?W():Q==="hardreset"?ie():Q==="restart"?I():Q==="shutdown"?g():Q==="reboot"?d():Q==="create-backup"?n({id:v.current,sender:"Header",method:"/api/create-backup",src:"Frontend",dst:"Matterbridge",params:{}}):Q==="unregister"?n({id:v.current,sender:"Header",method:"/api/unregister",src:"Frontend",dst:"Matterbridge",params:{}}):Q==="reset"?n({id:v.current,sender:"Header",method:"/api/reset",src:"Frontend",dst:"Matterbridge",params:{}}):Q==="factoryreset"&&n({id:v.current,sender:"Header",method:"/api/factoryreset",src:"Frontend",dst:"Matterbridge",params:{}})},de=Q=>{a&&console.log("Header: handleMenuCloseCancel:",Q),D(null)},me=Q=>{N(Q.currentTarget)},oe=()=>{N(null)},ve=Q=>{R(Q.currentTarget)},ae=()=>{R(null)},ge=Q=>{x(Q.currentTarget)},Y=()=>{x(null)},ue=Q=>{z(Q.currentTarget)},ye=()=>{z(null)},Ge=()=>{ei(),a&&console.log("Matterbridge logo clicked: debug is now",a)};return o.useEffect(()=>{const Q=ee=>{ee.src==="Matterbridge"&&ee.dst==="Frontend"&&(Ve(ee)&&ee.method==="/api/settings"&&ee.id===v.current&&(a&&console.log("Header received settings:",ee.response),U(ee.response),j(ee.response.matterbridgeInformation.restartRequired||ee.response.matterbridgeInformation.fixedRestartRequired),f(ee.response.matterbridgeInformation.fixedRestartRequired),V(ee.response.matterbridgeInformation.updateRequired)),he(ee)&&ee.method==="refresh_required"&&ee.params.changed==="settings"&&(a&&console.log(`Header received refresh_required: changed=${ee.params.changed} and sending /api/settings request`),n({id:v.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),he(ee)&&ee.method==="restart_required"&&(a&&console.log(`Header received restart_required with fixed: ${ee.params.fixed}`),j(!0),ee.params.fixed===!0&&f(!0)),he(ee)&&ee.method==="restart_not_required"&&(a&&console.log("Header received restart_not_required"),j(!1)),he(ee)&&ee.method==="update_required"&&(a&&console.log("Header received update_required"),V(!0)),he(ee)&&ee.method==="update_required_dev"&&(a&&console.log("Header received update_required_dev"),E(!0)),he(ee)&&ee.id===we.ShellySysUpdate&&(a&&console.log("Header received WS_ID_SHELLY_SYS_UPDATE:"),U(Te=>Te?{matterbridgeInformation:{...Te.matterbridgeInformation,shellySysUpdate:ee.params.available},systemInformation:Te.systemInformation}:null)),he(ee)&&ee.id===we.ShellyMainUpdate&&(a&&console.log("Header received WS_ID_SHELLY_MAIN_UPDATE:"),U(Te=>Te?{matterbridgeInformation:{...Te.matterbridgeInformation,shellyMainUpdate:ee.params.available},systemInformation:Te.systemInformation}:null)))};return h(Q),a&&console.log(`Header added WebSocket listener id ${v.current}`),()=>{y(Q),a&&console.log("Header removed WebSocket listener")}},[h,y,n,r]),o.useEffect(()=>{i&&(a&&console.log("Header sending /api/settings requests"),n({id:v.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[i,n]),a&&console.log("Header rendering..."),!i||!p?null:e.jsxs("div",{className:"header",children:[e.jsxs("div",{className:"sub-header",children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"30px"},onClick:Ge}),e.jsx("h2",{style:{fontSize:"22px",color:"var(--main-icon-color)",margin:"0px"},children:"Matterbridge"}),e.jsxs("nav",{children:[e.jsx(lt,{to:"/",className:"nav-link",children:"Home"}),e.jsx(lt,{to:"/devices",className:"nav-link",children:"Devices"}),e.jsx(lt,{to:"/log",className:"nav-link",children:"Logs"}),e.jsx(lt,{to:"/settings",className:"nav-link",children:"Settings"})]})]}),e.jsxs("div",{className:"sub-header",children:[!p.matterbridgeInformation.readOnly&&H&&e.jsx($,{title:"New Matterbridge version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:T,children:["Update to v.",p.matterbridgeInformation.matterbridgeLatestVersion]})}),!p.matterbridgeInformation.readOnly&&M&&e.jsx($,{title:"New Matterbridge dev version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:Z,children:["Update to new dev v.",p.matterbridgeInformation.matterbridgeDevVersion.split("-dev-")[0]]})}),!p.matterbridgeInformation.readOnly&&e.jsx($,{title:"Matterbridge version, click to see the changelog",children:e.jsxs("span",{className:"status-information",onClick:S,children:["v.",p.matterbridgeInformation.matterbridgeVersion]})}),p.matterbridgeInformation.shellyBoard&&e.jsx("img",{src:"Shelly.svg",alt:"Shelly Icon",style:{height:"30px",padding:"0px",margin:"0px",marginRight:"30px"}}),p.matterbridgeInformation.bridgeMode!==""&&p.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Bridge mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:p.matterbridgeInformation.bridgeMode})}):null,p.matterbridgeInformation.restartMode!==""&&p.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Restart mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:p.matterbridgeInformation.restartMode})}):null,p.matterbridgeInformation.profile&&p.matterbridgeInformation.profile!==""&&p.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Current profile",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:p.matterbridgeInformation.profile})}):null]}),e.jsxs("div",{className:"sub-header",style:{gap:"5px"},children:[p.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Matterbridge discord group",children:e.jsx("img",{src:"discord.svg",alt:"Discord Logo",style:{cursor:"pointer",height:"25px"},onClick:m})}):null,p.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Give a star to Matterbridge",children:e.jsx(B,{style:{color:"#FFD700",margin:"0",padding:"0"},onClick:_,children:e.jsx(wr,{})})}):null,p.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Sponsor Matterbridge",children:e.jsx(B,{style:{color:"#b6409c",margin:"0",padding:"0"},onClick:ce,children:e.jsx(Zt,{})})}):null,e.jsx($,{title:"Matterbridge help",children:e.jsx(B,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:be,children:e.jsx(Mr,{})})}),e.jsx($,{title:"Matterbridge changelog",children:e.jsx(B,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:S,children:e.jsx(er,{})})}),p.matterbridgeInformation&&!p.matterbridgeInformation.readOnly&&e.jsx($,{title:"Update matterbridge to latest version",children:e.jsx(B,{style:{color:H?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:T,children:e.jsx(_e,{})})}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&p.matterbridgeInformation.shellySysUpdate&&e.jsx($,{title:"Shelly system update",children:e.jsx(B,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:Me,children:e.jsx(_e,{})})}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&p.matterbridgeInformation.shellyMainUpdate&&e.jsx($,{title:"Shelly software update",children:e.jsx(B,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:q,children:e.jsx(_e,{})})}),e.jsx($,{title:"Restart matterbridge",children:e.jsx(B,{style:{color:l||F?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:I,children:e.jsx(yt,{})})}),p.matterbridgeInformation.restartMode===""?e.jsx($,{title:"Shut down matterbridge",children:e.jsx(B,{style:{color:l||F?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:g,children:e.jsx(qe,{})})}):null,e.jsx($,{title:"Download, backup and more",children:e.jsx(B,{onClick:se,children:e.jsx(kr,{style:{color:"var(--main-icon-color)"}})})}),e.jsxs(rt,{id:"command-menu",anchorEl:b,keepMounted:!0,open:!!b,onClose:()=>J(""),children:[p.matterbridgeInformation&&!p.matterbridgeInformation.readOnly&&e.jsxs(L,{onClick:()=>J("update"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Install latest stable",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&!p.matterbridgeInformation.readOnly&&e.jsxs(L,{onClick:()=>J("updatedev"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Install latest dev",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&!p.matterbridgeInformation.readOnly&&e.jsxs(L,{onClick:()=>J("updatecheck"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Check for updates",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&p.matterbridgeInformation.shellySysUpdate&&e.jsxs(L,{onClick:()=>J("shelly-sys-update"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shelly system update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&p.matterbridgeInformation.shellyMainUpdate&&e.jsxs(L,{onClick:()=>J("shelly-main-update"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shelly software update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>J("restart"),children:[e.jsx(K,{children:e.jsx(yt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Restart",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation.restartMode===""?e.jsxs(L,{onClick:()=>J("shutdown"),children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shutdown",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}):null,p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&e.jsxs(L,{onClick:()=>{c("Reboot","Are you sure you want to reboot the Shelly board?","reboot",J,de)},children:[e.jsx(K,{children:e.jsx(yt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reboot...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsx(dt,{}),e.jsxs(L,{onClick:ve,children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"View",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-view",anchorEl:u,keepMounted:!0,open:!!u,onClose:ae,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(L,{onClick:()=>{J("view-mblog"),ae()},children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("view-mjlog"),ae()},children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&e.jsxs(L,{onClick:()=>{J("view-shellylog"),ae()},children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(dt,{}),e.jsxs(L,{onClick:ge,children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Download",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-download",anchorEl:C,keepMounted:!0,open:!!C,onClose:Y,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(L,{onClick:()=>{J("download-mbstorage"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("download-pluginstorage"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge plugins storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("download-pluginconfig"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge plugins config",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("download-mblog"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("download-mjstorage"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matter storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("download-mjlog"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&e.jsxs(L,{onClick:()=>{J("shelly-create-system-log"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Create Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&e.jsxs(L,{onClick:()=>{J("shelly-download-system-log"),Y()},children:[e.jsx(K,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Download Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(dt,{}),e.jsxs(L,{onClick:me,children:[e.jsx(K,{children:e.jsx(Nt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-backup",anchorEl:O,keepMounted:!0,open:!!O,onClose:oe,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(L,{onClick:()=>{J("create-backup"),oe()},children:[e.jsx(K,{children:e.jsx(Nt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Create backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{J("download-backup"),oe()},children:[e.jsx(K,{children:e.jsx(Nt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Download backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(dt,{}),e.jsxs(L,{onClick:ue,children:[e.jsx(K,{children:e.jsx(Ir,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-reset",anchorEl:w,keepMounted:!0,open:!!w,onClose:ye,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(L,{onClick:()=>{ye(),c("Reset all devices and shutdown","Are you sure you want to unregister all devices? This will temporarily remove all devices from the controller and you may loose the controller configuration.","unregister",J,de)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset all devices...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(L,{onClick:()=>{ye(),c("Reset commissioning and shutdown","Are you sure you want to reset the commissioning? You will have to manually remove Matterbridge from the controller.","reset",J,de)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset commissioning...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),!p.matterbridgeInformation.readOnly&&e.jsxs(L,{onClick:()=>{ye(),c("Factory reset and shutdown","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","factoryreset",J,de)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&e.jsxs(L,{onClick:()=>{ye(),c("Network reset","Are you sure you want to factory reset the network parameters?","softreset",J,de)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset network...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),p.matterbridgeInformation&&p.matterbridgeInformation.shellyBoard&&e.jsxs(L,{onClick:()=>{ye(),c("Factory reset","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","hardreset",J,de)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]})]})]})]})}const Jo=o.memo(Bo),Qo=()=>"ontouchstart"in window||typeof window.DocumentTouch<"u"&&document instanceof window.DocumentTouch?(a&&console.log("WebSocketLogs detectTouchscreen = true"),!0):(a&&console.log("WebSocketLogs detectTouchscreen = false"),!1);function Go(){const{messages:r,autoScroll:c}=o.useContext(ir),[i,n]=o.useState(!1),s=o.useRef(null),h=o.useMemo(()=>Qo(),[]),y=l=>n(!0),t=l=>n(!1);return o.useEffect(()=>{a&&console.log(`WebSocketLogs autoScroll: ${c} isHovering: ${i}`),c&&!i&&!h&&s.current?.scrollIntoView({behavior:"smooth"})},[r,i,c,h]),e.jsx("div",{style:{margin:"0px",padding:"0px"},children:e.jsxs("ul",{style:{margin:"0px",padding:"0px"},onMouseEnter:y,onMouseLeave:t,children:[r.map((l,j)=>e.jsx("li",{style:{wordWrap:"break-word",maxHeight:"200px",overflow:"hidden"},dangerouslySetInnerHTML:{__html:l}},j)),e.jsx("div",{ref:s})]})})}const ar=o.memo(Go);function Qe(){const{retry:r}=o.useContext(xe),c=()=>{window.location.reload()};return e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",fontSize:"20px",flexDirection:"column",color:"var(--main-text-color)",height:"100vh",backgroundColor:"var(--main-bg-color)"},children:e.jsx(X,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:r<100?e.jsxs(e.Fragment,{children:[e.jsx(Dr,{style:{color:"var(--primary-color)"}}),e.jsxs("div",{style:{marginTop:"20px",color:"var(--primary-color)"},children:["Reconnecting to Matterbridge ","(attempt "+r+")","..."]})]}):e.jsxs("div",{style:{marginTop:"20px",color:"var(--primary-color)",textAlign:"center"},children:["Unable to connect to Matterbridge after multiple attempts.",e.jsx("br",{}),"Please check your network connection.",e.jsx("br",{}),e.jsx(ne,{variant:"contained",color:"primary",onClick:c,style:{marginTop:"20px"},children:"Refresh the Page"})]})})})}function Ko({value:r,maxChars:c}){let i=r;if(r.length>c&&c>3){const n=c-3,s=r.substring(0,Math.ceil(n/2)),h=r.substring(r.length-Math.floor(n/2),r.length);i=`${s} … ${h}`}return r!==i?e.jsx($,{title:r,placement:"top",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[0,12]}}]}},children:e.jsx("span",{children:i})}):e.jsx("span",{children:i})}function Yo({systemInfo:r,compact:c}){const[i,n]=o.useState(r),{sendMessage:s,addListener:h,removeListener:y}=o.useContext(xe);if(a&&console.log("SystemInfoTable:",i,"compact:",c),r&&c&&i.totalMemory&&i.freeMemory){const t=i.totalMemory,l=i.freeMemory;i.freeMemory=`${l} / ${t}`,i.totalMemory=""}if(r&&c&&i.heapTotal&&i.heapUsed){const t=i.heapTotal,l=i.heapUsed;i.heapUsed=`${l} / ${t}`,i.heapTotal=""}if(r&&c&&i.osRelease&&i.osType){const t=i.osType,l=i.osRelease;i.osType=`${t} (${l})`,i.osRelease=""}if(r&&c&&i.osArch&&i.osPlatform){const t=i.osPlatform,l=i.osArch;i.osPlatform=`${t} (${l})`,i.osArch=""}return o.useEffect(()=>{const t=l=>{l.src==="Matterbridge"&&l.dst==="Frontend"&&(he(l)&&l.method==="memory_update"&&l.params&&l.params.totalMemory&&l.params.freeMemory&&l.params.heapTotal&&l.params.heapUsed&&l.params.rss&&(a&&console.log("SystemInfoTable received memory_update",l),(i.totalMemory!==l.params?.totalMemory||i.freeMemory!==l.params?.freeMemory||i.heapTotal!==l.params?.heapTotal||i.heapUsed!==l.params?.heapUsed||i.rss!==l.params?.rss)&&n(j=>({...j,totalMemory:l.params?.totalMemory?l.params.totalMemory:"",freeMemory:l.params?.freeMemory?l.params.freeMemory:"",heapTotal:l.params?.heapTotal?l.params.heapTotal:"",heapUsed:l.params?.heapUsed?l.params.heapUsed:"",rss:l.params?.rss?l.params.rss:""}))),he(l)&&l.method==="cpu_update"&&l.params&&l.params.cpuUsage&&(a&&console.log("SystemInfoTable received cpu_update",l),i.cpuUsage!==(l.params?.cpuUsage?l.params.cpuUsage.toFixed(2)+" %":"")&&n(j=>({...j,cpuUsage:l.params?.cpuUsage?l.params.cpuUsage.toFixed(2)+" %":""}))),he(l)&&l.method==="uptime_update"&&l.params&&l.params.systemUptime&&l.params.processUptime&&(a&&console.log("SystemInfoTable received uptime_update",l),(i.systemUptime!==l.params?.systemUptime||i.processUptime!==l.params?.processUptime)&&n(j=>({...j,systemUptime:l.params?.systemUptime?l.params.systemUptime:"",processUptime:l.params?.processUptime?l.params.processUptime:""}))))};return a&&console.log("SystemInfoTable useEffect WebSocketMessage mounting"),h(t),a&&console.log("SystemInfoTable useEffect WebSocketMessage mounted"),()=>{a&&console.log("SystemInfoTable useEffect WebSocketMessage unmounting"),y(t),a&&console.log("SystemInfoTable useEffect WebSocketMessage unmounted")}},[h,i.cpuUsage,i.freeMemory,i.heapTotal,i.heapUsed,i.processUptime,i.rss,i.systemUptime,i.totalMemory,y,s]),i?(a&&console.log("SystemInfoTable rendering..."),e.jsxs("div",{className:"MbfWindowDiv",style:{minWidth:"302px",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"System Information"})}),e.jsx("div",{className:"MbfWindowDivTable",children:e.jsx("table",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx("tbody",{style:{border:"none",borderCollapse:"collapse"},children:Object.entries(i).filter(([t,l])=>l!==void 0&&l!=="").map(([t,l],j)=>e.jsxs("tr",{className:j%2===0?"table-content-even":"table-content-odd",style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:t}),e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx(Ko,{value:typeof l!="string"?l.toString():l,maxChars:25})})]},t))})})})]})):null}const Xo=o.memo(Yo),Bt={margin:"0px",padding:"0px",color:"var(--div-text-color)",transition:"color 0.2s ease","& svg":{display:"block"},"& svg path":{fill:"var(--div-text-color)",transition:"fill 0.2s ease"},"&:hover":{color:"var(--primary-color)"},"&:hover svg path":{fill:"var(--primary-color)"},"&:focus-visible":{outline:"2px solid var(--primary-color)",outlineOffset:"2px"}},Zo=r=>{if(!r)return"";const c=r.toString().replace(/[^0-9]/g,"");if(c.length<5)return c;const i=c.slice(0,4),n=c.slice(4,7),s=c.slice(7,11);return[i,n,s].filter(Boolean).join("-")};function en({id:r}){const{online:c,sendMessage:i,addListener:n,removeListener:s,getUniqueId:h}=o.useContext(xe),[y,t]=o.useState(null),[l,j]=o.useState(null),F=o.useRef(null),f=o.useRef(h()),{showConfirmCancelDialog:H}=o.useContext(nt);o.useEffect(()=>{a&&console.log(`QRDiv received storeId update "${r}"`),r&&(a&&console.log(`QRDiv sending data request for storeId "${r}"`),t(r),i({id:f.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:r,server:!0}}))},[r]),o.useEffect(()=>{const v=b=>{b.src==="Matterbridge"&&b.dst==="Frontend"&&he(b)&&b.id===we.RefreshRequired&&b.params.changed==="matter"&&b.params.matter&&(a&&console.log(`QRDiv received refresh_required: changed=${b.params.changed} for storeId "${b.params.matter.id}":`,b.params.matter),y===b.params.matter.id&&(a&&console.log(`QRDiv received refresh_required/matter: setting matter data for storeId "${b.params.matter.id}":`,b.params.matter),F.current&&clearTimeout(F.current),b.params.matter.advertising&&b.params.matter.advertiseTime&&b.params.matter.advertiseTime+9e5<=Date.now()&&(b.params.matter.advertising=!1),j(b.params.matter),b.params.matter.advertising&&(a&&console.log(`QRDiv setting matter advertise timeout for storeId "${b.params.matter.id}":`,b.params.matter.advertiseTime+9e5-Date.now()),F.current=setTimeout(()=>{F.current&&clearTimeout(F.current),a&&console.log(`QRDiv clearing advertising state for storeId "${y}" after 15 minutes`),j(D=>D&&{...D,advertising:!1})},b.params.matter.advertiseTime+9e5-Date.now()))))};return n(v),a&&console.log("QRDiv webSocket effect mounted"),()=>{s(v),F.current&&clearTimeout(F.current),a&&console.log("QRDiv webSocket effect unmounted")}},[y]);const V=()=>{a&&console.log(`QRDiv sent matter startCommission for node "${l?.id}"`),l&&i({id:f.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:l.id,startCommission:!0}})},M=()=>{a&&console.log(`QRDiv sent matter stopCommission for node "${l?.id}"`),l&&i({id:f.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:l.id,stopCommission:!0}})},E=()=>{a&&console.log(`QRDiv sent matter advertise for node "${l?.id}"`),l&&i({id:f.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:l.id,advertise:!0}})},p=v=>{a&&console.log(`QRDiv sent matter removeFabric for node "${l?.id}" and fabricIndex ${v}`),l&&i({id:f.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:l.id,removeFabric:v}})},U=async()=>{if(!l||!l.manualPairingCode)return;const v=l.manualPairingCode.toString();try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(v);else{const b=document.createElement("textarea");b.value=v,b.style.position="fixed",b.style.opacity="0",document.body.appendChild(b),b.focus(),b.select(),document.execCommand("copy"),document.body.removeChild(b)}a&&console.log("Manual pairing code copied to clipboard")}catch(b){console.error("Failed to copy manual pairing code",b)}};return!l||!c?(a&&console.log("QRDiv rendering undefined state"),null):l.advertising&&l.qrPairingCode&&l.manualPairingCode?(a&&console.log("QRDiv rendering advertising state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"QR pairing code"}),e.jsxs("div",{className:"MbfWindowHeaderFooterIcons",children:[e.jsx(B,{"aria-label":"send advertising",size:"small",onClick:E,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(te,{path:At,size:"22px"})})}),e.jsx(B,{"aria-label":"stop pairing",size:"small",onClick:M,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Turn off pairing",arrow:!0,children:e.jsx(te,{path:mo,size:"22px"})})})]})]}),e.jsx("p",{className:"MbfWindowHeaderText",style:{overflow:"hidden",maxWidth:"280px",textOverflow:"ellipsis",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:y}),e.jsx(uo,{value:l.qrPairingCode,size:256,level:"M",fgColor:"var(--div-text-color)",bgColor:"var(--div-bg-color)",style:{margin:"20px"}}),e.jsxs("div",{className:"MbfWindowFooter",style:{justifyContent:"space-between"},children:[e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Manual pairing code: ",Zo(l.manualPairingCode)]}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx($,{title:"Copy manual pairing code",arrow:!0,children:e.jsx(B,{"aria-label":"copy manual pairing code",size:"small",onClick:U,sx:Bt,children:e.jsx(te,{path:go,size:.85})})})})]})]})):l.commissioned&&l.fabricInformations&&l.sessionInformations?(a&&console.log("QRDiv rendering commissioned state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Paired fabrics"}),e.jsxs("div",{className:"MbfWindowHeaderFooterIcons",children:[e.jsx(B,{"aria-label":"send advertising",size:"small",onClick:E,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(te,{path:At,size:"22px"})})}),e.jsx(B,{"aria-label":"start pairing",size:"small",onClick:V,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Turn on pairing",arrow:!0,children:e.jsx(te,{path:Ut,size:"22px"})})})]})]}),e.jsxs("div",{className:"MbfWindowBodyColumn",style:{paddingTop:"0px"},children:[e.jsx("p",{className:"MbfWindowHeaderText thin-scroll",style:{overflowX:"auto",maxWidth:"280px",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:y}),l.fabricInformations.map((v,b)=>e.jsxs("div",{style:{margin:"0px",padding:"10px",gap:"0px",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)",textAlign:"left",fontSize:"14px"},children:[e.jsxs("div",{style:{marginLeft:"20px",marginBottom:"10px",display:"flex",flexDirection:"row",justifyContent:"space-between",gap:"20px",alignItems:"center"},children:[e.jsxs("p",{className:"status-blue",style:{margin:"0px",padding:"3px 10px",width:"200px",fontSize:"14px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)"},children:["Fabric: ",v.fabricIndex]}),e.jsx($,{title:"Remove the fabric. You will also need to remove it from the controller.",arrow:!0,children:e.jsx(B,{"aria-label":"remove the fabric",size:"small",onClick:()=>H("Remove fabric","Are you sure you want to remove this fabric? You will also need to remove it from the controller.","RemoveFabric",()=>p(v.fabricIndex),()=>{}),sx:{...Bt,padding:"2px"},children:e.jsx(te,{path:ho,size:1})})})]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Vendor: ",v.rootVendorId," ",v.rootVendorName]}),v.label!==""&&e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Label: ",v.label]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Sessions: ",l.sessionInformations?l.sessionInformations.filter(D=>D.fabric?.fabricIndex===v.fabricIndex&&D.isPeerActive===!0).length:"0"," ","subscriptions: ",l.sessionInformations?l.sessionInformations.filter(D=>D.fabric?.fabricIndex===v.fabricIndex&&D.isPeerActive===!0&&D.numberOfActiveSubscriptions>0).length:"0"]})]},b))]}),e.jsx("div",{className:"MbfWindowFooter",children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Serial number: ",l.serialNumber]})})]})):!l.commissioned&&!l.advertising?(a&&console.log("QRDiv rendering not commissioned and not advertising state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsx("div",{className:"MbfWindowHeader",style:{height:"30px"},children:e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"QR pairing code"})}),e.jsx("p",{className:"MbfWindowHeaderText thin-scroll",style:{overflowX:"auto",maxWidth:"280px",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:y}),e.jsx(ne,{onClick:V,endIcon:e.jsx(te,{path:Ut,size:1}),style:{margin:"20px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:"Turn on pairing"}),e.jsx("div",{className:"MbfWindowFooter",children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Serial number: ",l.serialNumber]})})]})):(a&&console.log("QRDiv rendering unknown state"),null)}const tn=o.memo(en);function rn(){const{logMessage:r,sendMessage:c,getUniqueId:i}=o.useContext(xe),[n,s]=o.useState("matterbridge-"),[h,y]=o.useState(!1),[t,l]=o.useState(null),j=o.useRef(i()),F=b=>{b.preventDefault(),y(!0)},f=()=>{y(!1)},H=b=>{b.preventDefault(),y(!1);const D=b.dataTransfer.files[0];if(D){r("Plugins",`Installing package ${D.name}. Please wait...`);const O=new FormData;O.append("file",D),O.append("filename",D.name),fetch("./api/uploadpackage",{method:"POST",body:O}).then(N=>N.text()).then(N=>{r("Plugins",`Server response: ${N}`)}).catch(N=>{console.error("Error uploading plugin file:",N),r("Plugins",`Error installing package ${N}`)})}},V=b=>{const D=b.target.files&&b.target.files[0];if(D){r("Plugins",`Uploading package ${D.name}`);const O=new FormData;O.append("file",D),O.append("filename",D.name),fetch("./api/uploadpackage",{method:"POST",body:O}).then(N=>N.text()).then(N=>{r("Plugins",`Server response: ${N}`)}).catch(N=>{console.error("Error uploading plugin file:",N),r("Plugins",`Error uploading package ${N}`)})}},M=()=>{c({id:j.current,sender:"InstallPlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:n,restart:!1}})},E=()=>{document.getElementById("file-upload")?.click()},p=()=>{c({id:j.current,sender:"InstallPlugins",method:"/api/addplugin",src:"Frontend",dst:"Matterbridge",params:{pluginNameOrPath:n}})},U=b=>{l(b.currentTarget)},v=b=>{b!==""&&s(b),l(null)};return a&&console.log("AddRemovePlugins rendering..."),e.jsxs("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",alignItems:"center",justifyContent:"space-between",margin:"0px",padding:"10px",gap:"20px"},onDragOver:F,onDragLeave:f,onDrop:H,children:[e.jsx(pe,{value:n,onChange:b=>{s(b.target.value)},size:"small",id:"plugin-name",label:"Plugin name or plugin path",variant:"outlined",fullWidth:!0}),e.jsx(B,{onClick:U,children:e.jsx(Nr,{})}),e.jsxs(rt,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:!!t,onClose:()=>v(""),children:[e.jsx(L,{onClick:()=>v("matterbridge-zigbee2mqtt"),children:"matterbridge-zigbee2mqtt"}),e.jsx(L,{onClick:()=>v("matterbridge-somfy-tahoma"),children:"matterbridge-somfy-tahoma"}),e.jsx(L,{onClick:()=>v("matterbridge-shelly"),children:"matterbridge-shelly"}),e.jsx(L,{onClick:()=>v("matterbridge-hass"),children:"matterbridge-hass"}),e.jsx(L,{onClick:()=>v("matterbridge-webhooks"),children:"matterbridge-webhooks"}),e.jsx(L,{onClick:()=>v("matterbridge-bthome"),children:"matterbridge-bthome"}),e.jsx(L,{onClick:()=>v("matterbridge-test"),children:"matterbridge-test"}),e.jsx(L,{onClick:()=>v("matterbridge-example-accessory-platform"),children:"matterbridge-example-accessory-platform"}),e.jsx(L,{onClick:()=>v("matterbridge-example-dynamic-platform"),children:"matterbridge-example-dynamic-platform"}),e.jsx(L,{onClick:()=>v("matterbridge-eve-door"),children:"matterbridge-eve-door"}),e.jsx(L,{onClick:()=>v("matterbridge-eve-motion"),children:"matterbridge-eve-motion"}),e.jsx(L,{onClick:()=>v("matterbridge-eve-energy"),children:"matterbridge-eve-energy"}),e.jsx(L,{onClick:()=>v("matterbridge-eve-weather"),children:"matterbridge-eve-weather"}),e.jsx(L,{onClick:()=>v("matterbridge-eve-room"),children:"matterbridge-eve-room"})]}),e.jsx($,{title:"Install or update a plugin from npm",children:e.jsx(ne,{onClick:M,endIcon:e.jsx(Oe,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Install"})}),e.jsx($,{title:"Upload and install a plugin from a tarball",children:e.jsx(ne,{onClick:E,endIcon:e.jsx(Pr,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Upload"})}),e.jsx($,{title:"Add an installed plugin",children:e.jsx(ne,{onClick:p,endIcon:e.jsx(jt,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Add"})}),e.jsx("input",{id:"file-upload",type:"file",accept:".tgz",style:{display:"none"},onChange:V})]})}const on=o.memo(rn);function Ze({status:r,enabledText:c="Enabled",disabledText:i=void 0,tooltipText:n=void 0,onClick:s}){if(r===void 0)return e.jsx("div",{style:{margin:"-2.5px"},children:e.jsx("div",{})});{const h=e.jsx("div",{className:r?"status-enabled":"status-disabled",style:{cursor:"default"},onClick:s,children:r?c:i??c});return n!==void 0?e.jsx($,{title:n,children:h}):h}}const et={fontSize:"16px",fontWeight:"bold",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},tt={fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},nn={fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)",backgroundColor:"var(--div-bg-color)"},an={fontSize:"16px",fontWeight:"bold",backgroundColor:"var(--div-bg-color)"},Ee={padding:"0px",margin:"0px"},sn="5px 10px 5px 10px",ft={},Ce={},xt={},bt={};let vt=[],Jt=[];const ln=({open:r,onClose:c,plugin:i})=>{const{sendMessage:n,addListener:s,removeListener:h,getUniqueId:y}=o.useContext(xe),t=o.useRef(y()),[l,j]=o.useState(i.configJson),[F,f]=o.useState(i.schemaJson),[H,V]=o.useState({"ui:submitButtonOptions":{submitText:"Confirm"},"ui:globalOptions":{orderable:!0}}),[M,E]=o.useState("");let p={};o.useEffect(()=>{const k=P=>{P.src==="Matterbridge"&&P.dst==="Frontend"&&(P.id===t.current&&P.method==="/api/select/devices"&&(P.response&&(vt=P.response),P.error&&console.error("ConfigPluginDialog received /api/select/devices error:",P.error)),P.id===t.current&&P.method==="/api/select/entities"&&(P.response&&(Jt=P.response),P.error&&console.error("ConfigPluginDialog received /api/select/entities error:",P.error)))};return s(k),l!==void 0&&F!==void 0&&(Object.keys(F.properties).forEach(P=>{Object.keys(F.properties[P]).forEach(I=>{I.startsWith("ui:")&&(H[P]={},H[P][I]=F.properties[P][I],delete F.properties[P][I])})}),V(H)),i.name!==void 0&&i.configJson!==void 0&&i.schemaJson!==void 0&&(j(i.configJson),f(i.schemaJson),n({id:t.current,sender:"ConfigPlugin",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:i.name}}),n({id:t.current,sender:"ConfigPlugin",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:i.name}})),()=>{h(k)}},[s,l,i,h,F,n,H]);const U=({formData:k})=>{p=k},v=({formData:k})=>{j(k),i.configJson=k,i.restartRequired=!0,n({id:t.current,sender:"ConfigPlugin",method:"/api/savepluginconfig",src:"Frontend",dst:"Matterbridge",params:{pluginName:k.name,formData:k}}),c()};function b(k){const{id:P,label:I,onKeyChange:g,onDropPropertyClick:d,disabled:W,schema:ie,children:se,registry:J,readonly:de,required:me}=k,{templates:oe}=J,{RemoveButton:ve}=oe.ButtonTemplates;if(!(Ao in ie))return e.jsx(X,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:se});const ge=({target:Y})=>g(Y&&Y.value);return e.jsxs(X,{sx:{display:"flex",flexDirection:"row",flexGrow:1,padding:0,margin:0,border:"none"},children:[e.jsx(pe,{id:`${P}-key`,name:`${P}-key`,required:me,disabled:W||de,defaultValue:I,onBlur:de?void 0:ge,type:"text",variant:"outlined",sx:{width:"250px",minWidth:"250px",maxWidth:"250px",marginRight:"20px"}}),e.jsx(X,{sx:{flex:1},children:se}),e.jsx(ve,{disabled:W||de,onClick:d(I)})]})}function D(k){const{children:P,description:I,displayLabel:g,errors:d,help:W,hidden:ie,_id:se,_label:J,registry:de,uiSchema:me}=k,oe=Vo(me),ve=_o("WrapIfAdditionalTemplate",de,oe);return ie?e.jsx("div",{style:{display:"none"},children:P}):e.jsx(X,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:e.jsxs(ve,{...k,children:[g===!0&&I,P,d,W]})})}function O(k){const{description:P}=k;return P?e.jsx(le,{sx:tt,children:P}):null}function N(k){const{required:P,title:I}=k;return I?e.jsx(X,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsxs(le,{sx:et,children:["Title ",I," ",P&&e.jsx("mark",{children:"***"})]})}):null}function u(k){const{help:P,_idSchema:I}=k;return P?e.jsx(X,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsx(le,{sx:nn,children:P})}):null}function R(k){const{errors:P}=k;return P?e.jsxs(X,{sx:{padding:"10px",margin:"10px",border:"1px solid grey"},children:[e.jsx(le,{color:"error",sx:an,children:"Please fix the following errors:"}),e.jsx(it,{children:P.map((I,g)=>e.jsxs(Tr,{children:[e.jsx(K,{children:e.jsx(Wr,{color:"error"})}),e.jsx(re,{primary:I.stack})]},g))})]}):null}function C(k){const{errors:P}=k;return P?e.jsx(X,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:P.map((I,g)=>e.jsxs(le,{color:"error",variant:"body2",sx:{marginLeft:1},children:["This field ",I]},g))}):null}function x(k){const{id:P,name:I,_schema:g,_uiSchema:d,value:W,options:ie,label:se,type:J,placeholder:de,required:me,disabled:oe,readonly:ve,autofocus:ae,onChange:ge,onChangeOverride:Y,onBlur:ue,onFocus:ye,_rawErrors:Ge,_hideError:Q,_registry:ee,_formContext:Te}=k,He=({target:{value:je}})=>ge(je===""?ie.emptyValue:je),Re=({target:je})=>ue(P,je&&je.value),ze=({target:je})=>ye(P,je&&je.value);return e.jsx(X,{sx:{padding:"0px",margin:"0px"},children:e.jsx(pe,{id:P,name:P,label:de&&de!==""?se:void 0,variant:"outlined",placeholder:de&&de!==""?de:se,required:me,disabled:oe||ve,autoFocus:ae,value:W||W===0?W:"",type:J,autoComplete:J==="password"?"current-password":I,onChange:Y||He,onBlur:Re,onFocus:ze,fullWidth:!0})})}function w(k){return console.log("ArrayFieldTitleTemplate:",k),null}function z(k){return console.log("ArrayFieldDescriptionTemplate:",k),null}function ce(k){return console.log("ArrayFieldItemTemplate:",k),null}function be(k){const{canAdd:P,_className:I,_disabled:g,_formContext:d,_formData:W,_idSchema:ie,_items:se,onAddClick:J,_rawErrors:de,_readonly:me,_registry:oe,_required:ve,schema:ae,title:ge,_uiSchema:Y}=k,[ue,ye]=o.useState(!1),[Ge,Q]=o.useState(!1),[ee,Te]=o.useState(!1),[He,Re]=o.useState(""),ze=A=>{Re(A.target.value)},je=()=>{ye(!ue)},Ke=()=>{Q(!Ge)},Ye=()=>{Te(!ee)},Mt=A=>{ye(!1),ae.selectFrom==="serial"?ae.items.default=A.serial:ae.selectFrom==="name"&&(ae.items.default=A.name),J()},kt=A=>{Q(!1),ae.selectEntityFrom==="name"?ae.items.default=A.name:ae.selectEntityFrom==="description"&&(ae.items.default=A.description),J()},It=A=>{Te(!1),ae.selectDeviceEntityFrom==="name"?ae.items.default=A.name:ae.selectDeviceEntityFrom==="description"&&(ae.items.default=A.description),J()};return e.jsxs(X,{sx:{margin:"0px",padding:"5px 10px 5px 10px",border:"1px solid grey"},children:[ge&&e.jsxs(X,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ge&&e.jsx(le,{sx:et,children:ge}),P&&e.jsxs(X,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ae.selectFrom&&e.jsx($,{title:"Add a device from the list",children:e.jsx(B,{onClick:je,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),ae.selectEntityFrom&&e.jsx($,{title:"Add an entity from the list",children:e.jsx(B,{onClick:Ke,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),ae.selectDeviceEntityFrom&&e.jsx($,{title:"Add a device entity from the list",children:e.jsx(B,{onClick:Ye,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),e.jsx($,{title:"Add a new item",children:e.jsx(B,{onClick:J,size:"small",color:"primary",sx:Ee,children:e.jsx(jt,{})})})]})]}),ae.description&&e.jsx(le,{sx:tt,children:ae.description}),k.items.map(A=>e.jsxs(X,{sx:{margin:"2px 0px",padding:"0px",display:"flex",alignItems:"center"},children:[e.jsx(X,{sx:{flexGrow:1,marginRight:"10px"},children:A.children}),e.jsx(B,{disabled:!A.hasMoveUp,onClick:A.onReorderClick(A.index,A.index-1),size:"small",color:"primary",sx:Ee,children:e.jsx(Rt,{})}),e.jsx(B,{disabled:!A.hasMoveDown,onClick:A.onReorderClick(A.index,A.index+1),size:"small",color:"primary",sx:Ee,children:e.jsx(Ht,{})}),e.jsx(B,{onClick:A.onDropIndexClick(A.index),size:"small",color:"primary",sx:Ee,children:e.jsx(St,{})})]},A.index)),e.jsxs(De,{open:ue,onClose:je,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Ne,{children:"Select a device"}),e.jsxs(Pe,{children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(le,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:He,onChange:ze,placeholder:"Enter serial or name"})]}),e.jsx(it,{dense:!0,children:vt.filter(A=>A.serial.toLowerCase().includes(He.toLowerCase())||A.name.toLowerCase().includes(He.toLowerCase())).map((A,ke)=>e.jsxs(ut,{onClick:()=>Mt(A),sx:ft,children:[A.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),A.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),A.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),e.jsx(re,{primary:A.name,secondary:A.serial,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},ke))})]}),e.jsx(Le,{children:e.jsx(ne,{onClick:je,children:"Close"})})]}),e.jsxs(De,{open:Ge,onClose:Ke,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Ne,{children:"Select an entity"}),e.jsxs(Pe,{children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(le,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:He,onChange:ze,placeholder:"Enter name or description"})]}),e.jsx(it,{dense:!0,children:Jt.filter(A=>A.name.toLowerCase().includes(He.toLowerCase())||A.description.toLowerCase().includes(He.toLowerCase())).map((A,ke)=>e.jsxs(ut,{onClick:()=>kt(A),sx:ft,children:[A.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),A.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),A.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),A.icon==="component"&&e.jsx(K,{children:e.jsx(Ot,{style:Ce})}),A.icon==="matter"&&e.jsx(K,{children:e.jsx($t,{style:Ce})}),e.jsx(re,{primary:A.name,secondary:A.description,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},ke))})]}),e.jsx(Le,{children:e.jsx(ne,{onClick:Ke,children:"Close"})})]}),e.jsxs(De,{open:ee,onClose:Ye,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsxs(Ne,{children:["Select an entity for ",ge]}),e.jsx(Pe,{children:e.jsx(it,{dense:!0,children:vt.filter(A=>A.serial===ge||A.name===ge).map(A=>A.entities?.map((ke,Dt)=>e.jsxs(ut,{onClick:()=>It(ke),sx:ft,children:[ke.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),ke.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),ke.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),ke.icon==="component"&&e.jsx(K,{children:e.jsx(Ot,{style:Ce})}),ke.icon==="matter"&&e.jsx(K,{children:e.jsx($t,{style:Ce})}),e.jsx(re,{primary:ke.name,secondary:ke.description,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},Dt)))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:Ye,children:"Close"})})]})]})}function S(k){const{onAddClick:P,schema:I,properties:g,title:d,description:W}=k,[ie,se]=o.useState(!1),[J,de]=o.useState(""),me=Y=>{de(Y.target.value)},oe=()=>{se(!ie)},ve=Y=>{se(!1);let ue="";I.selectFrom==="serial"?ue=Y.serial:I.selectFrom==="name"&&(ue=Y.name),E(ue),P(I)()},ae=()=>{P(I)()},ge=!I.additionalProperties;return!ge&&M!==""&&g.forEach(Y=>{if(Y.name==="newKey"&&Y.content.key==="newKey"&&Y.content.props.name==="newKey"&&Y.content.props.onKeyChange&&M!==""){const ue=M;E(""),Y.content.props.onKeyChange(ue)}}),e.jsxs(X,{sx:{margin:"0px",padding:ge?"10px":"5px 10px 0px 10px",border:ge?"none":"1px solid grey"},children:[I.title&&ge&&e.jsx(X,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(le,{sx:et,children:I.title})}),d&&!ge&&e.jsxs(X,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[e.jsx(le,{sx:et,children:d}),e.jsxs(X,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[I.selectFrom&&e.jsx($,{title:"Add a device from the list",children:e.jsx(B,{onClick:oe,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),e.jsx($,{title:"Add a new item",children:e.jsx(B,{onClick:ae,size:"small",color:"primary",sx:Ee,children:e.jsx(jt,{})})})]})]}),I.description&&e.jsx(X,{sx:{padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(le,{sx:tt,children:I.description})}),g.map(({content:Y,name:ue,hidden:ye})=>!ye&&e.jsxs(X,{sx:{margin:"0px",marginBottom:"10px",padding:["object","array","boolean"].includes(I.properties[ue].type)?"0px":sn,border:["object","array","boolean"].includes(I.properties[ue].type)?"none":"1px solid grey"},children:[!["object","array","boolean"].includes(I.properties[ue].type)&&e.jsx(le,{sx:et,children:ue}),e.jsx(X,{sx:{flexGrow:1,padding:"0px",margin:"0px"},children:Y})]},ue)),e.jsxs(De,{open:ie,onClose:oe,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Ne,{children:"Select a device"}),e.jsxs(Pe,{children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(le,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:J,onChange:me,placeholder:"Enter serial or name"})]}),e.jsx(it,{dense:!0,children:vt.filter(Y=>Y.serial.toLowerCase().includes(J.toLowerCase())||Y.name.toLowerCase().includes(J.toLowerCase())).map((Y,ue)=>e.jsxs(ut,{onClick:()=>ve(Y),sx:ft,children:[Y.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),Y.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),Y.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),e.jsx(re,{primary:Y.name,secondary:Y.serial,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},ue))})]}),e.jsx(Le,{children:e.jsx(ne,{onClick:oe,children:"Close"})})]})]})}function m(k){const{uiSchema:P}=k,{submitText:I,norender:g}=Eo(P);return g?null:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",margin:"10px",padding:"0px",gap:"20px"},children:[e.jsx(ne,{type:"submit",variant:"contained",color:"primary",children:I}),e.jsx(ne,{variant:"contained",color:"primary",onClick:c,children:"Cancel"})]})}function _(k){const{className:P,disabled:I,onClick:g,registry:d,style:W,uiSchema:ie,...se}=k;return e.jsx($,{title:"Remove the item",children:e.jsx(B,{disabled:I,size:"small",color:"primary",onClick:g,children:e.jsx(St,{})})})}function T(k){const{className:P,disabled:I,onClick:g,registry:d,uiSchema:W,...ie}=k;return e.jsx($,{title:"Add an item",children:e.jsx(B,{size:"small",color:"primary",onClick:g,children:e.jsx(jt,{})})})}function Z(k){const{disabled:P,onClick:I,registry:g,style:d,uiSchema:W,...ie}=k;return e.jsx($,{title:"Move up the item",children:e.jsx(B,{size:"small",color:"primary",onClick:I,children:e.jsx(Rt,{})})})}function fe(k){const{disabled:P,onClick:I,registry:g,style:d,uiSchema:W,...ie}=k;return e.jsx($,{title:"Move down the item",children:e.jsx(B,{size:"small",color:"primary",onClick:I,children:e.jsx(Ht,{})})})}function Me(k){const{id:P,name:I,value:g,schema:d,readonly:W,onChange:ie}=k,[se,J]=o.useState(void 0),de=oe=>{J(oe&&oe!==""?oe:void 0)},me=()=>{n({id:t.current,sender:"ConfigPlugin",method:"/api/action",src:"Frontend",dst:"Matterbridge",params:{plugin:i.name,action:I,value:se,formData:p,id:P}}),d.buttonClose===!0?c():d.buttonSave===!0&&v({formData:l})};return d.buttonText&&d.description?e.jsxs(X,{sx:{margin:"0px",padding:"10px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(le,{sx:tt,children:d.description}),e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>me(),children:d.buttonText})]}):d.buttonField&&d.description?e.jsxs(X,{sx:{margin:"0px",padding:"10px",gap:"20px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(le,{sx:tt,children:d.description}),e.jsx(pe,{id:I+"-input",name:I,label:d.textLabel,placeholder:d.textPlaceholder,onChange:oe=>de(oe.target.value),sx:{width:"250px",minWidth:"250px",maxWidth:"250px"}}),e.jsx(ne,{id:I+"-button",variant:"contained",color:"primary",disabled:se===void 0,onClick:()=>me(),children:d.buttonField})]}):e.jsxs(X,{sx:{margin:"0px",padding:"5px 10px",border:"1px solid grey"},children:[I&&e.jsxs(X,{sx:{margin:"0px",padding:"0px",gap:"10px",display:"flex",justifyContent:"flex-start",alignItems:"center"},children:[e.jsx(le,{sx:et,children:I}),e.jsx(Fe,{checked:g,readOnly:W,onChange:()=>ie(!g),sx:{padding:"0px",margin:"0px"}})]}),d.description&&e.jsx(le,{sx:tt,children:d.description})]})}function q({schema:k,id:P,name:I,options:g,label:d,hideLabel:W,required:ie,disabled:se,placeholder:J,readonly:de,value:me,multiple:oe,autofocus:ve,onChange:ae,onBlur:ge,onFocus:Y,errorSchema:ue,rawErrors:ye=[],registry:Ge,uiSchema:Q,hideError:ee,formContext:Te,...He}){const{enumOptions:Re,enumDisabled:ze,emptyValue:je}=g;oe=typeof oe>"u"?!1:!!oe;const Ke=oe?[]:"",Ye=typeof me>"u"||oe&&me.length<1||!oe&&me===Ke,Mt=({target:{value:$e}})=>ae(Pt($e,Re,je)),kt=({target:$e})=>ge(P,Pt($e&&$e.value,Re,je)),It=({target:$e})=>Y(P,Pt($e&&$e.value,Re,je)),A=Oo(me,Re,oe),{InputLabelProps:ke,SelectProps:Dt,autocomplete:pr,...ur}=He,mr=!oe&&k.default===void 0;return e.jsxs(pe,{id:P,name:P,value:!Ye&&typeof A<"u"?A:Ke,required:ie,disabled:se||de,autoFocus:ve,autoComplete:pr,placeholder:J,error:ye.length>0,onChange:Mt,onBlur:kt,onFocus:It,...ur,select:!0,InputLabelProps:{...ke,shrink:!Ye},SelectProps:{...Dt,multiple:oe},"aria-describedby":$o(P),children:[mr&&e.jsx(L,{value:"",children:J}),Array.isArray(Re)&&Re.map(({value:$e,label:gr},Lt)=>{const hr=Array.isArray(ze)&&ze.indexOf($e)!==-1;return e.jsx(L,{value:String(Lt),disabled:hr,children:gr},Lt)})]})}return!r||!F||!l?null:e.jsxs(De,{open:r,onClose:c,maxWidth:"800px",children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h3",{children:"Matterbridge plugin configuration"})]})}),e.jsx(Pe,{style:{padding:"0px",margin:"0px",width:"800px",height:"600px",overflow:"auto"},children:e.jsx(Ho,{schema:F,formData:l,uiSchema:H,validator:Ro,templates:{FieldTemplate:D,BaseInputTemplate:x,TitleFieldTemplate:N,DescriptionFieldTemplate:O,FieldHelpTemplate:u,FieldErrorTemplate:C,ErrorListTemplate:R,WrapIfAdditionalTemplate:b,ArrayFieldTitleTemplate:w,ArrayFieldDescriptionTemplate:z,ArrayFieldItemTemplate:ce,ArrayFieldTemplate:be,ObjectFieldTemplate:S,ButtonTemplates:{SubmitButton:m,RemoveButton:_,AddButton:T,MoveUpButton:Z,MoveDownButton:fe}},widgets:{CheckboxWidget:Me,SelectWidget:q},onChange:U,onSubmit:v})})]})};function dn({data:r,columns:c,columnVisibility:i}){const n=Xt.useMemo(()=>c.filter(j=>i[j.accessor]),[c,i]),{getTableProps:s,getTableBodyProps:h,headerGroups:y,rows:t,prepareRow:l}=Ue.useTable({columns:n,data:r},Ue.useSortBy);return e.jsxs("table",{...s(),style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("thead",{style:{border:"none",borderCollapse:"collapse"},children:y.map(j=>e.jsx("tr",{...j.getHeaderGroupProps(),style:{border:"none",borderCollapse:"collapse"},children:j.headers.map(F=>e.jsx("th",{...F.getHeaderProps(void 0),style:{border:"none",borderCollapse:"collapse",cursor:"default"},children:F.render("Header")}))}))}),e.jsx("tbody",{...h(),style:{border:"none",borderCollapse:"collapse"},children:t.map((j,F)=>(l(j),e.jsx("tr",{className:F%2===0?"table-content-even":"table-content-odd",...j.getRowProps(),style:{border:"none",borderCollapse:"collapse"},children:j.cells.map(f=>e.jsx("td",{...f.getCellProps(),style:{border:"none",borderCollapse:"collapse"},children:f.render("Cell")}))})))})]})}function cn({_storeId:r,setStoreId:c}){const{online:i,sendMessage:n,addListener:s,removeListener:h,getUniqueId:y}=o.useContext(xe),{showConfirmCancelDialog:t}=o.useContext(nt),l=o.useRef(y()),[j,F]=o.useState(null),[f,H]=o.useState(null),[V,M]=o.useState([]),[E,p]=o.useState(!1),[U,v]=o.useState({name:!0,description:!0,version:!0,author:!0,type:!0,registeredDevices:!0,actions:!0,status:!0}),b=d=>{if(d===void 0||d.matter===void 0||!d.matter.fabricInformations&&!d.matter.qrPairingCode&&!d.matter.manualPairingCode)return"red";if(d.matter.commissioned===!1&&d.matter.qrPairingCode&&d.matter.manualPairingCode)return"var(--primary-color)";let W=0,ie=0;for(const se of d.matter.sessionInformations??[])se.fabric&&se.isPeerActive===!0&&W++,se.numberOfActiveSubscriptions>0&&(ie+=se.numberOfActiveSubscriptions);return d.matter.commissioned===!0&&d.matter.fabricInformations&&d.matter.sessionInformations&&(W===0||ie===0)?"var(--secondary-color)":"var(--div-text-color)"},D=[{Header:"Name",accessor:"name",Cell:({row:d})=>e.jsx($,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>m(d.original),children:d.original.name})})},{Header:"Description",accessor:"description",Cell:({row:d})=>e.jsx($,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>m(d.original),children:d.original.description})})},{Header:"Version",accessor:"version",Cell:({row:d})=>e.jsxs(e.Fragment,{children:[d.original.latestVersion!==void 0&&d.original.latestVersion!==d.original.version&&f&&!f.readOnly&&e.jsx($,{title:"New plugin stable version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>w(d.original),children:["Update to v.",d.original.latestVersion]})}),d.original.version.includes("-dev-")&&d.original.devVersion!==void 0&&d.original.devVersion!==d.original.version&&f&&!f.readOnly&&e.jsx($,{title:"New plugin dev version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>z(d.original),children:["Update to new dev v.",d.original.devVersion.split("-dev-")[0]]})}),e.jsx($,{title:"Plugin version",children:e.jsx("span",{children:d.original.version})})]})},{Header:"Author",accessor:"author",Cell:({row:d})=>e.jsx(e.Fragment,{children:d.original.author?d.original.author.replace("https://github.com/",""):"Unknown"})},{Header:"Type",accessor:"type",Cell:({row:d})=>e.jsx(e.Fragment,{children:d.original.type?d.original.type.replace("Platform",""):"Unknown"})},{Header:"Devices",accessor:"registeredDevices"},{Header:"Actions",accessor:"actions",Cell:({row:d})=>e.jsxs("div",{style:{margin:"0px",padding:"0px",gap:"4px",display:"flex",flexDirection:"row"},children:[f&&f.bridgeMode==="childbridge"&&!d.original.error&&d.original.enabled&&e.jsx($,{title:"Shows the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:b(d.original)},onClick:()=>{d.original?.matter?.id&&c(d.original?.matter?.id)},size:"small",children:e.jsx(tr,{})})}),f&&f.bridgeMode==="childbridge"&&!d.original.error&&d.original.enabled&&e.jsx($,{title:"Restart the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0",padding:"0",width:"19px",height:"19px"},onClick:()=>be(d.original),size:"small",children:e.jsx(yt,{})})}),e.jsx($,{title:"Plugin config",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{disabled:d.original.restartRequired===!0,style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>P(d.original),size:"small",children:e.jsx(Je,{})})}),f&&!f.readOnly&&e.jsx($,{title:"Remove the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{R("Remove plugin","Are you sure? This will also remove all devices and configuration from the controller.","remove",d.original)},size:"small",children:e.jsx(St,{})})}),d.original.enabled?e.jsx($,{title:"Disable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{R("Disable plugin","Are you sure? This will also remove all devices and configuration from the controller.","disable",d.original)},size:"small",children:e.jsx(Fr,{})})}):e.jsx(e.Fragment,{}),d.original.enabled?e.jsx(e.Fragment,{}):e.jsx($,{title:"Enable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>S(d.original),size:"small",children:e.jsx(Lr,{})})}),e.jsx($,{title:"Open the plugin help",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>T(d.original),size:"small",children:e.jsx(Hr,{})})}),e.jsx($,{title:"Open the plugin version history",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>Z(d.original),size:"small",children:e.jsx(Rr,{})})}),f&&!f.readOnly&&e.jsx($,{title:"Sponsor the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:"#b6409c"},onClick:()=>_(d.original),size:"small",children:e.jsx(Zt,{})})})]})},{Header:"Status",accessor:"status",Cell:({row:d})=>e.jsx("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",gap:"5px"},children:d.original.error?e.jsx(e.Fragment,{children:e.jsx(Ze,{status:!1,enabledText:"Error",disabledText:"Error",tooltipText:"The plugin is in error state. Check the log!"})}):e.jsx(e.Fragment,{children:d.original.enabled===!1?e.jsx(e.Fragment,{children:e.jsx(Ze,{status:d.original.enabled,enabledText:"Enabled",disabledText:"Disabled",tooltipText:"Whether the plugin is enable or disabled"})}):e.jsx(e.Fragment,{children:d.original.loaded&&d.original.started&&d.original.configured?e.jsx(e.Fragment,{children:e.jsx(Ze,{status:d.original.loaded,enabledText:"Running",tooltipText:"Whether the plugin is running"})}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{status:d.original.loaded,enabledText:"Loaded",tooltipText:"Whether the plugin has been loaded"}),e.jsx(Ze,{status:d.original.started,enabledText:"Started",tooltipText:"Whether the plugin started"}),e.jsx(Ze,{status:d.original.configured,enabledText:"Configured",tooltipText:"Whether the plugin has been configured"})]})})})})}];o.useEffect(()=>{const d=W=>{W.src==="Matterbridge"&&W.dst==="Frontend"&&(he(W)&&W.method==="refresh_required"&&(W.params.changed==="plugins"||W.params.changed==="matter")&&(a&&console.log(`HomePlugins received refresh_required: changed=${W.params.changed} and sending /api/plugins request`),n({id:l.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),he(W)&&W.method==="refresh_required"&&W.params.changed==="settings"&&(a&&console.log(`HomePlugins received refresh_required: changed=${W.params.changed} and sending /api/settings request`),n({id:l.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),Ve(W)&&W.id===l.current&&W.method==="/api/settings"&&(a&&console.log(`HomePlugins (id: ${W.id}) received settings:`,W.response),F(W.response.systemInformation),H(W.response.matterbridgeInformation)),Ve(W)&&W.id===l.current&&W.method==="/api/plugins"&&(a&&console.log(`HomePlugins (id: ${W.id}) received ${W.response.length} plugins:`,W.response),M(W.response)))};return s(d),a&&console.log("HomePlugins added WebSocket listener id:",l.current),()=>{h(d),a&&console.log("HomePlugins removed WebSocket listener")}},[s,h,n]),o.useEffect(()=>{i&&(a&&console.log("HomePlugins sending api requests"),n({id:l.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),n({id:l.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[i,n]),o.useEffect(()=>{const d=localStorage.getItem("homePluginsColumnVisibility");d&&v(JSON.parse(d))},[]);const O=()=>{p(!E)},N=d=>{v(W=>{const ie={...W,[d]:!W[d]};return localStorage.setItem("homePluginsColumnVisibility",JSON.stringify(ie)),ie})},u=o.useRef(null),R=(d,W,ie,se)=>{a&&console.log(`handleActionWithConfirmCancel ${ie} ${se.name}`),u.current=se,t(d,W,ie,C,x)},C=d=>{a&&console.log(`handleConfirm action confirmed ${d} ${u.current?.name}`),d==="remove"&&u.current?ce(u.current):d==="disable"&&u.current&&S(u.current),u.current=null},x=d=>{a&&console.log(`handleCancel action canceled ${d} ${u.current?.name}`),u.current=null},w=d=>{a&&console.log("handleUpdatePlugin plugin:",d.name),n({id:l.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:d.name,restart:!1}})},z=d=>{a&&console.log("handleUpdateDevPlugin plugin:",d.name),n({id:l.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:d.name+"@dev",restart:!1}})},ce=d=>{a&&console.log("handleRemovePlugin plugin:",d.name),n({id:l.current,sender:"HomePlugins",method:"/api/removeplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:d.name}})},be=d=>{a&&console.log("handleRestartPlugin plugin:",d.name),n({id:l.current,sender:"HomePlugins",method:"/api/restartplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:d.name}})},S=d=>{a&&console.log("handleEnableDisablePlugin plugin:",d.name,"enabled:",d.enabled),d.enabled===!0?(d.enabled=!1,n({id:l.current,sender:"HomePlugins",method:"/api/disableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:d.name}})):(d.enabled=!0,n({id:l.current,sender:"HomePlugins",method:"/api/enableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:d.name}}))},m=d=>{a&&console.log(`handleHomepagePlugin plugin: ${d.name} homepage: ${d.homepage}`),d.homepage&&window.open(d.homepage,"_blank")},_=d=>{a&&console.log("handleSponsorPlugin plugin:",d.name,"funding:",d.funding),d.funding&&window.open(d.funding,"_blank")},T=d=>{a&&console.log("handleHelpPlugin plugin:",d.name,"help:",d.help),d.help&&window.open(d.help,"_blank")},Z=d=>{a&&console.log("handleChangelogPlugin plugin:",d.name,"changelog:",d.changelog),d.changelog&&window.open(d.changelog,"_blank")},[fe,Me]=o.useState({}),[q,k]=o.useState(!1),P=d=>{a&&console.log("handleConfigPlugin plugin:",d.name),n({id:l.current,sender:"HomePlugins",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:d.name}}),n({id:l.current,sender:"HomePlugins",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:d.name}}),Me(d),I()},I=()=>{k(!0)},g=()=>{k(!1)};return a&&console.log("HomePlugins rendering..."),i?e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"0 0 auto",overflow:"hidden"},children:[e.jsx(ln,{open:q,onClose:g,plugin:fe}),e.jsxs(De,{open:E,onClose:O,children:[e.jsx(Ne,{children:"Configure Plugins Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:D.map(d=>e.jsx(We,{control:e.jsx(Fe,{disabled:["description","actions","status"].includes(d.accessor),checked:U[d.accessor]??!1,onChange:()=>N(d.accessor)}),label:d.Header},d.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:O,children:"Close"})})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Plugins"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(B,{onClick:O,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})})]}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0px",padding:"0px",gap:"0",overflow:"auto"},children:e.jsx(dn,{data:V,columns:D,columnVisibility:U})})]}):e.jsx(Qe,{})}const pn=o.memo(cn),un=r=>{if(r===void 0||!r.qrPairingCode&&!r.manualPairingCode&&!r.fabricInformations&&!r.sessionInformations)return"red";if(r.commissioned===!1&&r.qrPairingCode&&r.manualPairingCode)return"var(--primary-color)";var c=0,i=0;for(const n of r.sessionInformations??[])n.fabric&&n.isPeerActive===!0&&c++,n.numberOfActiveSubscriptions>0&&(i+=n.numberOfActiveSubscriptions);return r.commissioned===!0&&r.fabricInformations&&r.sessionInformations&&(c===0||i===0)?"var(--secondary-color)":"var(--div-text-color)"},mn=r=>`${r.pluginName}::${r.serial}`;function gn({data:r,columns:c,columnVisibility:i}){const n=o.useMemo(()=>{const f=localStorage.getItem("homeDevicesColumnsSortBy");return f?JSON.parse(f):[{id:"name",desc:!1}]},[c]),s=o.useMemo(()=>c.filter(f=>i[f.accessor]),[i,c]),{getTableProps:h,getTableBodyProps:y,headerGroups:t,rows:l,prepareRow:j,state:{sortBy:F}}=Ue.useTable({columns:s,data:r,getRowId:mn,initialState:{sortBy:n}},Ue.useSortBy);return o.useEffect(()=>{localStorage.setItem("homeDevicesColumnsSortBy",JSON.stringify(F))},[F]),e.jsxs("table",{...h(),style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("thead",{style:{border:"none",borderCollapse:"collapse"},children:t.map(f=>e.jsx("tr",{...f.getHeaderGroupProps(),style:{border:"none",borderCollapse:"collapse"},children:f.headers.map(H=>e.jsxs("th",{...H.getHeaderProps(H.noSort?void 0:H.getSortByToggleProps()),style:{border:"none",borderCollapse:"collapse",cursor:H.noSort?"default":"pointer"},children:[H.render("Header"),!H.noSort&&e.jsx("span",{style:{margin:"0px",marginLeft:"5px",padding:"0px"},children:H.isSorted?H.isSortedDesc?e.jsx(te,{path:Wt,size:"15px"}):e.jsx(te,{path:Ft,size:"15px"}):null})]}))}))}),e.jsx("tbody",{...y(),style:{border:"none",borderCollapse:"collapse"},children:l.map((f,H)=>(j(f),e.jsx("tr",{className:H%2===0?"table-content-even":"table-content-odd",...f.getRowProps(),style:{border:"none",borderCollapse:"collapse"},children:f.cells.map(V=>e.jsx("td",{...V.getCellProps(),style:{border:"none",borderCollapse:"collapse"},children:V.render("Cell")}))})))})]})}function hn({storeId:r,setStoreId:c}){const{online:i,sendMessage:n,addListener:s,removeListener:h,getUniqueId:y}=o.useContext(xe),[t,l]=o.useState(!1),[j,F]=o.useState(!0),[f,H]=o.useState(null),[V,M]=o.useState([]),[E,p]=o.useState([]),[U,v]=o.useState([]),[b,D]=o.useState([]),[O,N]=o.useState(!1),[u,R]=o.useState({pluginName:!0,name:!0,serial:!0,reachable:!0,powerSource:!0,configUrl:!1,actions:!0}),C=o.useRef(y()),x=[{Header:"Plugin",accessor:"pluginName"},{Header:"Name",accessor:"name"},{Header:"Serial",accessor:"serial"},{Header:"Availability",accessor:"reachable",Cell:({row:S})=>S.original.reachable===!0?"Online":S.original.reachable===!1?e.jsx("span",{style:{color:"red"},children:"Offline"}):"",sortType:(S,m)=>{const _=S.original.reachable===!0?1:S.original.reachable===!1?0:-1,T=m.original.reachable===!0?1:m.original.reachable===!1?0:-1;return _-T}},{Header:"Power",accessor:"powerSource",Cell:({row:S})=>S.original.powerSource==="ac"||S.original.powerSource==="dc"?e.jsx(rr,{fontSize:"small",sx:{color:"var(--primary-color)"}}):S.original.powerSource==="ok"?e.jsx(Ct,{fontSize:"small",sx:{color:"green"}}):S.original.powerSource==="warning"?e.jsx(Ct,{fontSize:"small",sx:{color:"yellow"}}):S.original.powerSource==="critical"?e.jsx(Ct,{fontSize:"small",sx:{color:"red"}}):e.jsx("span",{})},{Header:"Url",accessor:"configUrl"},{Header:"Actions",accessor:"actions",noSort:!0,Cell:({row:S})=>e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[S.original.matter!==void 0?e.jsx($,{title:"Show the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{onClick:()=>c(r===S.original.matter.id?f.matterbridgeInformation.bridgeMode==="bridge"?"Matterbridge":null:S.original.matter.id),"aria-label":"Show the QRCode",sx:{margin:0,padding:0,color:un(S.original.matter)},children:e.jsx(tr,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),S.original.configUrl?e.jsx($,{title:"Open the configuration page",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(B,{onClick:()=>window.open(S.original.configUrl,"_blank"),"aria-label":"Open config url",sx:{margin:0,padding:0},children:e.jsx(Je,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),S.original.selected!==void 0?e.jsx($,{title:"Select/unselect the device",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Fe,{checked:S.original.selected,onChange:m=>be(m,S.original),sx:{margin:"0",marginLeft:"8px",padding:"0"},size:"small"})}):e.jsx("div",{style:{width:"20px",height:"20px"}})]})}],w=o.useCallback(S=>{S.selected=void 0;const m=V.find(Z=>Z.name===S.pluginName);if(!m)return console.error(`HomeDevices isSelected: plugin ${S.pluginName} not found for device ${S.deviceName} `),S.selected;const _=m.schemaJson?.properties?.whiteList?.selectFrom;let T=m.configJson?.postfix;return T===""&&(T=void 0),m.hasWhiteList===!0&&m.hasBlackList===!0&&_&&(S.selected=!0,_==="serial"&&m.configJson.whiteList&&m.configJson.whiteList.length>0&&m.configJson.whiteList.includes(T?S.serial.replace("-"+T,""):S.serial)&&(S.selected=!0),_==="serial"&&m.configJson.whiteList&&m.configJson.whiteList.length>0&&!m.configJson.whiteList.includes(T?S.serial.replace("-"+T,""):S.serial)&&(S.selected=!1),_==="serial"&&m.configJson.blackList&&m.configJson.blackList.length>0&&m.configJson.blackList.includes(T?S.serial.replace("-"+T,""):S.serial)&&(S.selected=!1),_==="name"&&m.configJson.whiteList&&m.configJson.whiteList.length>0&&m.configJson.whiteList.includes(S.name)&&(S.selected=!0),_==="name"&&m.configJson.whiteList&&m.configJson.whiteList.length>0&&!m.configJson.whiteList.includes(S.name)&&(S.selected=!1),_==="name"&&m.configJson.blackList&&m.configJson.blackList.length>0&&m.configJson.blackList.includes(S.name)&&(S.selected=!1)),S.selected},[V]);o.useEffect(()=>{const S=m=>{if(m.src==="Matterbridge"&&m.dst==="Frontend"){if(m.method==="refresh_required"&&(console.log(`HomeDevices received refresh_required: changed=${m.params.changed} and sending /api/plugins request`),n({id:C.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),m.method==="restart_required"&&(a&&console.log("HomeDevices received restart_required"),l(!0)),m.method==="restart_not_required"&&(a&&console.log("HomeDevices received restart_not_required"),l(!1)),m.method==="state_update"&&m.params.plugin&&m.params.serialNumber&&m.params.cluster.includes("BasicInformationServer")&&m.params.attribute==="reachable"&&(console.log(`HomeDevices updating device reachability for plugin ${m.params.plugin} serial ${m.params.serialNumber} value ${m.params.value}`),p(_=>_.map(T=>T.pluginName===m.params.plugin&&T.serial===m.params.serialNumber?{...T,reachable:m.params.value}:T))),m.id===C.current&&m.method==="/api/settings"&&(a&&console.log(`HomeDevices (id: ${m.id}) received settings:`,m.response),H(m.response),l(m.response.matterbridgeInformation.restartRequired||m.response.matterbridgeInformation.fixedRestartRequired)),m.id===C.current&&m.method==="/api/plugins"&&(a&&console.log(`HomeDevices (id: ${m.id}) received ${m.response?.length} plugins:`,m.response),m.response)){let _=!0;for(const T of m.response)T.enabled===!0&&(T.loaded!==!0||T.started!==!0||T.error===!0)&&(_=!1);if(!_)return;a&&console.log("HomeDevices reset plugins, devices and selectDevices"),F(!1),M(m.response),p([]),v([]),n({id:C.current,sender:"HomeDevices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}),a&&console.log("HomeDevices sent /api/devices");for(const T of m.response)T.enabled===!0&&T.loaded===!0&&T.started===!0&&T.error!==!0&&(n({id:C.current,sender:"HomeDevices",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:T.name}}),a&&console.log(`HomeDevices sent /api/select/devices for plugin: ${T.name}`))}if(m.id===C.current&&m.method==="/api/devices"&&(a&&console.log(`HomeDevices (id: ${m.id}) received ${m.response?.length} devices:`,m.response),m.response)){for(const _ of m.response)_.selected=w(_);p(m.response)}m.id===C.current&&m.method==="/api/select/devices"&&(a&&console.log(`HomeDevices (id: ${m.id}) received ${m.response?.length} selectDevices for plugin ${m.response&&m.response.length>0?m.response[0].pluginName:"no select devices"}:`,m.response),m.response&&m.response.length>0&&v(_=>{const T=_.filter(fe=>fe.pluginName!==m.response[0].pluginName),Z=m.response.map(fe=>({...fe,selected:w(fe)}));return[...T,...Z]}))}};return s(S),a&&console.log(`HomeDevices added WebSocket listener id ${C.current}`),()=>{h(S),a&&console.log("HomeDevices removed WebSocket listener")}},[V,s,h,n,w]),o.useEffect(()=>{if(E.length===0&&U.length===0){D([]);return}console.log(`HomeDevices mixing devices (${E.length}) and selectDevices (${U.length})`);const S=[];for(const m of E)S.push(m);for(const m of U)E.find(_=>_.pluginName===m.pluginName&&_.serial.includes(m.serial))||S.push(m);S.length>0&&(D(S),console.log(`HomeDevices mixed ${S.length} devices and selectDevices`))},[V,E,U,D]),o.useEffect(()=>{i&&(a&&console.log("HomeDevices sending /api/settings and /api/plugins requests"),n({id:C.current,sender:"HomeDevices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),n({id:C.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[i,n]),o.useEffect(()=>{const S=localStorage.getItem("homeDevicesColumnVisibility");if(S){const m=JSON.parse(S);m.powerSource===void 0&&(m.powerSource=!0),R(m),a&&console.log("HomeDevices loaded column visibility from localStorage")}},[]);const z=S=>{R(m=>{const _={...m,[S]:!m[S]};return localStorage.setItem("homeDevicesColumnVisibility",JSON.stringify(_)),a&&console.log("HomeDevices saved column visibility to localStorage",JSON.stringify(_),_),_})},ce=()=>{N(!O)},be=(S,m)=>{console.log(`handleCheckboxChange: checkbox changed to ${S.target.checked} for device ${m.name} serial ${m.serial}`),D(_=>{const T=_.findIndex(fe=>fe.pluginName===m.pluginName&&fe.serial===m.serial);if(T<0)return console.error(`handleCheckboxChange: device not found ${m.name} serial ${m.serial} id ${m.id}`),_;const Z=[..._];return Z[T]={...Z[T],selected:S.target.checked},Z}),S.target.checked?n({id:C.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"selectdevice",plugin:m.pluginName,serial:m.serial,name:m.name}}):n({id:C.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"unselectdevice",plugin:m.pluginName,serial:m.serial,name:m.name}})};return a&&console.log("HomeDevices rendering..."),i?e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",overflow:"hidden"},children:[e.jsxs(De,{open:O,onClose:ce,children:[e.jsx(Ne,{children:"Configure Devices Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:x.map(S=>e.jsx(We,{control:e.jsx(Fe,{disabled:["name","actions"].includes(S.accessor),checked:u[S.accessor],onChange:()=>z(S.accessor)}),label:S.Header},S.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:ce,children:"Close"})})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Devices"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(B,{onClick:ce,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})})]}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0px",padding:"0px",gap:"0",overflow:"auto"},children:e.jsx(gn,{data:b,columns:x,columnVisibility:u})}),e.jsxs("div",{className:"MbfWindowFooter",style:{borderTop:"1px solid var(--table-border-color)",justifyContent:"space-between"},children:[j&&e.jsx("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",fontSize:"14px",color:"var(--secondary-color)"},children:"Waiting for the plugins to fully load..."}),!j&&e.jsxs("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",fontSize:"14px",color:"var(--secondary-color)"},children:["Registered devices: ",E.length.toString(),"/",b.length.toString()]}),t&&e.jsx("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",fontSize:"14px",color:"var(--secondary-color)"},children:"Restart required"})]})]}):e.jsx(Qe,{})}const fn=o.memo(hn);function xn(){const[r,c]=o.useState(null),[i,n]=o.useState(null),[s,h]=o.useState([]),[y]=o.useState(localStorage.getItem("homePagePlugins")!=="false"),[t,l]=o.useState(localStorage.getItem("homePageMode")??"devices"),[j,F]=o.useState(""),[f,H]=o.useState(!1),[V,M]=o.useState(!1),[E,p]=o.useState(null),{addListener:U,removeListener:v,online:b,sendMessage:D,logFilterLevel:O,logFilterSearch:N,autoScroll:u,getUniqueId:R}=o.useContext(xe),C=o.useRef(R());return o.useEffect(()=>{const x=w=>{w.src==="Matterbridge"&&w.dst==="Frontend"&&(he(w)&&w.method==="refresh_required"&&w.params.changed==="settings"&&(a&&console.log(`Home received refresh_required: changed=${w.params.changed} and sending /api/settings request`),D({id:C.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),Ve(w)&&w.method==="/api/settings"&&w.id===C.current&&(a&&console.log("Home received settings:",w.response),c(w.response.systemInformation),n(w.response.matterbridgeInformation),w.response.matterbridgeInformation.bridgeMode==="bridge"&&(E||p("Matterbridge")),w.response.matterbridgeInformation.bridgeMode==="childbridge"&&s.length>0&&E===null&&!E&&s.length>0&&s[0].matter?.id&&p(s[0].matter.id),w.response.matterbridgeInformation.matterbridgeVersion&&F(`https://github.com/Luligu/matterbridge/blob/${w.response.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?"dev":"main"}/CHANGELOG.md`),localStorage.getItem("frontendVersion")===null&&w.response.matterbridgeInformation.frontendVersion?localStorage.setItem("frontendVersion",w.response.matterbridgeInformation.frontendVersion):w.response.matterbridgeInformation.frontendVersion!==localStorage.getItem("frontendVersion")&&w.response.matterbridgeInformation.frontendVersion&&(localStorage.setItem("frontendVersion",w.response.matterbridgeInformation.frontendVersion),M(!0)),localStorage.getItem("matterbridgeVersion")===null?localStorage.setItem("matterbridgeVersion",w.response.matterbridgeInformation.matterbridgeVersion):w.response.matterbridgeInformation.matterbridgeVersion!==localStorage.getItem("matterbridgeVersion")&&(localStorage.setItem("matterbridgeVersion",w.response.matterbridgeInformation.matterbridgeVersion),H(!0)),w.response.matterbridgeInformation.shellyBoard&&(localStorage.getItem("homePageMode")||(localStorage.setItem("homePageMode","devices"),l("devices")))),Ve(w)&&w.method==="/api/plugins"&&w.id===C.current&&(a&&console.log(`Home received plugins (${i?.bridgeMode}):`,w.response),h(w.response),i?.bridgeMode==="childbridge"&&w.response.length>0&&!E&&w.response.length>0&&w.response[0].matter?.id&&p(w.response[0].matter.id)))};return U(x),a&&console.log(`Home added WebSocket listener id ${C.current}`),()=>{v(x),a&&console.log("Home removed WebSocket listener")}},[U,v,D,i,s,E]),o.useEffect(()=>{b&&(a&&console.log("Home received online"),D({id:C.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),D({id:C.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[b,D]),a&&console.log("Home rendering..."),!b||!r||!i?e.jsx(Qe,{}):e.jsxs("div",{className:"MbfPageDiv",style:{flexDirection:"row"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"302px",minWidth:"302px",gap:"20px"},children:[e.jsx(tn,{id:E}),e.jsx(Xo,{systemInfo:r,compact:!0})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",gap:"20px"},children:[V&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Frontend Update"})}),e.jsxs("div",{className:"MbfWindowBody",style:{flexDirection:"row",justifyContent:"space-between"},children:[e.jsx("h4",{style:{margin:0},children:"The frontend has been updated. You are viewing an outdated web UI. Please refresh the page now."}),e.jsx("div",{children:e.jsx(ne,{onClick:()=>window.location.reload(),endIcon:e.jsx(Or,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Refresh"})})]})]}),f&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge Update"})}),e.jsxs("div",{className:"MbfWindowBody",style:{flexDirection:"row",justifyContent:"space-between"},children:[e.jsx("h4",{style:{margin:0},children:"Matterbridge has been updated."}),e.jsxs("div",{children:[e.jsx(ne,{onClick:()=>window.open(j,"_blank"),endIcon:e.jsx(er,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Changelog"}),e.jsx(ne,{onClick:()=>window.location.reload(),endIcon:e.jsx($r,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Close"})]})]})]}),y&&!i.readOnly&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Install plugins"})}),e.jsx(on,{})]}),y&&e.jsx(pn,{storeId:E,setStoreId:p}),t==="devices"&&e.jsx(fn,{storeId:E,setStoreId:p}),t==="logs"&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"1 1 auto",width:"100%",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:"Logs"}),e.jsx("div",{className:"MbfWindowHeaderText",style:{display:"flex",justifyContent:"space-between"},children:e.jsxs("span",{style:{fontWeight:"normal",fontSize:"12px",marginTop:"2px"},children:['Filter: logger level "',O,'" and search "',N,'" Scroll: ',u?"auto":"manual"]})})]}),e.jsx("div",{style:{flex:"1 1 auto",margin:"0px",padding:"10px",overflow:"auto"},children:e.jsx(ar,{})})]})]})]})}const bn=o.memo(xn),Qt={display:"flex",gap:"2px",justifyContent:"space-evenly",width:"100%",height:"40px"},vn={margin:"0",padding:"0",fontSize:"36px",fontWeight:"medium",color:"var(--primary-color)"},yn={margin:"0",padding:"0",fontSize:"20px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},Gt={margin:"0",padding:"0",paddingBottom:"2px",fontSize:"16px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},jn={display:"flex",gap:"2px",justifyContent:"center",width:"100%",height:"18px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},Cn={margin:"0",padding:"0",fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)"},Sn={display:"flex",justifyContent:"center",width:"100%",height:"52px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},wn={margin:"0",padding:"0",fontSize:"14px",fontWeight:"bold",color:"var(--div-text-color)"},Mn={display:"flex",gap:"4px",justifyContent:"center",width:"100%",height:"15px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},Tt={margin:"0",padding:"0px 4px",borderRadius:"5px",textAlign:"center",fontSize:"12px",fontWeight:"normal",color:"var(--secondary-color)"},kn=[256,257,268,269],In=[266,267],Dn=[259,260,261,271,272],Nn=[256,257,268,269,266,267,259,260,261];function G({icon:r,iconColor:c,cluster:i,value:n,unit:s,prefix:h}){return a&&console.log(`Render cluster "${i.clusterName}.${i.attributeName}" value(${typeof n}-${isNaN(n)}) "${n}" unit "${s}"`),h=h??!1,e.jsxs(X,{sx:Qt,children:[r&&o.cloneElement(r,{key:`${i.clusterId}-${i.attributeId}-icon`,sx:{...vn,color:c??"var(--primary-color)"}}),e.jsxs(X,{sx:{...Qt,gap:"4px",alignContent:"center",alignItems:"end",justifyContent:"center"},children:[s&&h===!0&&e.jsx(le,{sx:Gt,children:s},`${i.clusterId}-${i.attributeId}-unit`),e.jsx(le,{sx:yn,children:n==null||typeof n=="number"&&isNaN(n)||n==="NaN"?"---":n},`${i.clusterId}-${i.attributeId}-value`),s&&h===!1&&e.jsx(le,{sx:Gt,children:s},`${i.clusterId}-${i.attributeId}-unit`)]},`${i.clusterId}-${i.attributeId}-valueunitbox`)]},`${i.clusterId}-${i.attributeId}-box`)}function Pn({device:r,endpoint:c,id:i,deviceType:n,clusters:s}){const h=["Unknown","Good","Fair","Moderate","Poor","VeryPoor","Ext.Poor"];let y="";return a&&console.log(`Device "${r.name}" endpoint "${c}" id "${i}" deviceType "0x${n.toString(16).padStart(4,"0")}" clusters (${s?.length}):`,s),n===17&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batVoltage").map(t=>y=`${t.attributeLocalValue} mV`),Nn.includes(n)&&s.filter(t=>t.clusterName==="LevelControl"&&t.attributeName==="currentLevel").map(t=>y=`Level ${t.attributeValue}`),n===514&&s.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>y=`Position ${t.attributeValue/100}%`),n===769&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedHeatingSetpoint").map(t=>y=`Heat ${t.attributeValue/100}°C `),n===769&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedCoolingSetpoint").map(t=>y=y+`Cool ${t.attributeValue/100}°C`),n===118&&s.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>y=`${t.attributeLocalValue===0?"No CO detected":"CO alarm!"}`),n===1296&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="voltage").map(t=>y=`${t.attributeLocalValue/1e3} V, `),n===1296&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activeCurrent").map(t=>y=y+`${t.attributeLocalValue/1e3} A, `),n===1296&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activePower").map(t=>y=y+`${t.attributeLocalValue/1e3} W`),e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0px",padding:"5px",width:"150px",height:"150px",borderColor:"var(--div-bg-color)",borderRadius:"5px",justifyContent:"space-between"},children:[n===19&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:t.attributeLocalValue===!0?e.jsx(at,{}):e.jsx(Er,{}),iconColor:t.attributeLocalValue===!0?"green":"red",cluster:t,value:t.attributeLocalValue===!0?"Online":"Offline"})),n===17&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batPercentRemaining").map(t=>e.jsx(G,{icon:e.jsx(Ct,{}),cluster:t,value:t.attributeValue/2,unit:"%"})),n===17&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="wiredCurrentType").map(t=>e.jsx(G,{icon:e.jsx(rr,{}),cluster:t,value:t.attributeLocalValue===0?"AC":"DC"})),n===1293&&s.filter(t=>t.clusterName==="DeviceEnergyManagement"&&t.attributeName==="esaState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:fo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Offline":"Online"})),kn.includes(n)&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(Vr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),In.includes(n)&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(te,{path:xo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),Dn.includes(n)&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(te,{path:bo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),n===115&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:vo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===124&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:yo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===117&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:jo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===123&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(Et,{}),cluster:t,value:"Oven"})),n===112&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(_r,{}),cluster:t,value:"Fridge"})),n===113&&s.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===121&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(Et,{}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===122&&s.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="fanMode").map(t=>e.jsx(G,{icon:e.jsx(te,{path:So,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===120&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(te,{path:zt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Cooktop"})),n===119&&s.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(G,{icon:e.jsx(te,{path:zt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===116&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(te,{path:wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Robot"})),n===514&&s.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>e.jsx(G,{icon:e.jsx(Ar,{}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),n===769&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),n===10&&s.filter(t=>t.clusterName==="DoorLock"&&t.attributeName==="lockState").map(t=>e.jsx(G,{icon:t.attributeValue==="1"?e.jsx(Ur,{}):e.jsx(zr,{}),cluster:t,value:t.attributeValue==="1"?"Locked":"Unlocked"})),n===43&&s.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(G,{icon:e.jsx(qr,{}),cluster:t,value:t.attributeValue,unit:"%"})),n===15&&s.filter(t=>t.clusterName==="Switch"&&t.attributeName==="currentPosition").map(t=>e.jsx(G,{icon:e.jsx(te,{path:ko,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeValue,unit:"pos",prefix:!0})),n===39&&s.filter(t=>t.clusterName==="ModeSelect"&&t.attributeName==="currentMode").map(t=>e.jsx(G,{icon:e.jsx(Br,{}),cluster:t,value:t.attributeValue,unit:"mode",prefix:!0})),n===771&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(Jr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),n===45&&s.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(G,{icon:e.jsx(Vt,{}),cluster:t,value:t.attributeValue,unit:"%"})),n===114&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(G,{icon:e.jsx(Vt,{}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),n===67&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:e.jsx(Qr,{}),cluster:t,value:t.attributeLocalValue===!0?"Leak":"No leak"})),n===65&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:e.jsx(Gr,{}),cluster:t,value:t.attributeLocalValue===!0?"Freeze":"No freeze"})),n===68&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:e.jsx(Kr,{}),cluster:t,value:t.attributeLocalValue===!0?"Rain":"No rain"})),n===1292&&s.filter(t=>t.clusterName==="EnergyEvse"&&t.attributeName==="state").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Io,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Free":"In use"})),n===1295&&s.filter(t=>t.clusterName==="WaterHeaterManagement"&&t.attributeName==="tankPercentage").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Do,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Tank "+(t.attributeLocalValue??0)+"%"})),n===777&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(G,{icon:e.jsx(te,{path:No,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"HeatPump"})),n===23&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Po,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Solar"})),n===24&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="featureMap").map(t=>e.jsx(G,{icon:e.jsx(te,{path:To,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Inverter"})),n===118&&s.find(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="featureMap"&&t.attributeLocalValue.smokeAlarm===!0)&&s.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="smokeState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:qt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No smoke":"Smoke!"})),n===118&&s.find(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="featureMap"&&t.attributeLocalValue.smokeAlarm===!1)&&s.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:qt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No Co":"Co!"})),n===66&&s.filter(t=>t.clusterName==="ValveConfigurationAndControl"&&t.attributeName==="currentState").map(t=>e.jsx(G,{icon:e.jsx(Yr,{}),cluster:t,value:t.attributeLocalValue===0?"Closed":"Opened"})),n===44&&s.filter(t=>t.clusterName==="AirQuality"&&t.attributeName==="airQuality").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:h[t.attributeLocalValue??0]})),n===770&&s.filter(t=>t.clusterName==="TemperatureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(Xr,{}),cluster:t,value:t.attributeLocalValue/100,unit:"°C"})),n===775&&s.filter(t=>t.clusterName==="RelativeHumidityMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Fo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),n===774&&s.filter(t=>t.clusterName==="FlowMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(Zr,{}),cluster:t,value:t.attributeLocalValue,unit:"l/h"})),n===773&&s.filter(t=>t.clusterName==="PressureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(eo,{}),cluster:t,value:t.attributeLocalValue,unit:"hPa"})),n===21&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:t.attributeValue==="true"?e.jsx(to,{}):e.jsx(ro,{}),cluster:t,value:t.attributeValue==="true"?"Closed":"Opened"})),n===263&&s.filter(t=>t.clusterName==="OccupancySensing"&&t.attributeName==="occupancy").map(t=>e.jsx(G,{icon:t.attributeValue==="{ occupied: true }"?e.jsx(oo,{}):e.jsx(no,{}),cluster:t,value:t.attributeValue==="{ occupied: true }"?"Occupied":"Unocc."})),n===262&&s.filter(t=>t.clusterName==="IlluminanceMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(io,{}),cluster:t,value:Math.round(Math.pow(10,t.attributeValue/1e4)),unit:"lx"})),n===1296&&s.filter(t=>t.clusterName==="ElectricalEnergyMeasurement"&&t.attributeName==="cumulativeEnergyImported").map(t=>e.jsx(G,{icon:e.jsx(ao,{}),cluster:t,value:Math.round(t.attributeLocalValue?.energy/1e6),unit:"kwh"})),e.jsx(X,{sx:jn,children:e.jsx(le,{sx:Cn,children:y})}),e.jsx(X,{sx:Sn,children:e.jsx(le,{sx:wn,children:r.name})}),e.jsxs(X,{sx:Mn,children:[a&&e.jsx(le,{sx:Tt,children:c}),e.jsx(le,{sx:Tt,children:i}),a&&e.jsxs(le,{sx:Tt,children:["0x",n.toString(16).padStart(4,"0")]})]})]})}function Tn({filter:r}){const{online:c,sendMessage:i,addListener:n,removeListener:s,getUniqueId:h}=o.useContext(xe),[y,t]=o.useState({}),[l,j]=o.useState([]),[F,f]=o.useState([]),[H,V]=o.useState({}),[M,E]=o.useState({}),[p,U]=o.useState({}),[v,b]=o.useState(F),D=o.useRef(h());return o.useEffect(()=>{const O=N=>{if(N.src==="Matterbridge"&&N.dst==="Frontend"){if(N.method==="refresh_required"&&(a&&console.log(`DevicesIcons received refresh_required: changed=${N.params.changed} and sending api requests`),i({id:D.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:D.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:D.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),N.method==="/api/settings"&&N.response&&(a&&console.log("DevicesIcons received settings:",N.response),t(N.response)),N.method==="/api/plugins"&&N.response&&(a&&console.log("DevicesIcons received plugins:",N.response),j(N.response)),N.method==="/api/devices"&&N.response){a&&console.log(`DevicesIcons received ${N.response.length} devices:`,N.response),f(N.response);for(let u of N.response)a&&console.log("DevicesIcons sending /api/clusters"),i({id:D.current,sender:"Icons",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:u.pluginName,endpoint:u.endpoint}})}if(N.method==="/api/clusters"&&N.response){if(console.log(`DevicesIcons received for device "${N.response.deviceName}" serial "${N.response.serialNumber}" deviceType ${N.response.deviceTypes.join(" ")} clusters (${N.response.length}):`,N.response),N.response.length===0)return;const u=N.response.serialNumber;H[u]=[],M[u]=N.response.deviceTypes,p[u]=[];for(let R of N.response.clusters)H[u].find(C=>C.endpoint===R.endpoint)||H[u].push({endpoint:R.endpoint,id:R.id,deviceTypes:R.deviceTypes}),!["FixedLabel","Descriptor","Identify","Groups","PowerTopology"].includes(R.clusterName)&&p[u].push(R);V({...H}),E({...M}),U({...p}),a&&console.log(`DevicesIcons endpoints for "${u}":`,H[u]),a&&console.log(`DevicesIcons deviceTypes for "${u}":`,M[u]),a&&console.log(`DevicesIcons clusters for "${u}":`,p[u])}}};return n(O),a&&console.log("DevicesIcons useEffect webSocket mounted"),()=>{s(O),a&&console.log("DevicesIcons useEffect webSocket unmounted")}},[n,s,i]),o.useEffect(()=>(a&&console.log("DevicesIcons useEffect online mounting"),c&&(a&&console.log("DevicesIcons useEffect online sending api requests"),i({id:D.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:D.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:D.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),a&&console.log("DevicesIcons useEffect online mounted"),()=>{a&&console.log("DevicesIcons useEffect online unmounted")}),[c,i]),o.useEffect(()=>{if(r===""){b(F);return}const O=F.filter(N=>N.name.toLowerCase().includes(r)||N.serial.toLowerCase().includes(r));b(O)},[F,r]),a&&console.log("DevicesIcons rendering..."),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"auto"},children:v.map(O=>H[O.serial]&&H[O.serial].map(N=>N.deviceTypes.map(u=>e.jsx(Pn,{device:O,endpoint:N.endpoint,id:N.id,deviceType:u,clusters:p[O.serial].filter(R=>R.endpoint===N.endpoint)}))))})}const Wn=o.memo(Tn),sr=[{Header:"Plugin name",accessor:"pluginName"},{Header:"Device type",accessor:"type"},{Header:"Endpoint",accessor:"endpoint"},{Header:"Name",accessor:"name"},{Header:"Serial number",accessor:"serial"},{Header:"Unique ID",accessor:"uniqueId"},{Header:"Url",accessor:"configUrl"},{Header:"Config",accessor:"configButton",noSort:!0,Cell:({row:r})=>r.original.configUrl?e.jsx(B,{onClick:()=>window.open(r.original.configUrl,"_blank"),"aria-label":"Open Config",sx:{margin:0,padding:0},children:e.jsx(Je,{fontSize:"small"})}):null},{Header:"Cluster",accessor:"cluster"}],lr=[{Header:"Endpoint",accessor:"endpoint"},{Header:"Id",accessor:"id"},{Header:"Device Types",accessor:"deviceTypes",Cell:({value:r})=>Array.isArray(r)?r.map(c=>`0x${c.toString(16).padStart(4,"0")}`).join(", "):r},{Header:"Cluster Name",accessor:"clusterName"},{Header:"Cluster ID",accessor:"clusterId"},{Header:"Attribute Name",accessor:"attributeName"},{Header:"Attribute ID",accessor:"attributeId"},{Header:"Attribute Value",accessor:"attributeValue",Cell:({value:r})=>e.jsx($,{title:r,componentsProps:{tooltip:{sx:{fontSize:"14px",fontWeight:"normal",color:"#ffffff",backgroundColor:"var(--primary-color)"}}},children:e.jsx("div",{style:{maxWidth:"500px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r})})}],Fn=r=>`${r.pluginName}::${r.uniqueId}`,Ln=r=>`${r.endpoint}::${r.clusterName}::${r.attributeName}`;function Hn({data:r,columnVisibility:c,setPlugin:i,setEndpoint:n,setDeviceName:s}){const[h,y]=o.useState(null),t=o.useMemo(()=>sr.filter(M=>c[M.accessor]),[c]),{getTableProps:l,getTableBodyProps:j,headerGroups:F,rows:f,prepareRow:H}=Ue.useTable({columns:t,data:r,getRowId:Fn},Ue.useSortBy),V=M=>{if(M.id===h){y(null),i(null),n(null),s(null),a&&console.log("Device unclicked:",M.id,"selectedDeviceIndex:",h);return}y(M.id),i(M.original.pluginName),n(M.original.endpoint),s(M.original.name),a&&console.log("Device clicked:",M.id,"selectedDeviceIndex:",h,"pluginName:",M.original.pluginName,"endpoint:",M.original.endpoint)};return e.jsxs("table",{...l(),style:{margin:"-1px",border:"1px solid var(--table-border-color)"},children:[e.jsx("thead",{children:F.map(M=>e.jsx("tr",{...M.getHeaderGroupProps(),children:M.headers.map(E=>e.jsxs("th",{...E.getHeaderProps(E.noSort?void 0:E.getSortByToggleProps()),children:[E.render("Header"),!E.noSort&&e.jsx("span",{style:{margin:"0px",marginLeft:"5px",padding:"0px"},children:E.isSorted?E.isSortedDesc?e.jsx(te,{path:Wt,size:"15px"}):e.jsx(te,{path:Ft,size:"15px"}):null})]}))}))}),e.jsx("tbody",{...j(),children:f.map((M,E)=>(H(M),e.jsx("tr",{className:E%2===0?"table-content-even":"table-content-odd",...M.getRowProps(),onClick:()=>V(M),style:{backgroundColor:h===M.id?"var(--table-selected-bg-color)":"",cursor:"pointer"},children:M.cells.map(p=>e.jsx("td",{...p.getCellProps(),children:p.render("Cell")}))})))})]})}function Rn({data:r,columnVisibility:c}){const i=o.useMemo(()=>lr.filter(l=>c[l.accessor]),[c]),{getTableProps:n,getTableBodyProps:s,headerGroups:h,rows:y,prepareRow:t}=Ue.useTable({columns:i,data:r,getRowId:Ln},Ue.useSortBy);return e.jsxs("table",{...n(),style:{margin:"-1px"},children:[e.jsx("thead",{children:h.map(l=>e.jsx("tr",{...l.getHeaderGroupProps(),children:l.headers.map(j=>e.jsx("th",{...j.getHeaderProps(),children:j.render("Header")}))}))}),e.jsx("tbody",{...s(),children:y.map((l,j)=>(t(l),e.jsx("tr",{className:j%2===0?"table-content-even":"table-content-odd",...l.getRowProps(),children:l.cells.map(F=>e.jsx("td",{...F.getCellProps(),children:F.render("Cell")}))})))})]})}function On(){const{online:r,sendMessage:c,addListener:i,removeListener:n,getUniqueId:s}=o.useContext(xe),[h,y]=o.useState([]),[t,l]=o.useState([]),[j,F]=o.useState(null),[f,H]=o.useState(null),[V,M]=o.useState(null),[E,p]=o.useState(0),[U,v]=o.useState(!1),[b,D]=o.useState({pluginName:!0,type:!0,endpoint:!0,name:!0,serial:!0,uniqueId:!1,configUrl:!1,configButton:!0,cluster:!0}),[O,N]=o.useState(!1),[u,R]=o.useState({endpoint:!0,id:!0,deviceTypes:!0,clusterName:!0,clusterId:!0,attributeName:!0,attributeId:!0,attributeValue:!0}),[C,x]=o.useState(""),[w,z]=o.useState(h),[ce,be]=o.useState("icon"),S=o.useRef(s());o.useEffect(()=>{const q=k=>{if(a&&console.log("Devices received WebSocket Message:",k),k.src==="Matterbridge"&&k.dst==="Frontend"&&(k.method==="refresh_required"&&k.params.changed==="devices"&&(a&&console.log(`Devices received refresh_required: changed=${k.params.changed} and sending /api/devices request`),c({id:S.current,sender:"Devices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),k.method==="/api/devices"&&(a&&console.log(`Devices received ${k.response.length} devices:`,k.response),y(k.response)),k.method==="/api/clusters")){console.log(`Devices received ${k.response.length} clusters:`,k.response),l(k.response.clusters);const P={};for(const I of k.response.clusters)a&&console.log("Cluster:",I.endpoint),P[I.endpoint]?P[I.endpoint]++:P[I.endpoint]=1;p(Object.keys(P).length)}};return i(q),a&&console.log("Devices added WebSocket listener"),()=>{n(q),a&&console.log("Devices removed WebSocket listener")}},[i,n,c]),o.useEffect(()=>{r&&(a&&console.log("Devices sending api requests"),c({id:S.current,sender:"Devices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:S.current,sender:"Devices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:S.current,sender:"Devices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}))},[r,c]),o.useEffect(()=>{j&&f&&(a&&console.log("Devices sending /api/clusters"),c({id:S.current,sender:"Devices",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:j,endpoint:f}}))},[j,f,c]);const m=()=>{v(!U)},_=q=>{D(k=>{const P={...k,[q]:!k[q]};return localStorage.setItem("devicesColumnVisibility",JSON.stringify(P)),P})};o.useEffect(()=>{const q=localStorage.getItem("devicesColumnVisibility");q&&D(JSON.parse(q))},[]);const T=()=>{N(!O)},Z=q=>{R(k=>{const P={...k,[q]:!k[q]};return localStorage.setItem("clustersColumnVisibility",JSON.stringify(P)),P})};o.useEffect(()=>{const q=localStorage.getItem("clustersColumnVisibility");q&&R(JSON.parse(q))},[]);const fe=q=>{x(q.target.value.toLowerCase()),localStorage.setItem("devicesFilter",q.target.value.toLowerCase())},Me=q=>{be(q),localStorage.setItem("devicesViewMode",q)};return o.useEffect(()=>{if(C===""){z(h);return}const q=h.filter(k=>k.name.toLowerCase().includes(C)||k.serial.toLowerCase().includes(C));z(q)},[h,C]),o.useEffect(()=>{const q=localStorage.getItem("devicesFilter");q&&x(q)},[]),o.useEffect(()=>{const q=localStorage.getItem("devicesViewMode");q&&be(q)},[]),a&&console.log("Devices rendering..."),r?e.jsxs("div",{className:"MbfPageDiv",children:[e.jsxs("div",{className:"MbfWindowBodyRow",style:{justifyContent:"space-between",padding:0,gap:"20px",width:"100%",height:"45px",minHeight:"45px",maxHeight:"45px"},children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(le,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{variant:"outlined",value:C,onChange:fe,placeholder:"Enter the device name or serial number",sx:{width:"320px"},InputProps:{style:{backgroundColor:"var(--main-bg-color)"}}})]}),e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(le,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"View mode:"}),e.jsx(B,{onClick:()=>Me("table"),"aria-label":"Table View",disabled:ce==="table",children:e.jsx($,{title:"Table View",children:e.jsx(so,{style:{color:ce==="table"?"var(--main-icon-color)":"var(--primary-color)"}})})}),e.jsx(B,{onClick:()=>Me("icon"),"aria-label":"Icon View",disabled:ce==="icon",children:e.jsx($,{title:"Icon View (beta)",children:e.jsx(lo,{style:{color:ce==="icon"?"var(--main-icon-color)":"var(--primary-color)"}})})})]})]}),e.jsxs(De,{open:U,onClose:m,children:[e.jsx(Ne,{children:"Configure Devices Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:sr.map(q=>e.jsx(We,{control:e.jsx(Fe,{disabled:["pluginName","name","configButton"].includes(q.accessor),checked:b[q.accessor],onChange:()=>_(q.accessor)}),label:q.Header},q.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:m,children:"Close"})})]}),ce==="table"&&e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",maxHeight:`${j&&f?"50%":"100%"}`,width:"100%",flex:"1 1 auto",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Registered devices"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(B,{onClick:m,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})})]}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0",padding:"0",gap:"0"},children:e.jsx(Hn,{data:w,columnVisibility:b,setPlugin:F,setEndpoint:H,setDeviceName:M})}),e.jsx("div",{className:"MbfWindowFooter",style:{borderTop:"1px solid var(--table-border-color)",justifyContent:"flex-start"},children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",textAlign:"left"},children:["Total devices: ",w.length.toString()]})})]}),e.jsxs(De,{open:O,onClose:T,children:[e.jsx(Ne,{children:"Configure Clusters Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:lr.map(q=>e.jsx(We,{control:e.jsx(Fe,{disabled:["clusterName","attributeName","attributeValue"].includes(q.accessor),checked:u[q.accessor],onChange:()=>Z(q.accessor)}),label:q.Header},q.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:T,children:"Close"})})]}),ce==="table"&&j&&f&&e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",height:"50%",maxHeight:"50%",width:"100%",flex:"1 1 auto",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsxs("div",{className:"MbfWindowHeaderText",style:{display:"flex",flexDirection:"row",justifyContent:"space-between"},children:[e.jsxs("p",{style:{margin:"0px",padding:"0px"},children:['Clusters for device "',V,'" on endpoint ',f]}),e.jsx(B,{onClick:T,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})]})}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0",padding:"0",gap:"0"},children:e.jsx(Rn,{data:t,columnVisibility:u})}),e.jsx("div",{className:"MbfWindowFooter",style:{borderTop:"1px solid var(--table-border-color)",justifyContent:"flex-start"},children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",textAlign:"left"},children:["Total child endpoints: ",E-1]})})]}),ce==="icon"&&e.jsx(Wn,{filter:C,devices:w})]}):e.jsx(Qe,{})}const $n=o.memo(On);function En(){const[r,c]=o.useState(localStorage.getItem("logFilterLevel")??"info"),[i,n]=o.useState(localStorage.getItem("logFilterSearch")??"*"),[s,h]=o.useState(localStorage.getItem("logAutoScroll")!=="false"),{setMessages:y,setLogFilters:t,online:l,setAutoScroll:j}=o.useContext(xe),F=M=>{c(M.target.value),t(M.target.value,i),localStorage.setItem("logFilterLevel",M.target.value),a&&console.log("handleChangeLevel called with value:",M.target.value)},f=M=>{n(M.target.value),t(r,M.target.value),localStorage.setItem("logFilterSearch",M.target.value),a&&console.log("handleChangeSearch called with value:",M.target.value)},H=M=>{h(M.target.checked),j(M.target.checked),localStorage.setItem("logAutoScroll",M.target.value?"true":"false"),a&&console.log("handleAutoScrollChange called with value:",M.target.checked)},V=()=>{a&&console.log("handleClearLogsClick called"),y([])};return a&&console.log("Logs rendering..."),l?e.jsxs("div",{className:"MbfPageDiv",children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",margin:"0px",padding:"0px",gap:"10px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(_t,{id:"select-level",style:{color:"var(--div-text-color)"},children:"Filter log by level:"}),e.jsxs(ot,{style:{height:"30px",backgroundColor:"var(--main-bg-color)"},labelId:"select-level",id:"debug-level",value:r,onChange:F,children:[e.jsx(L,{value:"debug",children:"Debug"}),e.jsx(L,{value:"info",children:"Info"}),e.jsx(L,{value:"notice",children:"Notice"}),e.jsx(L,{value:"warn",children:"Warn"}),e.jsx(L,{value:"error",children:"Error"}),e.jsx(L,{value:"fatal",children:"Fatal"})]}),e.jsx(_t,{id:"search",style:{color:"var(--div-text-color)"},children:"Filter log by text:"}),e.jsx(pe,{style:{width:"300px"},size:"small",id:"logsearch",variant:"outlined",value:i,onChange:f,InputProps:{style:{height:"30px",padding:"0 0px",backgroundColor:"var(--main-bg-color)"}}}),e.jsx(We,{control:e.jsx(Fe,{checked:s,onChange:H}),label:"Auto scroll",style:{color:"var(--div-text-color)"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:e.jsx($,{title:"Clear the logs",children:e.jsx(ne,{onClick:V,endIcon:e.jsx(St,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Clear"})})})]}),e.jsx("div",{style:{flex:"1",overflow:"auto",margin:"0px",padding:"0px"},children:e.jsx(ar,{})})]}):e.jsx(Qe,{})}const Vn=({open:r,ip:c,onClose:i,onSave:n})=>{const s=c?c.split(".").slice(0,3).join(".")+".1":"",[h,y]=o.useState("dhcp"),[t,l]=o.useState({ip:c??"",subnet:"255.255.255.0",gateway:s,dns:s}),j=H=>V=>{l({...t,[H]:V.target.value})},F=()=>{i()},f=()=>{const H=h==="static"?{type:h,...t}:{type:h};n(H),i()};return e.jsxs(De,{open:r,onClose:(H,V)=>{V==="backdropClick"||V==="escapeKeyDown"||i()},maxWidth:"sm",style:{maxWidth:"550px",margin:"auto"},children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:"Network Configuration"})]})}),e.jsxs(Pe,{dividers:!0,children:[e.jsxs(or,{component:"fieldset",fullWidth:!0,children:[e.jsx(Ie,{component:"legend",children:"Select IP Configuration"}),e.jsxs(nr,{row:!0,value:h,onChange:H=>y(H.target.value),children:[e.jsx(We,{value:"dhcp",control:e.jsx(wt,{}),label:"DHCP"}),e.jsx(We,{value:"static",control:e.jsx(wt,{}),label:"Static"})]})]}),h==="static"&&e.jsxs(Ae,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"IP Address",fullWidth:!0,value:t.ip,onChange:j("ip")})}),e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"Subnet Mask",fullWidth:!0,value:t.subnet,onChange:j("subnet")})}),e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"Gateway",fullWidth:!0,value:t.gateway,onChange:j("gateway")})}),e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"DNS Server",fullWidth:!0,value:t.dns,onChange:j("dns")})})]})]}),e.jsxs(Le,{children:[e.jsx(ne,{onClick:F,children:"Cancel"}),e.jsx(ne,{variant:"contained",onClick:f,children:"Save"})]})]})},_n=({open:r,onClose:c,onSave:i})=>{const[n,s]=o.useState(""),[h,y]=o.useState(""),t=V=>{s(V.target.value)},l=V=>{y(V.target.value)},j=n.length>0&&n===h,F=()=>{c()},f=()=>{j&&(i(n),c())},H=()=>{i(""),c()};return e.jsxs(De,{open:r,onClose:(V,M)=>{M==="backdropClick"||M==="escapeKeyDown"||c()},maxWidth:"sm",style:{maxWidth:"500px",margin:"auto"},disableEscapeKeyDown:!0,children:[e.jsx(Ne,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:"Change Password"})]})}),e.jsx(Pe,{dividers:!0,children:e.jsx(or,{component:"fieldset",fullWidth:!0,sx:{margin:0,padding:0,gap:"20px"},children:e.jsxs(Ae,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Ae,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"New Password",size:"small",variant:"outlined",fullWidth:!0,value:n,onChange:t})}),e.jsx(Ae,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"Confirm Password",size:"small",variant:"outlined",fullWidth:!0,value:h,onChange:l,error:h!==""&&n!==h,helperText:h!==""&&n!==h?"Passwords do not match":""})})]})})}),e.jsxs(Le,{children:[e.jsx(ne,{onClick:F,children:"Cancel"}),e.jsx(ne,{variant:"contained",onClick:f,disabled:!j,children:"Change"}),e.jsx(ne,{variant:"contained",onClick:H,children:"Reset"})]})]})};function An(){const{online:r,addListener:c,removeListener:i,sendMessage:n,getUniqueId:s}=o.useContext(xe),[h,y]=o.useState(null),[t,l]=o.useState(null),j=o.useRef(s());return o.useEffect(()=>{const F=f=>{f.src==="Matterbridge"&&f.dst==="Frontend"&&(f.method==="refresh_required"&&f.params.changed==="settings"&&(a&&console.log(`Settings received refresh_required: changed=${f.params.changed} and sending /api/settings request`),n({id:j.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),f.method==="/api/settings"&&(a&&console.log("Settings received /api/settings:",f.response),y(f.response.matterbridgeInformation),l(f.response.systemInformation)))};return c(F),a&&console.log("Settings added WebSocket listener"),()=>{i(F),a&&console.log("Settings removed WebSocket listener")}},[c,i,n]),o.useEffect(()=>{r&&(a&&console.log("Settings received online"),n({id:j.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[r,n]),h?(a&&console.log("Settings rendering..."),r?e.jsx("div",{className:"MbfPageDiv",children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"20px",width:"100%"},children:[e.jsx(Un,{matterbridgeInfo:h,systemInfo:t}),e.jsx(zn,{matterbridgeInfo:h}),e.jsx(qn,{matterbridgeInfo:h})]})}):e.jsx(Qe,{})):null}function Un({matterbridgeInfo:r,systemInfo:c}){const{sendMessage:i,getUniqueId:n}=o.useContext(xe),[s,h]=o.useState("bridge"),[y,t]=o.useState("Info"),[l,j]=o.useState(!1),[F,f]=o.useState("dark"),[H,V]=o.useState(localStorage.getItem("homePagePlugins")!=="false"),[M,E]=o.useState(localStorage.getItem("homePageMode")??"logs"),[p,U]=o.useState(localStorage.getItem("virtualMode")??"outlet"),v=o.useRef(n()),[b,D]=o.useState(!1),O=()=>D(!1),N=T=>{a&&console.log("handleSaveNetConfig called with config:",T),i({id:v.current,sender:"Settings",method:"/api/shellynetconfig",src:"Frontend",dst:"Matterbridge",params:T})},[u,R]=o.useState(!1),C=()=>R(!1),x=T=>{a&&console.log("handleSaveChangePassword called with password:",T),i({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setpassword",value:T}})};o.useEffect(()=>{r.bridgeMode!==void 0&&(h(r.bridgeMode==="bridge"?"bridge":"childbridge"),t(r.loggerLevel.charAt(0).toUpperCase()+r.loggerLevel.slice(1)),j(r.fileLogger),U(r.virtualMode))},[r]),o.useEffect(()=>{const T=localStorage.getItem("frontendTheme");T&&f(T)},[]);const w=T=>{a&&console.log("handleChangeBridgeMode called with value:",T.target.value),h(T.target.value),i({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setbridgemode",value:T.target.value}})},z=T=>{a&&console.log("handleChangeMbLoggerLevel called with value:",T.target.value),t(T.target.value),i({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmbloglevel",value:T.target.value}})},ce=T=>{a&&console.log("handleLogOnFileMbChange called with value:",T.target.checked),j(T.target.checked),i({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmblogfile",value:T.target.checked}})},be=T=>{const Z=T.target.value;a&&console.log("handleChangeTheme called with value:",Z),f(Z),localStorage.setItem("frontendTheme",Z),document.body.setAttribute("frontend-theme",Z)},S=T=>{const Z=T.target.checked;a&&console.log("handleChangeHomePagePlugins called with value:",Z),V(Z),localStorage.setItem("homePagePlugins",Z?"true":"false")},m=T=>{const Z=T.target.value;a&&console.log("handleChangeHomePageMode called with value:",Z),E(Z),localStorage.setItem("homePageMode",Z)},_=T=>{const Z=T.target.value;a&&console.log("handleChangeVirtualMode called with value:",Z),U(Z),localStorage.setItem("virtualMode",Z),i({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setvirtualmode",value:Z}})};return e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge settings"})}),e.jsx(Vn,{open:b,ip:c.ipv4Address,onClose:O,onSave:N}),e.jsx(_n,{open:u,onClose:C,onSave:x}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(X,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"matterbridgeInfo-mode",children:"Matterbridge mode:"}),e.jsxs(nr,{row:!0,name:"mode-buttons-group",value:s,onChange:w,children:[e.jsx(We,{value:"bridge",control:e.jsx(wt,{}),label:"Bridge",disabled:r.readOnly===!0}),e.jsx(We,{value:"childbridge",control:e.jsx(wt,{}),label:"Childbridge",disabled:r.readOnly===!0})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"mblogger-level-label",children:"Logger level:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"mblogger-level-label",id:"mblogger-level",value:y,onChange:z,children:[e.jsx(L,{value:"Debug",children:"Debug"}),e.jsx(L,{value:"Info",children:"Info"}),e.jsx(L,{value:"Notice",children:"Notice"}),e.jsx(L,{value:"Warn",children:"Warn"}),e.jsx(L,{value:"Error",children:"Error"}),e.jsx(L,{value:"Fatal",children:"Fatal"})]}),e.jsx(We,{style:{padding:"0px",margin:"0px"},control:e.jsx(Fe,{checked:l,onChange:ce,name:"logOnFileMb"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-theme-label",children:"Frontend theme:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"frontend-theme-label",id:"frontend-theme",value:F,onChange:be,children:[e.jsx(L,{value:"classic",children:"Classic"}),e.jsx(L,{value:"light",children:"Light"}),e.jsx(L,{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-home-plugin-label",children:"Home page plugins:"}),e.jsx(Fe,{checked:H,onChange:S,name:"showPlugins"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-home-label",children:"Home page bottom panel:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"frontend-home-label",id:"frontend-home",value:M,onChange:m,children:[e.jsx(L,{value:"logs",children:"Logs"}),e.jsx(L,{value:"devices",children:"Devices"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"10px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-virtual-label",children:"Virtual devices:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"frontend-virtual-label",id:"frontend-virtual",value:p,onChange:_,children:[e.jsx(L,{value:"disabled",children:"Disabled"}),e.jsx(L,{value:"outlet",children:"Outlet"}),e.jsx(L,{value:"light",children:"Light"}),e.jsx(L,{value:"switch",children:"Switch"}),e.jsx(L,{value:"mounted_switch",children:"Mounted Switch"})]})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>R(!0),children:"Change password"})}),r.shellyBoard&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>D(!0),children:"Configure IP"})})]})})]})}function zn({matterbridgeInfo:r}){const{sendMessage:c,getUniqueId:i}=o.useContext(xe),[n,s]=o.useState("Info"),[h,y]=o.useState(!1),[t,l]=o.useState(""),[j,F]=o.useState(""),[f,H]=o.useState(""),[V,M]=o.useState(),[E,p]=o.useState(),[U,v]=o.useState(),b=o.useRef(i());o.useEffect(()=>{r.bridgeMode!==void 0&&(s(["Debug","Info","Notice","Warn","Error","Fatal"][r.matterLoggerLevel]),y(r.matterFileLogger),l(r.matterMdnsInterface),F(r.matterIpv4Address),H(r.matterIpv6Address),M(r.matterPort),p(r.matterDiscriminator),v(r.matterPasscode))},[r]);const D=z=>{a&&console.log("handleChangeMjLoggerLevel called with value:",z.target.value),s(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjloglevel",value:z.target.value}})},O=z=>{a&&console.log("handleLogOnFileMjChange called with value:",z.target.checked),y(z.target.checked),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjlogfile",value:z.target.checked}})},N=z=>{a&&console.log("handleChangeMdnsInterface called with value:",z.target.value),l(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmdnsinterface",value:z.target.value}})},u=z=>{a&&console.log("handleChangeIpv4Address called with value:",z.target.value),F(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv4address",value:z.target.value}})},R=z=>{a&&console.log("handleChangeIpv6Address called with value:",z.target.value),H(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv6address",value:z.target.value}})},C=z=>{a&&console.log("handleChangeMatterPort called with value:",z.target.value),M(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterport",value:z.target.value}})},x=z=>{a&&console.log("handleChangeMatterDiscriminator called with value:",z.target.value),p(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterdiscriminator",value:z.target.value}})},w=z=>{a&&console.log("handleChangemMatterPasscode called with value:",z.target.value),v(z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterpasscode",value:z.target.value}})};return e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matter settings"})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(X,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"mjdebug-info",children:"Logger level:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"select-mjlevel",id:"mjdebug-level",value:n,onChange:D,children:[e.jsx(L,{value:"Debug",children:"Debug"}),e.jsx(L,{value:"Info",children:"Info"}),e.jsx(L,{value:"Notice",children:"Notice"}),e.jsx(L,{value:"Warn",children:"Warn"}),e.jsx(L,{value:"Error",children:"Error"}),e.jsx(L,{value:"Fatal",children:"Fatal"})]}),e.jsx(We,{style:{padding:"0px",margin:"0px"},control:e.jsx(Fe,{checked:h,onChange:O,name:"logOnFileMj"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Mdns interface:"}),e.jsx(pe,{value:t,onChange:N,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Ipv4 address:"}),e.jsx(pe,{value:j,onChange:u,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Ipv6 address:"}),e.jsx(pe,{value:f,onChange:R,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Commissioning port:"}),e.jsx(pe,{value:V,onChange:C,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Commissioning discriminator:"}),e.jsx(pe,{value:E,onChange:x,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Commissioning passcode:"}),e.jsx(pe,{value:U,onChange:w,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]})]})})]})}function qn({matterbridgeInfo:r}){return e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge info"})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(X,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[" ",e.jsx(Be,{value:r.matterbridgeVersion,label:"Current Version"}),e.jsx(Be,{value:r.matterbridgeLatestVersion,label:"Latest Version"}),e.jsx(Be,{value:r.homeDirectory,label:"Home Directory"}),e.jsx(Be,{value:r.rootDirectory,label:"Root Directory"}),e.jsx(Be,{value:r.matterbridgeDirectory,label:"Matterbridge Storage Directory"}),e.jsx(Be,{value:r.matterbridgePluginDirectory,label:"Matterbridge Plugin Directory"}),e.jsx(Be,{value:r.globalModulesDirectory,label:"Global Module Directory"})]})})]})}function Be({value:r,label:c}){return e.jsx(pe,{focused:!0,value:r,size:"small",label:c,variant:"standard",sx:{width:"400px"},InputProps:{readOnly:!0,sx:{color:"var(--div-text-color)","&:before":{borderBottomColor:"var(--main-label-color)"},"&:after":{borderBottomColor:"var(--main-label-color)"}}},InputLabelProps:{sx:{marginTop:"3px",color:"var(--main-label-color)","&.Mui-focused":{color:"var(--main-label-color)"}}}})}function Bn(r,c,i){const n=r?.[i],s=c?.[i];return n==null&&s==null?0:n==null?-1:s==null?1:typeof n=="boolean"&&typeof s=="boolean"?n===s?0:n?1:-1:typeof n=="number"&&typeof s=="number"?n-s:String(n).localeCompare(String(s))}function Jn({name:r,columns:c,rows:i,getRowKey:n,footerLeft:s,footerRight:h}){const y=o.useRef(new WeakMap),t=o.useRef(1),l=u=>{if(typeof n=="string"&&u&&u[n]!=null)return u[n];if(typeof n=="function"){const x=n(u);if(x!=null)return x}const R=c?.[0]?.id;if(R&&u&&u[R]!=null)return u[R];console.warn(`MbfTable(${r}): using fallback stable row key; consider providing getRowKey prop for better React performance`);let C=y.current.get(u);return C||(C=`rk_${t.current++}`,y.current.set(u,C)),C},[j,F]=o.useState(localStorage.getItem(`${r}_table_order_by`)||null),[f,H]=o.useState(localStorage.getItem(`${r}_table_order`)||null),[V,M]=o.useState(!1),[E,p]=o.useState(()=>{try{const u=localStorage.getItem(`${r}_column_visibility`);if(u)return JSON.parse(u)}catch{}return{}}),U=o.useMemo(()=>{const u={};for(const R of c)R.hidden||(u[R.id]=R.required?!0:E[R.id]!==!1);return u},[c,E]),v=o.useMemo(()=>{if(!j||!f)return i;const u=c.find(C=>C.id===j);if(!u||u.nosort)return i;const R=i.map((C,x)=>({el:C,index:x}));return R.sort((C,x)=>{const w=Bn(C.el,x.el,j);return w!==0?f==="asc"?w:-w:C.index-x.index}),R.map(C=>C.el)},[i,j,f,c]),b=u=>{if(j!==u||!j){F(u),H("asc"),localStorage.setItem(`${r}_table_order_by`,u),localStorage.setItem(`${r}_table_order`,"asc");return}if(f==="asc"){H("desc"),localStorage.setItem(`${r}_table_order`,"desc");return}F(null),H(null),localStorage.removeItem(`${r}_table_order_by`),localStorage.removeItem(`${r}_table_order`)},D=()=>{M(!V)},O=u=>{p(R=>{const C=c.find(z=>z.id===u);if(C&&C.required)return R;const x=U[u]!==!1,w={...R};x?w[u]=!1:delete w[u];try{localStorage.setItem(`${r}_column_visibility`,JSON.stringify(w))}catch{}return w})},N=()=>{const u={};p(u);try{localStorage.setItem(`${r}_column_visibility`,JSON.stringify(u))}catch{}};return console.log(`Rendering table ${r}${j&&f?` ordered by ${j}:${f}`:""}`),e.jsxs("div",{style:{display:"flex",flexDirection:"column",margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",height:"100%",minHeight:0,overflow:"hidden"},children:[e.jsxs(De,{open:V,onClose:(u,R)=>{R==="backdropClick"||R==="escapeKeyDown"||D()},disableEscapeKeyDown:!0,disableRestoreFocus:!0,children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:`Configure ${r} columns`})]})}),e.jsx(Pe,{children:e.jsx(st,{children:c.filter(u=>!u.hidden).map(u=>e.jsx(We,{control:e.jsx(Fe,{disabled:!!u.required,checked:u.required?!0:U[u.id]!==!1,onChange:()=>O(u.id)}),label:u.label},u.id))})}),e.jsxs(Le,{children:[e.jsx(ne,{onClick:N,children:"Reset"}),e.jsx(ne,{variant:"contained",onClick:u=>{if(u?.currentTarget&&typeof u.currentTarget.blur=="function")try{u.currentTarget.blur()}catch{}const R=document.activeElement;if(R&&R instanceof HTMLElement&&typeof R.blur=="function")try{R.blur()}catch{}D()},children:"Close"})]})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between",borderBottom:"none"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:r}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(B,{onClick:u=>{if(u?.currentTarget?.blur)try{u.currentTarget.blur()}catch{}D()},"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:`Configure ${r} columns`,children:e.jsx(te,{path:Lo,size:"20px",style:{color:"var(--header-text-color)"}})})})})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",flex:"1 1 auto",minHeight:0,width:"100%",overflow:"auto",margin:"0px",padding:"0px",gap:"0"},children:e.jsxs("table",{"aria-label":`${r} table`,style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{style:{position:"sticky",top:0,zIndex:10,border:"none",color:"var(--header-text-color)",backgroundColor:"var(--header-bg-color"},children:e.jsx("tr",{style:{height:"30px",minHeight:"30px"},children:c.map(u=>{if(u.hidden||!u.required&&U[u.id]===!1)return null;const R=!u.nosort,C=R&&j===u.id&&!!f;return e.jsxs("th",{onClick:R?()=>b(u.id):void 0,style:{margin:"0",padding:"4px 8px",position:"sticky",top:0,minWidth:u.minWidth,maxWidth:u.maxWidth,textAlign:u.align||"left",cursor:R?"pointer":"default",border:"none",color:"var(--header-text-color)",backgroundColor:"var(--header-bg-color)",whiteSpace:u.maxWidth?"nowrap":void 0,overflow:u.maxWidth?"hidden":void 0,textOverflow:u.maxWidth?"ellipsis":void 0},"aria-sort":R?C?f==="asc"?"ascending":"descending":"none":void 0,children:[u.label,C&&e.jsxs("span",{style:{marginLeft:6},children:[f==="asc"&&e.jsx(te,{path:Ft,size:"15px"}),f==="desc"&&e.jsx(te,{path:Wt,size:"15px"})]})]},u.id)})})}),e.jsx("tbody",{children:v.map((u,R)=>{const C=l(u);return e.jsx("tr",{className:R%2===0?"table-content-even":"table-content-odd",style:{height:"30px",minHeight:"30px",border:"none",borderCollapse:"collapse"},children:c.map(x=>{if(x.hidden||!x.required&&U[x.id]===!1)return null;const w=u[x.id];return e.jsx("td",{style:{border:"none",borderCollapse:"collapse",textAlign:x.align||"left",padding:"4px 8px",margin:"0",maxWidth:x.maxWidth,whiteSpace:x.maxWidth?"nowrap":void 0,overflow:x.maxWidth?"hidden":void 0,textOverflow:x.maxWidth?"ellipsis":void 0},children:typeof x.render=="function"?x.render(w,C,u,x):typeof w=="boolean"?e.jsx(Fe,{checked:w,disabled:!0,size:"small",sx:{m:0,p:0,color:"var(--table-text-color)","&.Mui-disabled":{color:"var(--table-text-color)",opacity:.7}}}):x.format&&typeof w=="number"?x.format(w):w!=null?String(w):null},x.id)})},C)})})]})}),e.jsxs("div",{className:"MbfWindowFooter",style:{height:"30px",minHeight:"30px",justifyContent:"space-between",border:"none"},children:[e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:s}),e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:h})]})]})}const Qn=o.memo(Jn);function Gn(){const{online:r,sendMessage:c,addListener:i,removeListener:n,getUniqueId:s}=o.useContext(xe),{showSnackbarMessage:h,closeSnackbarMessage:y}=o.useContext(nt),[t,l]=o.useState(null),[j,F]=o.useState(null),[f,H]=o.useState(null),[V,M]=o.useState(null),[E,p]=o.useState({cpuUsage:0}),[U,v]=o.useState({totalMemory:"",freeMemory:"",heapTotal:"",heapUsed:"",external:"",arrayBuffers:"",rss:""}),[b,D]=o.useState({systemUptime:"",processUptime:""}),O=o.useRef(-1),[N,u]=o.useState(()=>dr);O.current||(O.current=s(),console.log("Test uniqueId:",O)),o.useEffect(()=>{console.log("Test useEffect WebSocketMessage mounting");const C=x=>{if(x.src==="Matterbridge"&&x.dst==="Frontend"){if(he(x)&&x.method==="restart_required"&&(console.log("Test received restart_required"),h("Restart required",0)),he(x)&&x.method==="refresh_required"&&(console.log(`Test received refresh_required: changed=${x.params.changed} and sending api requests`),h("Refresh required",0),c({id:O.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:O.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:O.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),he(x)&&x.method==="memory_update"&&(console.log("Test received memory_update",x),v(x.params)),he(x)&&x.method==="cpu_update"&&(console.log("Test received cpu_update",x),p(x.params)),he(x)&&x.method==="uptime_update"&&(console.log("Test received uptime_update",x),D(x.params)),Ve(x)&&x.method==="/api/settings"&&x.response&&(console.log("Test received /api/settings:",x.response),h("Test received /api/settings"),l(x.response)),Ve(x)&&x.method==="/api/plugins"&&x.response&&(console.log(`Test received ${x.response.length} plugins:`,x.response),h("Test received /api/plugins"),F(x.response)),Ve(x)&&x.method==="/api/devices"&&x.response){console.log(`Test received ${x.response.length} devices:`,x.response),h("Test received /api/devices"),H(x.response);for(const w of x.response)console.log("Test sending /api/clusters for device:",w.pluginName,w.name,w.endpoint),c({id:O.current,method:"/api/clusters",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{plugin:w.pluginName,endpoint:w.endpoint}})}Ve(x)&&x.method==="/api/clusters"&&x.response&&(console.log(`Test received ${x.response.clusters.length} clusters for device ${x.response.deviceName} endpoint ${x.response.endpoint}:`,x),h("Test received /api/clusters"),M(x.response))}};return i(C),console.log("Test useEffect WebSocketMessage mounted"),()=>{console.log("Test useEffect WebSocketMessage unmounting"),n(C),console.log("Test useEffect WebSocketMessage unmounted")}},[i,n,c,h]),o.useEffect(()=>(console.log("Test useEffect online mounting"),r&&(console.log("Test useEffect online received online"),c({id:O.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:O.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:O.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),console.log("Test useEffect online mounted"),()=>{console.log("Test useEffect online unmounted")}),[r,c,h]);const R=o.useCallback(C=>String(C.code),[]);return console.log("Test rendering..."),r?e.jsx("div",{className:"MbfPageDiv",style:{display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center",height:"100vh"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"20px",width:"100%"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"256px",width:"256px",margin:"10px"}}),e.jsx("p",{children:"Welcome to the Test page of the Matterbridge frontend"}),e.jsx("div",{style:{margin:"0",padding:"0",gap:"0",width:"1200px",maxWidth:"1200px",height:"600px",maxHeight:"600px",overflow:"hidden",backgroundColor:"var(--div-bg-color)",border:"1px solid #0004ffff"},children:e.jsx(Qn,{name:"Test",columns:Yn,rows:N,getRowKey:R,footerLeft:"Left Footer",footerRight:"Right Footer"})}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>{console.log("Test button clicked"),h("Test button clicked"),y("Refresh required"),y("Restart required"),y("Test permanent message removal")},children:"Test"}),e.jsx(ne,{variant:"outlined",onClick:()=>{u(C=>{const x=C.findIndex(be=>be.code==="F123");if(x===-1)return C;const w=C[x],z={...w,population:(w.population||0)+1},ce=C.slice();return ce[x]=z,ce})},children:"Update F123"})]})]})}):e.jsx(Qe,{})}const Kn=o.memo(Gn),Yn=[{id:"name",label:"Name",minWidth:50,maxWidth:100,required:!0},{id:"code",label:"ISO Code",minWidth:100,render:(r,c,i,n)=>e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",borderRadius:"8px",backgroundColor:"var(--chip-bg, #e6f4ff)",color:"var(--chip-fg, #0550ae)",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:"0.85em"},children:String(r)})},{id:"isIsland",label:"Island",minWidth:80,align:"center"},{id:"population",label:"Population",minWidth:170,align:"right",format:r=>r.toLocaleString("en-US")},{id:"size",label:"Size (km²)",minWidth:170,align:"right",format:r=>r.toLocaleString("en-US")},{id:"density",label:"Density",minWidth:170,align:"right",nosort:!0,format:r=>r.toFixed(2)},{id:"virtual",label:"Virtual",align:"right",required:!0,nosort:!0,render:(r,c,i,n)=>i.isIsland?"🏝️":"🏞️"}];function Se(r,c,i,n,s){const h=i/n;return{name:r,code:c,population:i,size:n,density:h,isIsland:s}}const dr=[Se("India","IN",1324171354,3287263,!1),Se("China","CN",1403500365,9596961,!1),Se("Italy","IT",60483973,301340,!1),Se("United States","US",327167434,9833520,!1),Se("Canada is a truly wonderful country","CA",37602103,9984670,!1),Se("Australia","AU",25475400,7692024,!0),Se("Germany","DE",83019200,357578,!1),Se("Ireland","IE",4857e3,70273,!0),Se("Mexico","MX",126577691,1972550,!1),Se("Japan","JP",126317e3,377973,!0),Se("France","FR",67022e3,640679,!1),Se("United Kingdom","GB",67545757,242495,!0),Se("Russia","RU",146793744,17098246,!1),Se("Nigeria","NG",200962417,923768,!1),Se("Brazil","BR",210147125,8515767,!1)],Kt=["Zor","Eld","Myth","Drak","Lum","Xen","Thal","Quor","Vex","Nyx"],Yt=["aria","dor","mere","land","wyn","gard","heim","quess","tor","vale"];for(let r=0;r<2e3;r++){const c=`${Kt[r%Kt.length]}${Yt[r%Yt.length]} ${r}`,i=`F${r.toString().padStart(3,"0")}`,n=Math.floor(Math.random()*1e9),s=Math.floor(Math.random()*1e7),h=Math.random()<.2;dr.push(Se(c,i,n,s,h))}function Xn(r,c){a&&console.log("getCssVariable:",r,"defaultValue",c);const i=getComputedStyle(document.body).getPropertyValue(r).trim();return i||console.error("getCssVariable: undefined",i),i||c}function Zn(r){return co({palette:{primary:{main:r},action:{disabled:"var(--main-label-color)"},text:{disabled:"var(--main-label-color)"}},typography:{fontFamily:"Roboto, Helvetica, Arial, sans-serif"},components:{MuiDialog:{styleOverrides:{paper:{color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)",border:"2px solid var(--div-border-color)",borderRadius:"var(--div-border-radius)",boxShadow:"2px 2px 5px var(--div-shadow-color)"}}},MuiTooltip:{defaultProps:{placement:"top-start",arrow:!0}},MuiButton:{styleOverrides:{root:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)","&:hover":{backgroundColor:"var(--main-button-bg-color)"},"&.Mui-disabled":{color:"var(--main-button-color)",backgroundColor:"var(--main-grey-color)"}},contained:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)"},outlined:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)"},text:{color:"var(--main-button-color)"}},defaultProps:{variant:"contained",size:"small"}},MuiIconButton:{styleOverrides:{root:{color:"var(--main-icon-color)","&:hover .MuiSvgIcon-root":{color:"var(--primary-color)"}}}},MuiCheckbox:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-checked":{color:"var(--primary-color)"}}}},MuiTextField:{defaultProps:{size:"small",variant:"outlined",fullWidth:!0}},MuiOutlinedInput:{styleOverrides:{root:{backgroundColor:"var(--div-bg-color)","& .MuiOutlinedInput-notchedOutline":{borderColor:"var(--main-label-color)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"var(--main-text-color)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"var(--primary-color)"},padding:"0px"},input:{color:"var(--div-text-color)",padding:"4px 8px"}}},MuiInputLabel:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-focused":{color:"var(--primary-color)"}}}},MuiFormLabel:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-focused":{color:"var(--main-label-color)"}}}},MuiFormControl:{styleOverrides:{root:{color:"var(--main-grey-color)"}}},MuiRadio:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-checked":{color:"var(--primary-color)"}}}},MuiSelect:{styleOverrides:{root:{backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)",height:"30px","&:hover":{borderColor:"var(--main-text-color)"},"&.Mui-focused":{borderColor:"var(--primary-color)"}}}},MuiMenu:{styleOverrides:{paper:{backgroundColor:"var(--main-menu-bg-color)",padding:"0px",margin:"0px"},list:{padding:"0px"}}},MuiMenuItem:{styleOverrides:{root:{color:"var(--main-menu-color)",backgroundColor:"var(--main-menu-bg-color)","&:hover":{backgroundColor:"var(--main-menu-hover-color)"},"&.Mui-selected":{color:"var(--main-menu-color)",backgroundColor:"var(--main-menu-bg-color)"},"&.Mui-selected:hover":{backgroundColor:"var(--main-menu-hover-color)"}}}},MuiListItemButton:{styleOverrides:{root:{cursor:"pointer","&:hover":{backgroundColor:"var(--main-bg-color)"}}}},MuiListItemIcon:{styleOverrides:{root:{color:"var(--div-text-color)"}}},MuiListItemText:{styleOverrides:{primary:{fontSize:"16px",fontWeight:"bold",color:"var(--div-text-color)"},secondary:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"}}}}})}let a=!1;const ei=()=>{a=!a},cr=o.createContext(void 0);function ti({children:r}){const[c,i]=o.useState(!1),[n,s]=o.useState(""),h=async y=>{try{const t=await fetch("./api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:y})});if(t.ok){const{valid:l}=await t.json();l?i(!0):y!==""&&s("Incorrect password!")}else console.error("Failed to log in:",t.statusText)}catch(t){console.error("Failed to log in:",t)}};return e.jsx(cr.Provider,{value:{loggedIn:c,logIn:h,errorMessage:n},children:r})}function ri(){const[r,c]=o.useState(""),i=o.useContext(cr),[n,s]=o.useState("#1976d2");if(!i)throw new Error("AuthContext not found");const{loggedIn:h,logIn:y,errorMessage:t}=i,l=M=>{M.preventDefault(),y(r)},j={display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",backgroundColor:"var(--main-bg-color)"},F={display:"flex",flexDirection:"column",maxWidth:"400px",margin:"0 auto",padding:"20px",gap:"20px",border:"1px solid var(--div-border-color)",borderRadius:"var(--div-border-radius)",boxShadow:"2px 2px 5px var(--div-shadow-color)",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},f={margin:"10px 0",padding:"3px 3px",fontSize:"14px",width:"230px",border:"1px solid var(--main-label-color)",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"};o.useEffect(()=>{a&&console.log("Setting frontend theme");const M=localStorage.getItem("frontendTheme");a&&console.log("Saved theme:",M),M?document.body.setAttribute("frontend-theme",M):document.body.setAttribute("frontend-theme","dark");const E=Xn("--primary-color","#1976d2");a&&console.log("Primary color from CSS:",E),s(E)},[]);const H=window.location.pathname.includes("/matterbridge/")?"/matterbridge":window.location.href.includes("/api/hassio_ingress/")?window.location.pathname:"/";console.log(`Loading App.js with href="${window.location.href}" and pathname="${window.location.pathname}" >>> baseName="${H}"`);const V=Zn(n);return y(""),h?e.jsx(po,{theme:V,children:e.jsx(jr,{dense:!0,maxSnack:10,preventDuplicate:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(zo,{children:e.jsx(qo,{children:e.jsx(fr,{basename:H,children:e.jsxs("div",{className:"MbfScreen",children:[e.jsx(Jo,{}),e.jsxs(xr,{children:[e.jsx(Xe,{path:"/",element:e.jsx(bn,{})}),e.jsx(Xe,{path:"/devices",element:e.jsx($n,{})}),e.jsx(Xe,{path:"/log",element:e.jsx(En,{})}),e.jsx(Xe,{path:"/settings",element:e.jsx(An,{})}),e.jsx(Xe,{path:"/test",element:e.jsx(Kn,{})}),e.jsx(Xe,{path:"*",element:e.jsx(br,{to:"/"})})]})]})})})})})}):e.jsx("div",{style:j,children:e.jsxs("form",{onSubmit:l,style:F,children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"64px",width:"64px"}}),e.jsx("h3",{style:{color:"var(--div-text-color)"},children:"Welcome to Matterbridge"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:"20px"},children:[e.jsx("input",{type:"text",name:"username",autoComplete:"username",style:{display:"none"},tabIndex:-1}),e.jsx("input",{type:"password",value:r,onChange:M=>c(M.target.value),style:f,placeholder:"password",autoComplete:"current-password"}),e.jsx("button",{type:"submit",style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",borderColor:"var(--div-bg-color)"},children:"Log in"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",margin:0,height:"30px"},children:t&&e.jsx("p",{style:{color:"red"},children:t})})]})})}function oi(){return e.jsx(ti,{children:e.jsx(ri,{})})}vr.createRoot(document.getElementById("root")).render(e.jsx(Xt.StrictMode,{children:e.jsx(oi,{})}));
|
|
23
|
+
*/var we=(r=>(r[r.Log=0]="Log",r[r.RefreshRequired=1]="RefreshRequired",r[r.RestartRequired=2]="RestartRequired",r[r.RestartNotRequired=3]="RestartNotRequired",r[r.CpuUpdate=4]="CpuUpdate",r[r.MemoryUpdate=5]="MemoryUpdate",r[r.UptimeUpdate=6]="UptimeUpdate",r[r.Snackbar=7]="Snackbar",r[r.UpdateRequired=8]="UpdateRequired",r[r.StateUpdate=9]="StateUpdate",r[r.CloseSnackbar=10]="CloseSnackbar",r[r.ShellySysUpdate=100]="ShellySysUpdate",r[r.ShellyMainUpdate=101]="ShellyMainUpdate",r))(we||{});function fe(r){return r.id>=0&&r.id<=101}function Ve(r){return r.id>101&&r.src==="Matterbridge"&&r.dst==="Frontend"&&("success"in r||"error"in r)}function zo({open:r,title:c,message:a,onConfirm:i,onCancel:l}){const g=t=>{s&&console.log("Confirmed"),t.preventDefault(),i()},b=t=>{s&&console.log("Canceled"),t.preventDefault(),l()};return e.jsxs(De,{open:r,children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:c})]})}),e.jsxs(Pe,{children:[e.jsx("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",margin:"0",marginBottom:"20px",maxHeight:"350px",maxWidth:"350px"},children:e.jsx("p",{style:{flex:1,margin:"0"},children:a})}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-around"},children:[e.jsx(ne,{onClick:g,variant:"contained",color:"primary",size:"small",children:"Confirm"}),e.jsx(ne,{onClick:b,variant:"contained",color:"primary",size:"small",children:"Cancel"})]})]})]})}const ht=[],nt=o.createContext(null);function qo({children:r}){const{enqueueSnackbar:c,closeSnackbar:a}=jr(),i=o.useCallback(f=>{s&&console.log(`UiProvider closeSnackbarMessage: message ${f}`);const k=ht.findIndex(R=>R.message===f);k!==-1&&(a(ht[k].key),ht.splice(k,1),s&&console.log(`UiProvider closeSnackbarMessage: message ${f} removed from persistMessages`))},[a]),l=o.useCallback((f,k,R)=>{s&&console.log(`UiProvider showSnackbarMessage: message ${f} timeout ${k}`);const C=c(f,{variant:"default",autoHideDuration:k==null||k>0?(k??5)*1e3:null,persist:k===0,content:m=>e.jsx(Z,{sx:{margin:"0",padding:"0",width:"300px",marginRight:"30px"},children:e.jsx(Sr,{severity:R??"info",variant:"filled",sx:{color:"#fff",fontWeight:"normal",width:"100%",cursor:"pointer",padding:"0px 10px"},onClick:()=>a(m),action:e.jsx(J,{size:"small",onClick:()=>a(m),sx:{color:"#fff"},children:e.jsx(wr,{fontSize:"small"})}),children:f},m)},m)});k===0&&(s&&console.log(`UiProvider showSnackbarMessage: message ${f} timeout ${k} - persist key ${C}`),ht.push({message:f,key:C}))},[c,a]),[g,b]=o.useState(!1),[t,d]=o.useState(""),[y,W]=o.useState(""),[h,L]=o.useState(""),V=o.useRef(null),M=o.useRef(null),O=()=>{s&&console.log(`UiProvider handle confirm action ${h}`),b(!1),V.current&&V.current(h)},u=()=>{s&&console.log(`UiProvider handle cancel action ${h}`),b(!1),M.current&&M.current(h)},z=o.useCallback((f,k,R,C,m)=>{s&&console.log(`UiProvider showConfirmCancelDialog for command ${R}`),d(f),W(k),L(R),V.current=C,M.current=m,b(!0)},[]),v=o.useMemo(()=>({showSnackbarMessage:l,closeSnackbarMessage:i,closeSnackbar:a,showConfirmCancelDialog:z}),[l,i,a,z]);return e.jsxs(nt.Provider,{value:v,children:[e.jsx(zo,{open:g,title:t,message:y,onConfirm:O,onCancel:u}),r]})}const ir=o.createContext(null),be=o.createContext(null);function Bo({children:r}){const[c,a]=o.useState(localStorage.getItem("logFilterLevel")??"info"),[i,l]=o.useState(localStorage.getItem("logFilterSearch")??"*"),[g,b]=o.useState([]),[t,d]=o.useState(1e3),[y,W]=o.useState(!0),[h,L]=o.useState(!1),{showSnackbarMessage:V,closeSnackbarMessage:M,closeSnackbar:O}=o.useContext(nt),u=o.useRef([]),z=o.useRef(null),v=o.useRef(1),f=o.useRef(Math.floor(Math.random()*999e3)+1e3),k=o.useRef(null),R=o.useRef(null),C=o.useRef(null),m=o.useRef(c),H=o.useRef(i),j=o.useMemo(()=>window.location.href.replace(/^http/,"ws"),[]),x=o.useMemo(()=>window.location.href.includes("api/hassio_ingress"),[]),w=100,q=60,de=50,xe=300;o.useEffect(()=>{m.current=c},[c]),o.useEffect(()=>{H.current=i},[i]);const S=o.useCallback(()=>Math.floor(Math.random()*999e3)+1e3,[]),p=o.useCallback(N=>{if(z.current&&z.current.readyState===WebSocket.OPEN)try{N.id===void 0&&(N.id=f.current);const n=JSON.stringify(N);z.current.send(n),s&&console.log("WebSocket sent message:",N)}catch(n){s&&console.error(`WebSocket error sending message: ${n}`)}else s&&console.error("WebSocket message not sent, WebSocket not connected:",N)},[]),E=o.useCallback((N,n)=>{const T=`<span style="background-color: #5c0e91; color: white; padding: 1px 5px; font-size: 12px; border-radius: 3px;">${N}</span>`;b(_=>[..._,T+' <span style="color: var(--main-log-color);">'+n+"</span>"])},[]),I=o.useCallback((N,n)=>{a(N),l(n),E("WebSocket",`Filtering by log level "${N}" and log search "${n}"`)},[E]),Y=o.useCallback(N=>{s&&console.log("WebSocket addListener:",N),u.current=[...u.current,N],s&&console.log("WebSocket addListener total listeners:",u.current.length)},[]),me=o.useCallback(N=>{s&&console.log("WebSocket removeListener:",N),u.current=u.current.filter(n=>n!==N),s&&console.log("WebSocket removeListener total listeners:",u.current.length)},[]),Me=o.useCallback(()=>{j===""||j===null||j===void 0||(E("WebSocket",`Connecting to WebSocket: ${j}`),z.current=new WebSocket(j),z.current.onmessage=N=>{h||L(!0);try{const n=JSON.parse(N.data);if(n.id===void 0)return;if(n.error&&s&&console.error("WebSocket error message:",n),n.id===f.current&&n.src==="Matterbridge"&&n.dst==="Frontend"&&n.response==="pong"){s&&console.log("WebSocket pong response message:",n,"listeners:",u.current.length),R.current&&clearTimeout(R.current),u.current.forEach(_=>_(n));return}if(n.id===we.RefreshRequired){s&&console.log("WebSocket WS_ID_REFRESH_REQUIRED message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.RestartRequired){s&&console.log("WebSocket WS_ID_RESTART_REQUIRED message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.RestartNotRequired){s&&console.log("WebSocket WS_ID_RESTART_NOT_REQUIRED message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.CpuUpdate){s&&console.log("WebSocket WS_ID_CPU_UPDATE message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.MemoryUpdate){s&&console.log("WebSocket WS_ID_MEMORY_UPDATE message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.UptimeUpdate){s&&console.log("WebSocket WS_ID_UPTIME_UPDATE message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.Snackbar&&n.params&&n.params.message){s&&console.log("WebSocket WS_ID_SNACKBAR message:",n,"listeners:",u.current.length),V(n.params.message,n.params.timeout,n.params.severity);return}else if(n.id===we.CloseSnackbar&&n.params&&n.params.message){s&&console.log("WebSocket WS_ID_CLOSE_SNACKBAR message:",n,"listeners:",u.current.length),M(n.params.message);return}else if(n.id===we.ShellySysUpdate){s&&console.log("WebSocket WS_ID_SHELLY_SYS_UPDATE message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id===we.ShellyMainUpdate){s&&console.log("WebSocket WS_ID_SHELLY_MAIN_UPDATE message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}else if(n.id!==we.Log){s&&console.log("WebSocket message:",n,"listeners:",u.current.length),u.current.forEach(_=>_(n));return}if(!n.params||!n.params.level||!n.params.time||!n.params.name||!n.params.message||["debug","info","notice","warn","error","fatal"].includes(n.params.level)&&(m.current==="info"&&n.params.level==="debug"||m.current==="notice"&&(n.params.level==="debug"||n.params.level==="info")||m.current==="warn"&&(n.params.level==="debug"||n.params.level==="info"||n.params.level==="notice")||m.current==="error"&&(n.params.level==="debug"||n.params.level==="info"||n.params.level==="notice"||n.params.level==="warn")||m.current==="fatal"&&(n.params.level==="debug"||n.params.level==="info"||n.params.level==="notice"||n.params.level==="warn"||n.params.level==="error"))||H.current!=="*"&&H.current!==""&&!n.params.message.toLowerCase().includes(H.current.toLowerCase())&&!n.params.name.toLowerCase().includes(H.current.toLowerCase())||n.params.name==="Commissioning"&&n.params.message.includes("is uncommissioned"))return;b(_=>{const ae=`<span style="color: #505050;">[${n.params?.time}]</span>`,ce=ve=>{switch(ve?.toLowerCase()){case"debug":return"gray";case"info":return"#267fb7";case"notice":return"green";case"warn":return"#e9db18";case"error":return"red";case"fatal":return"#ff0000";case"spawn":return"#ff00d0";default:return"lightblue"}},B=ve=>{switch(ve?.toLowerCase()){case"warn":return"black";default:return"white"}},ge=`${`<span style="background-color: ${ce(n.params?.level)}; color: ${B(n.params?.level)}; padding: 1px 5px; font-size: 12px; border-radius: 3px;">${n.params?.level}</span>`} ${ae} <span style="color: #09516d;">[${n.params?.name}]</span> <span style="color: var(--main-log-color);">${n.params?.message}</span>`,oe=[..._,ge];return oe.length>t?oe.slice(t/10):oe})}catch(n){console.error(`WebSocketUse error parsing message: ${n}`)}},z.current.onopen=()=>{s&&console.log(`WebSocket: Connected to WebSocket: ${j}`),E("WebSocket",`Connected to WebSocket: ${j}`),L(!0),O(),v.current=1,C.current=setTimeout(()=>{k.current=setInterval(()=>{p({id:f.current,method:"ping",src:"Frontend",dst:"Matterbridge",params:{}}),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{s&&console.error(`WebSocketUse: No pong response received from WebSocket: ${j}`),E("WebSocket",`No pong response received from WebSocket: ${j}`),L(!1)},1e3*de)},1e3*q)},1e3*xe)},z.current.onclose=()=>{s&&console.error(`WebSocket: Disconnected from WebSocket ${x?"with Ingress":""}: ${j}`),E("WebSocket",`Disconnected from WebSocket: ${j}`),L(!1),O(),C.current&&clearTimeout(C.current),R.current&&clearTimeout(R.current),k.current&&clearInterval(k.current),E("WebSocket",`Reconnecting (attempt ${v.current} of ${w}) to WebSocket${x?" (Ingress)":""}: ${j}`),x?setTimeout(U,5e3):v.current===1?U():v.current<w?setTimeout(U,1e3*v.current):E("WebSocket",`Reconnect attempts exceeded limit of ${w} retries, refresh the page to reconnect to: ${j}`),v.current=v.current+1},z.current.onerror=N=>{s&&console.error(`WebSocket: WebSocket error connecting to ${j}:`,N),E("WebSocket",`WebSocket error connecting to ${j}`)})},[j]),U=o.useCallback(()=>{s&&console.log(`WebSocket attemptReconnect ${v.current}/${w} to:`,j),Me()},[Me]);o.useEffect(()=>(Me(),()=>{z.current&&z.current.readyState===WebSocket.OPEN&&z.current.close()}),[Me]);const D=o.useMemo(()=>({messages:g,maxMessages:t,autoScroll:y,setMessages:b,setLogFilters:I,setMaxMessages:d,setAutoScroll:W}),[g,b,I]),P=o.useMemo(()=>({maxMessages:t,autoScroll:y,logFilterLevel:c,logFilterSearch:i,setMessages:b,setLogFilters:I,setMaxMessages:d,setAutoScroll:W,online:h,retry:v.current,getUniqueId:S,addListener:Y,removeListener:me,sendMessage:p,logMessage:E}),[t,y,b,I,d,W,h,v.current,Y,me,p,E]);return e.jsx(ir.Provider,{value:D,children:e.jsx(be.Provider,{value:P,children:r})})}function Jo(){const{showSnackbarMessage:r,showConfirmCancelDialog:c}=o.useContext(nt),{online:a,sendMessage:i,logMessage:l,addListener:g,removeListener:b,getUniqueId:t}=o.useContext(be),[d,y]=o.useState(!1),[W,h]=o.useState(!1),[L,V]=o.useState(!1),[M,O]=o.useState(!1),[u,z]=o.useState(null),v=o.useRef(t()),[f,k]=o.useState(null),[R,C]=o.useState(null),[m,H]=o.useState(null),[j,x]=o.useState(null),[w,q]=o.useState(null),de=()=>{window.open("https://www.buymeacoffee.com/luligugithub","_blank")},xe=()=>{window.open("https://github.com/Luligu/matterbridge/blob/main/README.md","_blank")},S=()=>{u?.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?window.open("https://github.com/Luligu/matterbridge/blob/dev/CHANGELOG.md","_blank"):window.open("https://github.com/Luligu/matterbridge/blob/main/CHANGELOG.md","_blank")},p=()=>{window.open("https://discord.gg/QX58CDe6hd","_blank")},E=()=>{window.open("https://github.com/Luligu/matterbridge","_blank")},I=()=>{i({id:v.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge",restart:!0}})},Y=()=>{i({id:v.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge@dev",restart:!0}})},me=()=>{i({id:v.current,sender:"Header",method:"/api/checkupdates",src:"Frontend",dst:"Matterbridge",params:{}})},Me=()=>{s&&console.log("Header: handleShellySystemUpdateClick"),l("Matterbridge","Installing system updates..."),i({id:v.current,sender:"Header",method:"/api/shellysysupdate",src:"Frontend",dst:"Matterbridge",params:{}})},U=()=>{s&&console.log("Header: handleShellyMainUpdateClick"),l("Matterbridge","Installing software updates..."),i({id:v.current,sender:"Header",method:"/api/shellymainupdate",src:"Frontend",dst:"Matterbridge",params:{}})},D=()=>{s&&console.log("Header: handleShellyCreateSystemLog"),i({id:v.current,sender:"Header",method:"/api/shellycreatesystemlog",src:"Frontend",dst:"Matterbridge",params:{}})},P=()=>{s&&console.log("Header: handleShellyDownloadSystemLog"),l("Matterbridge","Downloading Shelly system log..."),r("Downloading Shelly system log...",5),window.location.href="./api/shellydownloadsystemlog"},N=()=>{u?.matterbridgeInformation.restartMode===""?i({id:v.current,sender:"Header",method:"/api/restart",src:"Frontend",dst:"Matterbridge",params:{}}):i({id:v.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},n=()=>{i({id:v.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},T=()=>{i({id:v.current,sender:"Header",method:"/api/reboot",src:"Frontend",dst:"Matterbridge",params:{}})},_=()=>{i({id:v.current,sender:"Header",method:"/api/softreset",src:"Frontend",dst:"Matterbridge",params:{}})},ae=()=>{i({id:v.current,sender:"Header",method:"/api/hardreset",src:"Frontend",dst:"Matterbridge",params:{}})},ce=Q=>{k(Q.currentTarget)},B=Q=>{s&&console.log("Header: handleMenuClose",Q),k(null),Q==="download-mblog"?(l("Matterbridge","Downloading matterbridge log..."),r("Downloading matterbridge log...",5),window.location.href="./api/download-mblog"):Q==="download-mjlog"?(l("Matterbridge","Downloading matter log..."),r("Downloading matter log...",5),window.location.href="./api/download-mjlog"):Q==="view-mblog"?(l("Matterbridge","Loading matterbridge log..."),r("Loading matterbridge log...",5),window.location.href="./api/view-mblog"):Q==="view-mjlog"?(l("Matterbridge","Loading matter log..."),r("Loading matter log...",5),window.location.href="./api/view-mjlog"):Q==="view-shellylog"?(l("Matterbridge","Loading shelly system log..."),r("Loading shelly system log...",5),window.location.href="./api/shellyviewsystemlog"):Q==="download-mbstorage"?(l("Matterbridge","Downloading matterbridge storage..."),r("Downloading matterbridge storage...",5),window.location.href="./api/download-mbstorage"):Q==="download-pluginstorage"?(l("Matterbridge","Downloading matterbridge plugins storage..."),r("Downloading matterbridge plugins storage...",5),window.location.href="./api/download-pluginstorage"):Q==="download-pluginconfig"?(l("Matterbridge","Downloading matterbridge plugins config..."),r("Downloading matterbridge plugins config...",5),window.location.href="./api/download-pluginconfig"):Q==="download-mjstorage"?(l("Matterbridge","Downloading matter storage..."),r("Downloading matter storage...",5),window.location.href="./api/download-mjstorage"):Q==="download-backup"?(l("Matterbridge","Downloading backup..."),r("Downloading backup...",10),window.location.href="./api/download-backup"):Q==="update"?I():Q==="updatedev"?Y():Q==="updatecheck"?me():Q==="shelly-sys-update"?Me():Q==="shelly-main-update"?U():Q==="shelly-create-system-log"?D():Q==="shelly-download-system-log"?P():Q==="softreset"?_():Q==="hardreset"?ae():Q==="restart"?N():Q==="shutdown"?n():Q==="reboot"?T():Q==="create-backup"?i({id:v.current,sender:"Header",method:"/api/create-backup",src:"Frontend",dst:"Matterbridge",params:{}}):Q==="unregister"?i({id:v.current,sender:"Header",method:"/api/unregister",src:"Frontend",dst:"Matterbridge",params:{}}):Q==="reset"?i({id:v.current,sender:"Header",method:"/api/reset",src:"Frontend",dst:"Matterbridge",params:{}}):Q==="factoryreset"&&i({id:v.current,sender:"Header",method:"/api/factoryreset",src:"Frontend",dst:"Matterbridge",params:{}})},le=Q=>{s&&console.log("Header: handleMenuCloseCancel:",Q),k(null)},ge=Q=>{C(Q.currentTarget)},oe=()=>{C(null)},ve=Q=>{H(Q.currentTarget)},ie=()=>{H(null)},he=Q=>{x(Q.currentTarget)},X=()=>{x(null)},ue=Q=>{q(Q.currentTarget)},ye=()=>{q(null)},Ge=()=>{ei(),s&&console.log("Matterbridge logo clicked: debug is now",s)};return o.useEffect(()=>{const Q=ee=>{ee.src==="Matterbridge"&&ee.dst==="Frontend"&&(Ve(ee)&&ee.method==="/api/settings"&&ee.id===v.current&&(s&&console.log("Header received settings:",ee.response),z(ee.response),y(ee.response.matterbridgeInformation.restartRequired||ee.response.matterbridgeInformation.fixedRestartRequired),h(ee.response.matterbridgeInformation.fixedRestartRequired),V(ee.response.matterbridgeInformation.updateRequired)),fe(ee)&&ee.method==="refresh_required"&&ee.params.changed==="settings"&&(s&&console.log(`Header received refresh_required: changed=${ee.params.changed} and sending /api/settings request`),i({id:v.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),fe(ee)&&ee.method==="restart_required"&&(s&&console.log(`Header received restart_required with fixed: ${ee.params.fixed}`),y(!0),ee.params.fixed===!0&&h(!0)),fe(ee)&&ee.method==="restart_not_required"&&(s&&console.log("Header received restart_not_required"),y(!1)),fe(ee)&&ee.method==="update_required"&&(s&&console.log("Header received update_required"),V(!0)),fe(ee)&&ee.method==="update_required_dev"&&(s&&console.log("Header received update_required_dev"),O(!0)),fe(ee)&&ee.id===we.ShellySysUpdate&&(s&&console.log("Header received WS_ID_SHELLY_SYS_UPDATE:"),z(We=>We?{matterbridgeInformation:{...We.matterbridgeInformation,shellySysUpdate:ee.params.available},systemInformation:We.systemInformation}:null)),fe(ee)&&ee.id===we.ShellyMainUpdate&&(s&&console.log("Header received WS_ID_SHELLY_MAIN_UPDATE:"),z(We=>We?{matterbridgeInformation:{...We.matterbridgeInformation,shellyMainUpdate:ee.params.available},systemInformation:We.systemInformation}:null)))};return g(Q),s&&console.log(`Header added WebSocket listener id ${v.current}`),()=>{b(Q),s&&console.log("Header removed WebSocket listener")}},[g,b,i,r]),o.useEffect(()=>{a&&(s&&console.log("Header sending /api/settings requests"),i({id:v.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[a,i]),s&&console.log("Header rendering..."),!a||!u?null:e.jsxs("div",{className:"header",children:[e.jsxs("div",{className:"sub-header",children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"30px"},onClick:Ge}),e.jsx("h2",{style:{fontSize:"22px",color:"var(--main-icon-color)",margin:"0px"},children:"Matterbridge"}),e.jsxs("nav",{children:[e.jsx(lt,{to:"/",className:"nav-link",children:"Home"}),e.jsx(lt,{to:"/devices",className:"nav-link",children:"Devices"}),e.jsx(lt,{to:"/log",className:"nav-link",children:"Logs"}),e.jsx(lt,{to:"/settings",className:"nav-link",children:"Settings"})]})]}),e.jsxs("div",{className:"sub-header",children:[!u.matterbridgeInformation.readOnly&&L&&e.jsx($,{title:"New Matterbridge version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:I,children:["Update to v.",u.matterbridgeInformation.matterbridgeLatestVersion]})}),!u.matterbridgeInformation.readOnly&&M&&e.jsx($,{title:"New Matterbridge dev version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:Y,children:["Update to new dev v.",u.matterbridgeInformation.matterbridgeDevVersion.split("-dev-")[0]]})}),!u.matterbridgeInformation.readOnly&&e.jsx($,{title:"Matterbridge version, click to see the changelog",children:e.jsxs("span",{className:"status-information",onClick:S,children:["v.",u.matterbridgeInformation.matterbridgeVersion]})}),u.matterbridgeInformation.shellyBoard&&e.jsx("img",{src:"Shelly.svg",alt:"Shelly Icon",style:{height:"30px",padding:"0px",margin:"0px",marginRight:"30px"}}),u.matterbridgeInformation.bridgeMode!==""&&u.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Bridge mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:u.matterbridgeInformation.bridgeMode})}):null,u.matterbridgeInformation.restartMode!==""&&u.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Restart mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:u.matterbridgeInformation.restartMode})}):null,u.matterbridgeInformation.profile&&u.matterbridgeInformation.profile!==""&&u.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Current profile",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:u.matterbridgeInformation.profile})}):null]}),e.jsxs("div",{className:"sub-header",style:{gap:"5px"},children:[u.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Matterbridge discord group",children:e.jsx("img",{src:"discord.svg",alt:"Discord Logo",style:{cursor:"pointer",height:"25px"},onClick:p})}):null,u.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Give a star to Matterbridge",children:e.jsx(J,{style:{color:"#FFD700",margin:"0",padding:"0"},onClick:E,children:e.jsx(Mr,{})})}):null,u.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Sponsor Matterbridge",children:e.jsx(J,{style:{color:"#b6409c",margin:"0",padding:"0"},onClick:de,children:e.jsx(Zt,{})})}):null,e.jsx($,{title:"Matterbridge help",children:e.jsx(J,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:xe,children:e.jsx(kr,{})})}),e.jsx($,{title:"Matterbridge changelog",children:e.jsx(J,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:S,children:e.jsx(er,{})})}),u.matterbridgeInformation&&!u.matterbridgeInformation.readOnly&&e.jsx($,{title:"Update matterbridge to latest version",children:e.jsx(J,{style:{color:L?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:I,children:e.jsx(_e,{})})}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&u.matterbridgeInformation.shellySysUpdate&&e.jsx($,{title:"Shelly system update",children:e.jsx(J,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:Me,children:e.jsx(_e,{})})}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&u.matterbridgeInformation.shellyMainUpdate&&e.jsx($,{title:"Shelly software update",children:e.jsx(J,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:U,children:e.jsx(_e,{})})}),e.jsx($,{title:"Restart matterbridge",children:e.jsx(J,{style:{color:d||W?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:N,children:e.jsx(yt,{})})}),u.matterbridgeInformation.restartMode===""?e.jsx($,{title:"Shut down matterbridge",children:e.jsx(J,{style:{color:d||W?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:n,children:e.jsx(qe,{})})}):null,e.jsx($,{title:"Download, backup and more",children:e.jsx(J,{onClick:ce,children:e.jsx(Ir,{style:{color:"var(--main-icon-color)"}})})}),e.jsxs(rt,{id:"command-menu",anchorEl:f,keepMounted:!0,open:!!f,onClose:()=>B(""),children:[u.matterbridgeInformation&&!u.matterbridgeInformation.readOnly&&e.jsxs(F,{onClick:()=>B("update"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Install latest stable",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&!u.matterbridgeInformation.readOnly&&e.jsxs(F,{onClick:()=>B("updatedev"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Install latest dev",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&!u.matterbridgeInformation.readOnly&&e.jsxs(F,{onClick:()=>B("updatecheck"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Check for updates",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&u.matterbridgeInformation.shellySysUpdate&&e.jsxs(F,{onClick:()=>B("shelly-sys-update"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shelly system update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&u.matterbridgeInformation.shellyMainUpdate&&e.jsxs(F,{onClick:()=>B("shelly-main-update"),children:[e.jsx(K,{children:e.jsx(_e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shelly software update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>B("restart"),children:[e.jsx(K,{children:e.jsx(yt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Restart",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation.restartMode===""?e.jsxs(F,{onClick:()=>B("shutdown"),children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shutdown",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}):null,u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&e.jsxs(F,{onClick:()=>{c("Reboot","Are you sure you want to reboot the Shelly board?","reboot",B,le)},children:[e.jsx(K,{children:e.jsx(yt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reboot...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsx(dt,{}),e.jsxs(F,{onClick:ve,children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"View",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-view",anchorEl:m,keepMounted:!0,open:!!m,onClose:ie,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(F,{onClick:()=>{B("view-mblog"),ie()},children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("view-mjlog"),ie()},children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&e.jsxs(F,{onClick:()=>{B("view-shellylog"),ie()},children:[e.jsx(K,{children:e.jsx(ct,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(dt,{}),e.jsxs(F,{onClick:he,children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Download",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-download",anchorEl:j,keepMounted:!0,open:!!j,onClose:X,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(F,{onClick:()=>{B("download-mbstorage"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("download-pluginstorage"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge plugins storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("download-pluginconfig"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge plugins config",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("download-mblog"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("download-mjstorage"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matter storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("download-mjlog"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&e.jsxs(F,{onClick:()=>{B("shelly-create-system-log"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Create Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&e.jsxs(F,{onClick:()=>{B("shelly-download-system-log"),X()},children:[e.jsx(K,{children:e.jsx($e,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Download Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(dt,{}),e.jsxs(F,{onClick:ge,children:[e.jsx(K,{children:e.jsx(Nt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-backup",anchorEl:R,keepMounted:!0,open:!!R,onClose:oe,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(F,{onClick:()=>{B("create-backup"),oe()},children:[e.jsx(K,{children:e.jsx(Nt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Create backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{B("download-backup"),oe()},children:[e.jsx(K,{children:e.jsx(Nt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Download backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(dt,{}),e.jsxs(F,{onClick:ue,children:[e.jsx(K,{children:e.jsx(Dr,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(rt,{id:"sub-menu-reset",anchorEl:w,keepMounted:!0,open:!!w,onClose:ye,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(F,{onClick:()=>{ye(),c("Reset all devices and shutdown","Are you sure you want to unregister all devices? This will temporarily remove all devices from the controller and you may loose the controller configuration.","unregister",B,le)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset all devices...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(F,{onClick:()=>{ye(),c("Reset commissioning and shutdown","Are you sure you want to reset the commissioning? You will have to manually remove Matterbridge from the controller.","reset",B,le)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset commissioning...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),!u.matterbridgeInformation.readOnly&&e.jsxs(F,{onClick:()=>{ye(),c("Factory reset and shutdown","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","factoryreset",B,le)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&e.jsxs(F,{onClick:()=>{ye(),c("Network reset","Are you sure you want to factory reset the network parameters?","softreset",B,le)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Reset network...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),u.matterbridgeInformation&&u.matterbridgeInformation.shellyBoard&&e.jsxs(F,{onClick:()=>{ye(),c("Factory reset","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","hardreset",B,le)},children:[e.jsx(K,{children:e.jsx(qe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(re,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]})]})]})]})}const Qo=o.memo(Jo),Go=()=>"ontouchstart"in window||typeof window.DocumentTouch<"u"&&document instanceof window.DocumentTouch?(s&&console.log("WebSocketLogs detectTouchscreen = true"),!0):(s&&console.log("WebSocketLogs detectTouchscreen = false"),!1);function Ko(){const{messages:r,autoScroll:c}=o.useContext(ir),[a,i]=o.useState(!1),l=o.useRef(null),g=o.useMemo(()=>Go(),[]),b=d=>i(!0),t=d=>i(!1);return o.useEffect(()=>{s&&console.log(`WebSocketLogs autoScroll: ${c} isHovering: ${a}`),c&&!a&&!g&&l.current?.scrollIntoView({behavior:"smooth"})},[r,a,c,g]),e.jsx("div",{style:{margin:"0px",padding:"0px"},children:e.jsxs("ul",{style:{margin:"0px",padding:"0px"},onMouseEnter:b,onMouseLeave:t,children:[r.map((d,y)=>e.jsx("li",{style:{wordWrap:"break-word",maxHeight:"200px",overflow:"hidden"},dangerouslySetInnerHTML:{__html:d}},y)),e.jsx("div",{ref:l})]})})}const ar=o.memo(Ko);function Qe(){const{retry:r}=o.useContext(be),c=()=>{window.location.reload()};return e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",fontSize:"20px",flexDirection:"column",color:"var(--main-text-color)",height:"100vh",backgroundColor:"var(--main-bg-color)"},children:e.jsx(Z,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:r<100?e.jsxs(e.Fragment,{children:[e.jsx(Nr,{style:{color:"var(--primary-color)"}}),e.jsxs("div",{style:{marginTop:"20px",color:"var(--primary-color)"},children:["Reconnecting to Matterbridge ","(attempt "+r+")","..."]})]}):e.jsxs("div",{style:{marginTop:"20px",color:"var(--primary-color)",textAlign:"center"},children:["Unable to connect to Matterbridge after multiple attempts.",e.jsx("br",{}),"Please check your network connection.",e.jsx("br",{}),e.jsx(ne,{variant:"contained",color:"primary",onClick:c,style:{marginTop:"20px"},children:"Refresh the Page"})]})})})}function Yo({value:r,maxChars:c}){let a=r;if(r.length>c&&c>3){const i=c-3,l=r.substring(0,Math.ceil(i/2)),g=r.substring(r.length-Math.floor(i/2),r.length);a=`${l} … ${g}`}return r!==a?e.jsx($,{title:r,placement:"top",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[0,12]}}]}},children:e.jsx("span",{children:a})}):e.jsx("span",{children:a})}function Xo({systemInfo:r,compact:c}){const[a,i]=o.useState(r),{sendMessage:l,addListener:g,removeListener:b}=o.useContext(be);if(s&&console.log("SystemInfoTable:",a,"compact:",c),r&&c&&a.totalMemory&&a.freeMemory){const t=a.totalMemory,d=a.freeMemory;a.freeMemory=`${d} / ${t}`,a.totalMemory=""}if(r&&c&&a.heapTotal&&a.heapUsed){const t=a.heapTotal,d=a.heapUsed;a.heapUsed=`${d} / ${t}`,a.heapTotal=""}if(r&&c&&a.osRelease&&a.osType){const t=a.osType,d=a.osRelease;a.osType=`${t} (${d})`,a.osRelease=""}if(r&&c&&a.osArch&&a.osPlatform){const t=a.osPlatform,d=a.osArch;a.osPlatform=`${t} (${d})`,a.osArch=""}return o.useEffect(()=>{const t=d=>{d.src==="Matterbridge"&&d.dst==="Frontend"&&(fe(d)&&d.method==="memory_update"&&d.params&&d.params.totalMemory&&d.params.freeMemory&&d.params.heapTotal&&d.params.heapUsed&&d.params.rss&&(s&&console.log("SystemInfoTable received memory_update",d),(a.totalMemory!==d.params?.totalMemory||a.freeMemory!==d.params?.freeMemory||a.heapTotal!==d.params?.heapTotal||a.heapUsed!==d.params?.heapUsed||a.rss!==d.params?.rss)&&i(y=>({...y,totalMemory:d.params?.totalMemory?d.params.totalMemory:"",freeMemory:d.params?.freeMemory?d.params.freeMemory:"",heapTotal:d.params?.heapTotal?d.params.heapTotal:"",heapUsed:d.params?.heapUsed?d.params.heapUsed:"",rss:d.params?.rss?d.params.rss:""}))),fe(d)&&d.method==="cpu_update"&&d.params&&d.params.cpuUsage&&(s&&console.log("SystemInfoTable received cpu_update",d),a.cpuUsage!==(d.params?.cpuUsage?d.params.cpuUsage.toFixed(2)+" %":"")&&i(y=>({...y,cpuUsage:d.params?.cpuUsage?d.params.cpuUsage.toFixed(2)+" %":""}))),fe(d)&&d.method==="uptime_update"&&d.params&&d.params.systemUptime&&d.params.processUptime&&(s&&console.log("SystemInfoTable received uptime_update",d),(a.systemUptime!==d.params?.systemUptime||a.processUptime!==d.params?.processUptime)&&i(y=>({...y,systemUptime:d.params?.systemUptime?d.params.systemUptime:"",processUptime:d.params?.processUptime?d.params.processUptime:""}))))};return s&&console.log("SystemInfoTable useEffect WebSocketMessage mounting"),g(t),s&&console.log("SystemInfoTable useEffect WebSocketMessage mounted"),()=>{s&&console.log("SystemInfoTable useEffect WebSocketMessage unmounting"),b(t),s&&console.log("SystemInfoTable useEffect WebSocketMessage unmounted")}},[g,a.cpuUsage,a.freeMemory,a.heapTotal,a.heapUsed,a.processUptime,a.rss,a.systemUptime,a.totalMemory,b,l]),a?(s&&console.log("SystemInfoTable rendering..."),e.jsxs("div",{className:"MbfWindowDiv",style:{minWidth:"302px",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"System Information"})}),e.jsx("div",{className:"MbfWindowDivTable",children:e.jsx("table",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx("tbody",{style:{border:"none",borderCollapse:"collapse"},children:Object.entries(a).filter(([t,d])=>d!==void 0&&d!=="").map(([t,d],y)=>e.jsxs("tr",{className:y%2===0?"table-content-even":"table-content-odd",style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:t}),e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx(Yo,{value:typeof d!="string"?d.toString():d,maxChars:25})})]},t))})})})]})):null}const Zo=o.memo(Xo),Bt={margin:"0px",padding:"0px",color:"var(--div-text-color)",transition:"color 0.2s ease","& svg":{display:"block"},"& svg path":{fill:"var(--div-text-color)",transition:"fill 0.2s ease"},"&:hover":{color:"var(--primary-color)"},"&:hover svg path":{fill:"var(--primary-color)"},"&:focus-visible":{outline:"2px solid var(--primary-color)",outlineOffset:"2px"}},en=r=>{if(!r)return"";const c=r.toString().replace(/[^0-9]/g,"");if(c.length<5)return c;const a=c.slice(0,4),i=c.slice(4,7),l=c.slice(7,11);return[a,i,l].filter(Boolean).join("-")};function tn({id:r}){const{online:c,sendMessage:a,addListener:i,removeListener:l,getUniqueId:g}=o.useContext(be),[b,t]=o.useState(null),[d,y]=o.useState(null),W=o.useRef(null),h=o.useRef(g()),{showConfirmCancelDialog:L}=o.useContext(nt);o.useEffect(()=>{s&&console.log(`QRDiv received storeId update "${r}"`),r&&(s&&console.log(`QRDiv sending data request for storeId "${r}"`),t(r),a({id:h.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:r,server:!0}}))},[r]),o.useEffect(()=>{const v=f=>{f.src==="Matterbridge"&&f.dst==="Frontend"&&fe(f)&&f.id===we.RefreshRequired&&f.params.changed==="matter"&&f.params.matter&&(s&&console.log(`QRDiv received refresh_required: changed=${f.params.changed} for storeId "${f.params.matter.id}":`,f.params.matter),b===f.params.matter.id&&(s&&console.log(`QRDiv received refresh_required/matter: setting matter data for storeId "${f.params.matter.id}":`,f.params.matter),W.current&&clearTimeout(W.current),f.params.matter.advertising&&f.params.matter.advertiseTime&&f.params.matter.advertiseTime+9e5<=Date.now()&&(f.params.matter.advertising=!1),y(f.params.matter),f.params.matter.advertising&&(s&&console.log(`QRDiv setting matter advertise timeout for storeId "${f.params.matter.id}":`,f.params.matter.advertiseTime+9e5-Date.now()),W.current=setTimeout(()=>{W.current&&clearTimeout(W.current),s&&console.log(`QRDiv clearing advertising state for storeId "${b}" after 15 minutes`),y(k=>k&&{...k,advertising:!1})},f.params.matter.advertiseTime+9e5-Date.now()))))};return i(v),s&&console.log("QRDiv webSocket effect mounted"),()=>{l(v),W.current&&clearTimeout(W.current),s&&console.log("QRDiv webSocket effect unmounted")}},[b]);const V=()=>{s&&console.log(`QRDiv sent matter startCommission for node "${d?.id}"`),d&&a({id:h.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,startCommission:!0}})},M=()=>{s&&console.log(`QRDiv sent matter stopCommission for node "${d?.id}"`),d&&a({id:h.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,stopCommission:!0}})},O=()=>{s&&console.log(`QRDiv sent matter advertise for node "${d?.id}"`),d&&a({id:h.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,advertise:!0}})},u=v=>{s&&console.log(`QRDiv sent matter removeFabric for node "${d?.id}" and fabricIndex ${v}`),d&&a({id:h.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,removeFabric:v}})},z=async()=>{if(!d||!d.manualPairingCode)return;const v=d.manualPairingCode.toString();try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(v);else{const f=document.createElement("textarea");f.value=v,f.style.position="fixed",f.style.opacity="0",document.body.appendChild(f),f.focus(),f.select(),document.execCommand("copy"),document.body.removeChild(f)}s&&console.log("Manual pairing code copied to clipboard")}catch(f){console.error("Failed to copy manual pairing code",f)}};return!d||!c?(s&&console.log("QRDiv rendering undefined state"),null):d.online?d.advertising&&d.qrPairingCode&&d.manualPairingCode?(s&&console.log("QRDiv rendering advertising state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"QR pairing code"}),e.jsxs("div",{className:"MbfWindowHeaderFooterIcons",children:[e.jsx(J,{"aria-label":"send advertising",size:"small",onClick:O,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(te,{path:At,size:"22px"})})}),e.jsx(J,{"aria-label":"stop pairing",size:"small",onClick:M,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Turn off pairing",arrow:!0,children:e.jsx(te,{path:go,size:"22px"})})})]})]}),e.jsx("p",{className:"MbfWindowHeaderText",style:{overflow:"hidden",maxWidth:"280px",textOverflow:"ellipsis",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:b}),e.jsx(mo,{value:d.qrPairingCode,size:256,level:"M",fgColor:"var(--div-text-color)",bgColor:"var(--div-bg-color)",style:{margin:"20px"}}),e.jsxs("div",{className:"MbfWindowFooter",style:{justifyContent:"space-between"},children:[e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Manual pairing code: ",en(d.manualPairingCode)]}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx($,{title:"Copy manual pairing code",arrow:!0,children:e.jsx(J,{"aria-label":"copy manual pairing code",size:"small",onClick:z,sx:Bt,children:e.jsx(te,{path:ho,size:.85})})})})]})]})):d.commissioned&&d.fabricInformations&&d.sessionInformations?(s&&console.log("QRDiv rendering commissioned state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Paired fabrics"}),e.jsxs("div",{className:"MbfWindowHeaderFooterIcons",children:[e.jsx(J,{"aria-label":"send advertising",size:"small",onClick:O,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(te,{path:At,size:"22px"})})}),e.jsx(J,{"aria-label":"start pairing",size:"small",onClick:V,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{title:"Turn on pairing",arrow:!0,children:e.jsx(te,{path:Ut,size:"22px"})})})]})]}),e.jsxs("div",{className:"MbfWindowBodyColumn",style:{paddingTop:"0px"},children:[e.jsx("p",{className:"MbfWindowHeaderText thin-scroll",style:{overflowX:"auto",maxWidth:"280px",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:b}),d.fabricInformations.map((v,f)=>e.jsxs("div",{style:{margin:"0px",padding:"10px",gap:"0px",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)",textAlign:"left",fontSize:"14px"},children:[e.jsxs("div",{style:{marginLeft:"20px",marginBottom:"10px",display:"flex",flexDirection:"row",justifyContent:"space-between",gap:"20px",alignItems:"center"},children:[e.jsxs("p",{className:"status-blue",style:{margin:"0px",padding:"3px 10px",width:"200px",fontSize:"14px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)"},children:["Fabric: ",v.fabricIndex]}),e.jsx($,{title:"Remove the fabric. You will also need to remove it from the controller.",arrow:!0,children:e.jsx(J,{"aria-label":"remove the fabric",size:"small",onClick:()=>L("Remove fabric","Are you sure you want to remove this fabric? You will also need to remove it from the controller.","RemoveFabric",()=>u(v.fabricIndex),()=>{}),sx:{...Bt,padding:"2px"},children:e.jsx(te,{path:fo,size:1})})})]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Vendor: ",v.rootVendorId," ",v.rootVendorName]}),v.label!==""&&e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Label: ",v.label]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Sessions: ",d.sessionInformations?d.sessionInformations.filter(k=>k.fabric?.fabricIndex===v.fabricIndex&&k.isPeerActive===!0).length:"0"," ","subscriptions: ",d.sessionInformations?d.sessionInformations.filter(k=>k.fabric?.fabricIndex===v.fabricIndex&&k.isPeerActive===!0&&k.numberOfActiveSubscriptions>0).length:"0"]})]},f))]}),e.jsx("div",{className:"MbfWindowFooter",children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Serial number: ",d.serialNumber]})})]})):!d.commissioned&&!d.advertising?(s&&console.log("QRDiv rendering not commissioned and not advertising state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsx("div",{className:"MbfWindowHeader",style:{height:"30px"},children:e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"QR pairing code"})}),e.jsx("p",{className:"MbfWindowHeaderText thin-scroll",style:{overflowX:"auto",maxWidth:"280px",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:b}),e.jsx(ne,{onClick:V,endIcon:e.jsx(te,{path:Ut,size:1}),style:{margin:"20px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:"Turn on pairing"}),e.jsx("div",{className:"MbfWindowFooter",children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Serial number: ",d.serialNumber]})})]})):(s&&console.log("QRDiv rendering unknown state"),null):(s&&console.log("QRDiv rendering offline state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Server node"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons"})]}),e.jsx("p",{className:"MbfWindowHeaderText",style:{overflow:"hidden",maxWidth:"280px",textOverflow:"ellipsis",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:b}),e.jsx("p",{style:{textAlign:"center",fontSize:"14px",fontWeight:"bold"},children:"Server offline: restart to commission"}),e.jsx("div",{className:"MbfWindowFooter",children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Serial number: ",d.serialNumber]})})]}))}const rn=o.memo(tn);function on(){const{logMessage:r,sendMessage:c,getUniqueId:a}=o.useContext(be),[i,l]=o.useState("matterbridge-"),[g,b]=o.useState(!1),[t,d]=o.useState(null),y=o.useRef(a()),W=f=>{f.preventDefault(),b(!0)},h=()=>{b(!1)},L=f=>{f.preventDefault(),b(!1);const k=f.dataTransfer.files[0];if(k){r("Plugins",`Installing package ${k.name}. Please wait...`);const R=new FormData;R.append("file",k),R.append("filename",k.name),fetch("./api/uploadpackage",{method:"POST",body:R}).then(C=>C.text()).then(C=>{r("Plugins",`Server response: ${C}`)}).catch(C=>{console.error("Error uploading plugin file:",C),r("Plugins",`Error installing package ${C}`)})}},V=f=>{const k=f.target.files&&f.target.files[0];if(k){r("Plugins",`Uploading package ${k.name}`);const R=new FormData;R.append("file",k),R.append("filename",k.name),fetch("./api/uploadpackage",{method:"POST",body:R}).then(C=>C.text()).then(C=>{r("Plugins",`Server response: ${C}`)}).catch(C=>{console.error("Error uploading plugin file:",C),r("Plugins",`Error uploading package ${C}`)})}},M=()=>{c({id:y.current,sender:"InstallPlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:i,restart:!1}})},O=()=>{document.getElementById("file-upload")?.click()},u=()=>{c({id:y.current,sender:"InstallPlugins",method:"/api/addplugin",src:"Frontend",dst:"Matterbridge",params:{pluginNameOrPath:i}})},z=f=>{d(f.currentTarget)},v=f=>{f!==""&&l(f),d(null)};return s&&console.log("AddRemovePlugins rendering..."),e.jsxs("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",alignItems:"center",justifyContent:"space-between",margin:"0px",padding:"10px",gap:"20px"},onDragOver:W,onDragLeave:h,onDrop:L,children:[e.jsx(pe,{value:i,onChange:f=>{l(f.target.value)},size:"small",id:"plugin-name",label:"Plugin name or plugin path",variant:"outlined",fullWidth:!0}),e.jsx(J,{onClick:z,children:e.jsx(Pr,{})}),e.jsxs(rt,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:!!t,onClose:()=>v(""),children:[e.jsx(F,{onClick:()=>v("matterbridge-zigbee2mqtt"),children:"matterbridge-zigbee2mqtt"}),e.jsx(F,{onClick:()=>v("matterbridge-somfy-tahoma"),children:"matterbridge-somfy-tahoma"}),e.jsx(F,{onClick:()=>v("matterbridge-shelly"),children:"matterbridge-shelly"}),e.jsx(F,{onClick:()=>v("matterbridge-hass"),children:"matterbridge-hass"}),e.jsx(F,{onClick:()=>v("matterbridge-webhooks"),children:"matterbridge-webhooks"}),e.jsx(F,{onClick:()=>v("matterbridge-bthome"),children:"matterbridge-bthome"}),e.jsx(F,{onClick:()=>v("matterbridge-test"),children:"matterbridge-test"}),e.jsx(F,{onClick:()=>v("matterbridge-example-accessory-platform"),children:"matterbridge-example-accessory-platform"}),e.jsx(F,{onClick:()=>v("matterbridge-example-dynamic-platform"),children:"matterbridge-example-dynamic-platform"}),e.jsx(F,{onClick:()=>v("matterbridge-eve-door"),children:"matterbridge-eve-door"}),e.jsx(F,{onClick:()=>v("matterbridge-eve-motion"),children:"matterbridge-eve-motion"}),e.jsx(F,{onClick:()=>v("matterbridge-eve-energy"),children:"matterbridge-eve-energy"}),e.jsx(F,{onClick:()=>v("matterbridge-eve-weather"),children:"matterbridge-eve-weather"}),e.jsx(F,{onClick:()=>v("matterbridge-eve-room"),children:"matterbridge-eve-room"})]}),e.jsx($,{title:"Install or update a plugin from npm",children:e.jsx(ne,{onClick:M,endIcon:e.jsx($e,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Install"})}),e.jsx($,{title:"Upload and install a plugin from a tarball",children:e.jsx(ne,{onClick:O,endIcon:e.jsx(Wr,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Upload"})}),e.jsx($,{title:"Add an installed plugin",children:e.jsx(ne,{onClick:u,endIcon:e.jsx(jt,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Add"})}),e.jsx("input",{id:"file-upload",type:"file",accept:".tgz",style:{display:"none"},onChange:V})]})}const nn=o.memo(on);function Ze({status:r,enabledText:c="Enabled",disabledText:a=void 0,tooltipText:i=void 0,onClick:l}){if(r===void 0)return e.jsx("div",{style:{margin:"-2.5px"},children:e.jsx("div",{})});{const g=e.jsx("div",{className:r?"status-enabled":"status-disabled",style:{cursor:"default"},onClick:l,children:r?c:a??c});return i!==void 0?e.jsx($,{title:i,children:g}):g}}const et={fontSize:"16px",fontWeight:"bold",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},tt={fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},an={fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)",backgroundColor:"var(--div-bg-color)"},sn={fontSize:"16px",fontWeight:"bold",backgroundColor:"var(--div-bg-color)"},Ee={padding:"0px",margin:"0px"},ln="5px 10px 5px 10px",ft={},Ce={},xt={},bt={};let vt=[],Jt=[];const dn=({open:r,onClose:c,plugin:a})=>{const{sendMessage:i,addListener:l,removeListener:g,getUniqueId:b}=o.useContext(be),t=o.useRef(b()),[d,y]=o.useState(a.configJson),[W,h]=o.useState(a.schemaJson),[L,V]=o.useState({"ui:submitButtonOptions":{submitText:"Confirm"},"ui:globalOptions":{orderable:!0}}),[M,O]=o.useState("");let u={};o.useEffect(()=>{const D=P=>{P.src==="Matterbridge"&&P.dst==="Frontend"&&(P.id===t.current&&P.method==="/api/select/devices"&&(P.response&&(vt=P.response),P.error&&console.error("ConfigPluginDialog received /api/select/devices error:",P.error)),P.id===t.current&&P.method==="/api/select/entities"&&(P.response&&(Jt=P.response),P.error&&console.error("ConfigPluginDialog received /api/select/entities error:",P.error)))};return l(D),d!==void 0&&W!==void 0&&(Object.keys(W.properties).forEach(P=>{Object.keys(W.properties[P]).forEach(N=>{N.startsWith("ui:")&&(L[P]={},L[P][N]=W.properties[P][N],delete W.properties[P][N])})}),V(L)),a.name!==void 0&&a.configJson!==void 0&&a.schemaJson!==void 0&&(y(a.configJson),h(a.schemaJson),i({id:t.current,sender:"ConfigPlugin",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:a.name}}),i({id:t.current,sender:"ConfigPlugin",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:a.name}})),()=>{g(D)}},[l,d,a,g,W,i,L]);const z=({formData:D})=>{u=D},v=({formData:D})=>{y(D),a.configJson=D,a.restartRequired=!0,i({id:t.current,sender:"ConfigPlugin",method:"/api/savepluginconfig",src:"Frontend",dst:"Matterbridge",params:{pluginName:D.name,formData:D}}),c()};function f(D){const{id:P,label:N,onKeyChange:n,onDropPropertyClick:T,disabled:_,schema:ae,children:ce,registry:B,readonly:le,required:ge}=D,{templates:oe}=B,{RemoveButton:ve}=oe.ButtonTemplates;if(!(Uo in ae))return e.jsx(Z,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:ce});const he=({target:X})=>n(X&&X.value);return e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",flexGrow:1,padding:0,margin:0,border:"none"},children:[e.jsx(pe,{id:`${P}-key`,name:`${P}-key`,required:ge,disabled:_||le,defaultValue:N,onBlur:le?void 0:he,type:"text",variant:"outlined",sx:{width:"250px",minWidth:"250px",maxWidth:"250px",marginRight:"20px"}}),e.jsx(Z,{sx:{flex:1},children:ce}),e.jsx(ve,{disabled:_||le,onClick:T(N)})]})}function k(D){const{children:P,description:N,displayLabel:n,errors:T,help:_,hidden:ae,_id:ce,_label:B,registry:le,uiSchema:ge}=D,oe=_o(ge),ve=Ao("WrapIfAdditionalTemplate",le,oe);return ae?e.jsx("div",{style:{display:"none"},children:P}):e.jsx(Z,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:e.jsxs(ve,{...D,children:[n===!0&&N,P,T,_]})})}function R(D){const{description:P}=D;return P?e.jsx(se,{sx:tt,children:P}):null}function C(D){const{required:P,title:N}=D;return N?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsxs(se,{sx:et,children:["Title ",N," ",P&&e.jsx("mark",{children:"***"})]})}):null}function m(D){const{help:P,_idSchema:N}=D;return P?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsx(se,{sx:an,children:P})}):null}function H(D){const{errors:P}=D;return P?e.jsxs(Z,{sx:{padding:"10px",margin:"10px",border:"1px solid grey"},children:[e.jsx(se,{color:"error",sx:sn,children:"Please fix the following errors:"}),e.jsx(it,{children:P.map((N,n)=>e.jsxs(Tr,{children:[e.jsx(K,{children:e.jsx(Fr,{color:"error"})}),e.jsx(re,{primary:N.stack})]},n))})]}):null}function j(D){const{errors:P}=D;return P?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:P.map((N,n)=>e.jsxs(se,{color:"error",variant:"body2",sx:{marginLeft:1},children:["This field ",N]},n))}):null}function x(D){const{id:P,name:N,_schema:n,_uiSchema:T,value:_,options:ae,label:ce,type:B,placeholder:le,required:ge,disabled:oe,readonly:ve,autofocus:ie,onChange:he,onChangeOverride:X,onBlur:ue,onFocus:ye,_rawErrors:Ge,_hideError:Q,_registry:ee,_formContext:We}=D,He=({target:{value:je}})=>he(je===""?ae.emptyValue:je),Re=({target:je})=>ue(P,je&&je.value),ze=({target:je})=>ye(P,je&&je.value);return e.jsx(Z,{sx:{padding:"0px",margin:"0px"},children:e.jsx(pe,{id:P,name:P,label:le&&le!==""?ce:void 0,variant:"outlined",placeholder:le&&le!==""?le:ce,required:ge,disabled:oe||ve,autoFocus:ie,value:_||_===0?_:"",type:B,autoComplete:B==="password"?"current-password":N,onChange:X||He,onBlur:Re,onFocus:ze,fullWidth:!0})})}function w(D){return console.log("ArrayFieldTitleTemplate:",D),null}function q(D){return console.log("ArrayFieldDescriptionTemplate:",D),null}function de(D){return console.log("ArrayFieldItemTemplate:",D),null}function xe(D){const{canAdd:P,_className:N,_disabled:n,_formContext:T,_formData:_,_idSchema:ae,_items:ce,onAddClick:B,_rawErrors:le,_readonly:ge,_registry:oe,_required:ve,schema:ie,title:he,_uiSchema:X}=D,[ue,ye]=o.useState(!1),[Ge,Q]=o.useState(!1),[ee,We]=o.useState(!1),[He,Re]=o.useState(""),ze=A=>{Re(A.target.value)},je=()=>{ye(!ue)},Ke=()=>{Q(!Ge)},Ye=()=>{We(!ee)},Mt=A=>{ye(!1),ie.selectFrom==="serial"?ie.items.default=A.serial:ie.selectFrom==="name"&&(ie.items.default=A.name),B()},kt=A=>{Q(!1),ie.selectEntityFrom==="name"?ie.items.default=A.name:ie.selectEntityFrom==="description"&&(ie.items.default=A.description),B()},It=A=>{We(!1),ie.selectDeviceEntityFrom==="name"?ie.items.default=A.name:ie.selectDeviceEntityFrom==="description"&&(ie.items.default=A.description),B()};return e.jsxs(Z,{sx:{margin:"0px",padding:"5px 10px 5px 10px",border:"1px solid grey"},children:[he&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[he&&e.jsx(se,{sx:et,children:he}),P&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ie.selectFrom&&e.jsx($,{title:"Add a device from the list",children:e.jsx(J,{onClick:je,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),ie.selectEntityFrom&&e.jsx($,{title:"Add an entity from the list",children:e.jsx(J,{onClick:Ke,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),ie.selectDeviceEntityFrom&&e.jsx($,{title:"Add a device entity from the list",children:e.jsx(J,{onClick:Ye,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),e.jsx($,{title:"Add a new item",children:e.jsx(J,{onClick:B,size:"small",color:"primary",sx:Ee,children:e.jsx(jt,{})})})]})]}),ie.description&&e.jsx(se,{sx:tt,children:ie.description}),D.items.map(A=>e.jsxs(Z,{sx:{margin:"2px 0px",padding:"0px",display:"flex",alignItems:"center"},children:[e.jsx(Z,{sx:{flexGrow:1,marginRight:"10px"},children:A.children}),e.jsx(J,{disabled:!A.hasMoveUp,onClick:A.onReorderClick(A.index,A.index-1),size:"small",color:"primary",sx:Ee,children:e.jsx(Rt,{})}),e.jsx(J,{disabled:!A.hasMoveDown,onClick:A.onReorderClick(A.index,A.index+1),size:"small",color:"primary",sx:Ee,children:e.jsx(Ht,{})}),e.jsx(J,{onClick:A.onDropIndexClick(A.index),size:"small",color:"primary",sx:Ee,children:e.jsx(St,{})})]},A.index)),e.jsxs(De,{open:ue,onClose:je,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Ne,{children:"Select a device"}),e.jsxs(Pe,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(se,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:He,onChange:ze,placeholder:"Enter serial or name"})]}),e.jsx(it,{dense:!0,children:vt.filter(A=>A.serial.toLowerCase().includes(He.toLowerCase())||A.name.toLowerCase().includes(He.toLowerCase())).map((A,ke)=>e.jsxs(ut,{onClick:()=>Mt(A),sx:ft,children:[A.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),A.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),A.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),e.jsx(re,{primary:A.name,secondary:A.serial,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},ke))})]}),e.jsx(Le,{children:e.jsx(ne,{onClick:je,children:"Close"})})]}),e.jsxs(De,{open:Ge,onClose:Ke,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Ne,{children:"Select an entity"}),e.jsxs(Pe,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(se,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:He,onChange:ze,placeholder:"Enter name or description"})]}),e.jsx(it,{dense:!0,children:Jt.filter(A=>A.name.toLowerCase().includes(He.toLowerCase())||A.description.toLowerCase().includes(He.toLowerCase())).map((A,ke)=>e.jsxs(ut,{onClick:()=>kt(A),sx:ft,children:[A.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),A.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),A.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),A.icon==="component"&&e.jsx(K,{children:e.jsx($t,{style:Ce})}),A.icon==="matter"&&e.jsx(K,{children:e.jsx(Ot,{style:Ce})}),e.jsx(re,{primary:A.name,secondary:A.description,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},ke))})]}),e.jsx(Le,{children:e.jsx(ne,{onClick:Ke,children:"Close"})})]}),e.jsxs(De,{open:ee,onClose:Ye,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsxs(Ne,{children:["Select an entity for ",he]}),e.jsx(Pe,{children:e.jsx(it,{dense:!0,children:vt.filter(A=>A.serial===he||A.name===he).map(A=>A.entities?.map((ke,Dt)=>e.jsxs(ut,{onClick:()=>It(ke),sx:ft,children:[ke.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),ke.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),ke.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),ke.icon==="component"&&e.jsx(K,{children:e.jsx($t,{style:Ce})}),ke.icon==="matter"&&e.jsx(K,{children:e.jsx(Ot,{style:Ce})}),e.jsx(re,{primary:ke.name,secondary:ke.description,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},Dt)))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:Ye,children:"Close"})})]})]})}function S(D){const{onAddClick:P,schema:N,properties:n,title:T,description:_}=D,[ae,ce]=o.useState(!1),[B,le]=o.useState(""),ge=X=>{le(X.target.value)},oe=()=>{ce(!ae)},ve=X=>{ce(!1);let ue="";N.selectFrom==="serial"?ue=X.serial:N.selectFrom==="name"&&(ue=X.name),O(ue),P(N)()},ie=()=>{P(N)()},he=!N.additionalProperties;return!he&&M!==""&&n.forEach(X=>{if(X.name==="newKey"&&X.content.key==="newKey"&&X.content.props.name==="newKey"&&X.content.props.onKeyChange&&M!==""){const ue=M;O(""),X.content.props.onKeyChange(ue)}}),e.jsxs(Z,{sx:{margin:"0px",padding:he?"10px":"5px 10px 0px 10px",border:he?"none":"1px solid grey"},children:[N.title&&he&&e.jsx(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(se,{sx:et,children:N.title})}),T&&!he&&e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[e.jsx(se,{sx:et,children:T}),e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[N.selectFrom&&e.jsx($,{title:"Add a device from the list",children:e.jsx(J,{onClick:oe,size:"small",color:"primary",sx:Ee,children:e.jsx(pt,{})})}),e.jsx($,{title:"Add a new item",children:e.jsx(J,{onClick:ie,size:"small",color:"primary",sx:Ee,children:e.jsx(jt,{})})})]})]}),N.description&&e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(se,{sx:tt,children:N.description})}),n.map(({content:X,name:ue,hidden:ye})=>!ye&&e.jsxs(Z,{sx:{margin:"0px",marginBottom:"10px",padding:["object","array","boolean"].includes(N.properties[ue].type)?"0px":ln,border:["object","array","boolean"].includes(N.properties[ue].type)?"none":"1px solid grey"},children:[!["object","array","boolean"].includes(N.properties[ue].type)&&e.jsx(se,{sx:et,children:ue}),e.jsx(Z,{sx:{flexGrow:1,padding:"0px",margin:"0px"},children:X})]},ue)),e.jsxs(De,{open:ae,onClose:oe,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Ne,{children:"Select a device"}),e.jsxs(Pe,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(se,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:B,onChange:ge,placeholder:"Enter serial or name"})]}),e.jsx(it,{dense:!0,children:vt.filter(X=>X.serial.toLowerCase().includes(B.toLowerCase())||X.name.toLowerCase().includes(B.toLowerCase())).map((X,ue)=>e.jsxs(ut,{onClick:()=>ve(X),sx:ft,children:[X.icon==="wifi"&&e.jsx(K,{children:e.jsx(at,{style:Ce})}),X.icon==="ble"&&e.jsx(K,{children:e.jsx(mt,{style:Ce})}),X.icon==="hub"&&e.jsx(K,{children:e.jsx(gt,{style:Ce})}),e.jsx(re,{primary:X.name,secondary:X.serial,primaryTypographyProps:{style:xt},secondaryTypographyProps:{style:bt}})]},ue))})]}),e.jsx(Le,{children:e.jsx(ne,{onClick:oe,children:"Close"})})]})]})}function p(D){const{uiSchema:P}=D,{submitText:N,norender:n}=Vo(P);return n?null:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",margin:"10px",padding:"0px",gap:"20px"},children:[e.jsx(ne,{type:"submit",variant:"contained",color:"primary",children:N}),e.jsx(ne,{variant:"contained",color:"primary",onClick:c,children:"Cancel"})]})}function E(D){const{className:P,disabled:N,onClick:n,registry:T,style:_,uiSchema:ae,...ce}=D;return e.jsx($,{title:"Remove the item",children:e.jsx(J,{disabled:N,size:"small",color:"primary",onClick:n,children:e.jsx(St,{})})})}function I(D){const{className:P,disabled:N,onClick:n,registry:T,uiSchema:_,...ae}=D;return e.jsx($,{title:"Add an item",children:e.jsx(J,{size:"small",color:"primary",onClick:n,children:e.jsx(jt,{})})})}function Y(D){const{disabled:P,onClick:N,registry:n,style:T,uiSchema:_,...ae}=D;return e.jsx($,{title:"Move up the item",children:e.jsx(J,{size:"small",color:"primary",onClick:N,children:e.jsx(Rt,{})})})}function me(D){const{disabled:P,onClick:N,registry:n,style:T,uiSchema:_,...ae}=D;return e.jsx($,{title:"Move down the item",children:e.jsx(J,{size:"small",color:"primary",onClick:N,children:e.jsx(Ht,{})})})}function Me(D){const{id:P,name:N,value:n,schema:T,readonly:_,onChange:ae}=D,[ce,B]=o.useState(void 0),le=oe=>{B(oe&&oe!==""?oe:void 0)},ge=()=>{i({id:t.current,sender:"ConfigPlugin",method:"/api/action",src:"Frontend",dst:"Matterbridge",params:{plugin:a.name,action:N,value:ce,formData:u,id:P}}),T.buttonClose===!0?c():T.buttonSave===!0&&v({formData:d})};return T.buttonText&&T.description?e.jsxs(Z,{sx:{margin:"0px",padding:"10px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(se,{sx:tt,children:T.description}),e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>ge(),children:T.buttonText})]}):T.buttonField&&T.description?e.jsxs(Z,{sx:{margin:"0px",padding:"10px",gap:"20px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(se,{sx:tt,children:T.description}),e.jsx(pe,{id:N+"-input",name:N,label:T.textLabel,placeholder:T.textPlaceholder,onChange:oe=>le(oe.target.value),sx:{width:"250px",minWidth:"250px",maxWidth:"250px"}}),e.jsx(ne,{id:N+"-button",variant:"contained",color:"primary",disabled:ce===void 0,onClick:()=>ge(),children:T.buttonField})]}):e.jsxs(Z,{sx:{margin:"0px",padding:"5px 10px",border:"1px solid grey"},children:[N&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",gap:"10px",display:"flex",justifyContent:"flex-start",alignItems:"center"},children:[e.jsx(se,{sx:et,children:N}),e.jsx(Fe,{checked:n,readOnly:_,onChange:()=>ae(!n),sx:{padding:"0px",margin:"0px"}})]}),T.description&&e.jsx(se,{sx:tt,children:T.description})]})}function U({schema:D,id:P,name:N,options:n,label:T,hideLabel:_,required:ae,disabled:ce,placeholder:B,readonly:le,value:ge,multiple:oe,autofocus:ve,onChange:ie,onBlur:he,onFocus:X,errorSchema:ue,rawErrors:ye=[],registry:Ge,uiSchema:Q,hideError:ee,formContext:We,...He}){const{enumOptions:Re,enumDisabled:ze,emptyValue:je}=n;oe=typeof oe>"u"?!1:!!oe;const Ke=oe?[]:"",Ye=typeof ge>"u"||oe&&ge.length<1||!oe&&ge===Ke,Mt=({target:{value:Oe}})=>ie(Pt(Oe,Re,je)),kt=({target:Oe})=>he(P,Pt(Oe&&Oe.value,Re,je)),It=({target:Oe})=>X(P,Pt(Oe&&Oe.value,Re,je)),A=Oo(ge,Re,oe),{InputLabelProps:ke,SelectProps:Dt,autocomplete:ur,...mr}=He,gr=!oe&&D.default===void 0;return e.jsxs(pe,{id:P,name:P,value:!Ye&&typeof A<"u"?A:Ke,required:ae,disabled:ce||le,autoFocus:ve,autoComplete:ur,placeholder:B,error:ye.length>0,onChange:Mt,onBlur:kt,onFocus:It,...mr,select:!0,InputLabelProps:{...ke,shrink:!Ye},SelectProps:{...Dt,multiple:oe},"aria-describedby":Eo(P),children:[gr&&e.jsx(F,{value:"",children:B}),Array.isArray(Re)&&Re.map(({value:Oe,label:hr},Lt)=>{const fr=Array.isArray(ze)&&ze.indexOf(Oe)!==-1;return e.jsx(F,{value:String(Lt),disabled:fr,children:hr},Lt)})]})}return!r||!W||!d?null:e.jsxs(De,{open:r,onClose:c,maxWidth:"800px",children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h3",{children:"Matterbridge plugin configuration"})]})}),e.jsx(Pe,{style:{padding:"0px",margin:"0px",width:"800px",height:"600px",overflow:"auto"},children:e.jsx(Ro,{schema:W,formData:d,uiSchema:L,validator:$o,templates:{FieldTemplate:k,BaseInputTemplate:x,TitleFieldTemplate:C,DescriptionFieldTemplate:R,FieldHelpTemplate:m,FieldErrorTemplate:j,ErrorListTemplate:H,WrapIfAdditionalTemplate:f,ArrayFieldTitleTemplate:w,ArrayFieldDescriptionTemplate:q,ArrayFieldItemTemplate:de,ArrayFieldTemplate:xe,ObjectFieldTemplate:S,ButtonTemplates:{SubmitButton:p,RemoveButton:E,AddButton:I,MoveUpButton:Y,MoveDownButton:me}},widgets:{CheckboxWidget:Me,SelectWidget:U},onChange:z,onSubmit:v})})]})};function sr(r){if(s&&console.log(`getQRColor (id: ${r?.id}) received matter:`,r??"undefined"),r===void 0||!r.online||!r.qrPairingCode&&!r.manualPairingCode&&!r.fabricInformations&&!r.sessionInformations)return"red";if(r.commissioned===!1&&r.qrPairingCode&&r.manualPairingCode)return"var(--primary-color)";let c=0,a=0;for(const i of r.sessionInformations??[])i.fabric&&i.isPeerActive===!0&&c++,i.numberOfActiveSubscriptions>0&&(a+=i.numberOfActiveSubscriptions);return r.commissioned===!0&&r.fabricInformations&&r.sessionInformations&&(c===0||a===0)?"var(--secondary-color)":"var(--div-text-color)"}function cn({data:r,columns:c,columnVisibility:a}){const i=Xt.useMemo(()=>c.filter(y=>a[y.accessor]),[c,a]),{getTableProps:l,getTableBodyProps:g,headerGroups:b,rows:t,prepareRow:d}=Ue.useTable({columns:i,data:r},Ue.useSortBy);return e.jsxs("table",{...l(),style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("thead",{style:{border:"none",borderCollapse:"collapse"},children:b.map(y=>e.jsx("tr",{...y.getHeaderGroupProps(),style:{border:"none",borderCollapse:"collapse"},children:y.headers.map(W=>e.jsx("th",{...W.getHeaderProps(void 0),style:{border:"none",borderCollapse:"collapse",cursor:"default"},children:W.render("Header")}))}))}),e.jsx("tbody",{...g(),style:{border:"none",borderCollapse:"collapse"},children:t.map((y,W)=>(d(y),e.jsx("tr",{className:W%2===0?"table-content-even":"table-content-odd",...y.getRowProps(),style:{border:"none",borderCollapse:"collapse"},children:y.cells.map(h=>e.jsx("td",{...h.getCellProps(),style:{border:"none",borderCollapse:"collapse"},children:h.render("Cell")}))})))})]})}function pn({_storeId:r,setStoreId:c}){const{online:a,sendMessage:i,addListener:l,removeListener:g,getUniqueId:b}=o.useContext(be),{showConfirmCancelDialog:t}=o.useContext(nt),d=o.useRef(b()),[y,W]=o.useState(null),[h,L]=o.useState(null),[V,M]=o.useState([]),[O,u]=o.useState(!1),[z,v]=o.useState({name:!0,description:!0,version:!0,author:!0,type:!0,registeredDevices:!0,actions:!0,status:!0}),f=[{Header:"Name",accessor:"name",Cell:({row:n})=>e.jsx($,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>S(n.original),children:n.original.name})})},{Header:"Description",accessor:"description",Cell:({row:n})=>e.jsx($,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>S(n.original),children:n.original.description})})},{Header:"Version",accessor:"version",Cell:({row:n})=>e.jsxs(e.Fragment,{children:[n.original.latestVersion!==void 0&&n.original.latestVersion!==n.original.version&&h&&!h.readOnly&&e.jsx($,{title:"New plugin stable version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>x(n.original),children:["Update to v.",n.original.latestVersion]})}),n.original.version.includes("-dev-")&&n.original.devVersion!==void 0&&n.original.devVersion!==n.original.version&&h&&!h.readOnly&&e.jsx($,{title:"New plugin dev version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>w(n.original),children:["Update to new dev v.",n.original.devVersion.split("-dev-")[0]]})}),e.jsx($,{title:"Plugin version",children:e.jsx("span",{children:n.original.version})})]})},{Header:"Author",accessor:"author",Cell:({row:n})=>e.jsx(e.Fragment,{children:n.original.author?n.original.author.replace("https://github.com/",""):"Unknown"})},{Header:"Type",accessor:"type",Cell:({row:n})=>e.jsx(e.Fragment,{children:n.original.type?n.original.type.replace("Platform",""):"Unknown"})},{Header:"Devices",accessor:"registeredDevices"},{Header:"Actions",accessor:"actions",Cell:({row:n})=>e.jsxs("div",{style:{margin:"0px",padding:"0px",gap:"4px",display:"flex",flexDirection:"row"},children:[h&&h.bridgeMode==="childbridge"&&!n.original.error&&n.original.enabled&&e.jsx($,{title:"Shows the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:sr(n.original.matter)},onClick:()=>{n.original?.matter?.id&&c(n.original?.matter?.id)},size:"small",children:e.jsx(tr,{})})}),h&&h.bridgeMode==="childbridge"&&!n.original.error&&n.original.enabled&&e.jsx($,{title:"Restart the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0",padding:"0",width:"19px",height:"19px"},onClick:()=>de(n.original),size:"small",children:e.jsx(yt,{})})}),e.jsx($,{title:"Plugin config",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{disabled:n.original.restartRequired===!0,style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>D(n.original),size:"small",children:e.jsx(Je,{})})}),h&&!h.readOnly&&e.jsx($,{title:"Remove the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{m("Remove plugin","Are you sure? This will also remove all devices and configuration from the controller.","remove",n.original)},size:"small",children:e.jsx(St,{})})}),n.original.enabled?e.jsx($,{title:"Disable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{m("Disable plugin","Are you sure? This will also remove all devices and configuration from the controller.","disable",n.original)},size:"small",children:e.jsx(Lr,{})})}):e.jsx(e.Fragment,{}),n.original.enabled?e.jsx(e.Fragment,{}):e.jsx($,{title:"Enable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>xe(n.original),size:"small",children:e.jsx(Hr,{})})}),e.jsx($,{title:"Open the plugin help",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>E(n.original),size:"small",children:e.jsx(Rr,{})})}),e.jsx($,{title:"Open the plugin version history",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>I(n.original),size:"small",children:e.jsx($r,{})})}),h&&!h.readOnly&&e.jsx($,{title:"Sponsor the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:"#b6409c"},onClick:()=>p(n.original),size:"small",children:e.jsx(Zt,{})})})]})},{Header:"Status",accessor:"status",Cell:({row:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",gap:"5px"},children:n.original.error?e.jsx(e.Fragment,{children:e.jsx(Ze,{status:!1,enabledText:"Error",disabledText:"Error",tooltipText:"The plugin is in error state. Check the log!"})}):e.jsx(e.Fragment,{children:n.original.enabled===!1?e.jsx(e.Fragment,{children:e.jsx(Ze,{status:n.original.enabled,enabledText:"Enabled",disabledText:"Disabled",tooltipText:"Whether the plugin is enable or disabled"})}):e.jsx(e.Fragment,{children:n.original.loaded&&n.original.started&&n.original.configured?e.jsx(e.Fragment,{children:e.jsx(Ze,{status:n.original.loaded,enabledText:"Running",tooltipText:"Whether the plugin is running"})}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{status:n.original.loaded,enabledText:"Loaded",tooltipText:"Whether the plugin has been loaded"}),e.jsx(Ze,{status:n.original.started,enabledText:"Started",tooltipText:"Whether the plugin started"}),e.jsx(Ze,{status:n.original.configured,enabledText:"Configured",tooltipText:"Whether the plugin has been configured"})]})})})})}];o.useEffect(()=>{const n=T=>{T.src==="Matterbridge"&&T.dst==="Frontend"&&(fe(T)&&T.method==="refresh_required"&&T.params.changed==="plugins"&&(s&&console.log(`HomePlugins received refresh_required: changed=${T.params.changed} and sending /api/plugins request`),i({id:d.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),fe(T)&&T.method==="refresh_required"&&T.params.changed==="matter"&&(s&&console.log(`HomePlugins received refresh_required: changed=${T.params.changed} and setting matter id ${T.params.matter?.id}`),M(_=>{const ae=_.findIndex(B=>B.matter?.id===T.params.matter?.id);if(ae<0)return s&&console.log(`HomePlugins received refresh_required: changed=${T.params.changed} and matter id ${T.params.matter?.id} not found`),_;s&&console.log(`HomePlugins received refresh_required: changed=${T.params.changed} set matter id ${T.params.matter?.id}`);const ce=[..._];return ce[ae]={...ce[ae],matter:T.params.matter},ce})),fe(T)&&T.method==="refresh_required"&&T.params.changed==="settings"&&(s&&console.log(`HomePlugins received refresh_required: changed=${T.params.changed} and sending /api/settings request`),i({id:d.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),Ve(T)&&T.id===d.current&&T.method==="/api/settings"&&(s&&console.log(`HomePlugins (id: ${T.id}) received settings:`,T.response),W(T.response.systemInformation),L(T.response.matterbridgeInformation)),Ve(T)&&T.id===d.current&&T.method==="/api/plugins"&&(s&&console.log(`HomePlugins (id: ${T.id}) received ${T.response.length} plugins:`,T.response),M(T.response)))};return l(n),s&&console.log("HomePlugins added WebSocket listener id:",d.current),()=>{g(n),s&&console.log("HomePlugins removed WebSocket listener")}},[l,g,i]),o.useEffect(()=>{a&&(s&&console.log("HomePlugins sending api requests"),i({id:d.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:d.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[a,i]),o.useEffect(()=>{const n=localStorage.getItem("homePluginsColumnVisibility");n&&v(JSON.parse(n))},[]);const k=()=>{u(!O)},R=n=>{v(T=>{const _={...T,[n]:!T[n]};return localStorage.setItem("homePluginsColumnVisibility",JSON.stringify(_)),_})},C=o.useRef(null),m=(n,T,_,ae)=>{s&&console.log(`handleActionWithConfirmCancel ${_} ${ae.name}`),C.current=ae,t(n,T,_,H,j)},H=n=>{s&&console.log(`handleConfirm action confirmed ${n} ${C.current?.name}`),n==="remove"&&C.current?q(C.current):n==="disable"&&C.current&&xe(C.current),C.current=null},j=n=>{s&&console.log(`handleCancel action canceled ${n} ${C.current?.name}`),C.current=null},x=n=>{s&&console.log("handleUpdatePlugin plugin:",n.name),i({id:d.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:n.name,restart:!1}})},w=n=>{s&&console.log("handleUpdateDevPlugin plugin:",n.name),i({id:d.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:n.name+"@dev",restart:!1}})},q=n=>{s&&console.log("handleRemovePlugin plugin:",n.name),i({id:d.current,sender:"HomePlugins",method:"/api/removeplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:n.name}})},de=n=>{s&&console.log("handleRestartPlugin plugin:",n.name),i({id:d.current,sender:"HomePlugins",method:"/api/restartplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:n.name}})},xe=n=>{s&&console.log("handleEnableDisablePlugin plugin:",n.name,"enabled:",n.enabled),n.enabled===!0?(n.enabled=!1,i({id:d.current,sender:"HomePlugins",method:"/api/disableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:n.name}})):(n.enabled=!0,i({id:d.current,sender:"HomePlugins",method:"/api/enableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:n.name}}))},S=n=>{s&&console.log(`handleHomepagePlugin plugin: ${n.name} homepage: ${n.homepage}`),n.homepage&&window.open(n.homepage,"_blank")},p=n=>{s&&console.log("handleSponsorPlugin plugin:",n.name,"funding:",n.funding),n.funding&&window.open(n.funding,"_blank")},E=n=>{s&&console.log("handleHelpPlugin plugin:",n.name,"help:",n.help),n.help&&window.open(n.help,"_blank")},I=n=>{s&&console.log("handleChangelogPlugin plugin:",n.name,"changelog:",n.changelog),n.changelog&&window.open(n.changelog,"_blank")},[Y,me]=o.useState({}),[Me,U]=o.useState(!1),D=n=>{s&&console.log("handleConfigPlugin plugin:",n.name),i({id:d.current,sender:"HomePlugins",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:n.name}}),i({id:d.current,sender:"HomePlugins",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:n.name}}),me(n),P()},P=()=>{U(!0)},N=()=>{U(!1)};return s&&console.log("HomePlugins rendering..."),a?e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"0 0 auto",overflow:"hidden"},children:[e.jsx(dn,{open:Me,onClose:N,plugin:Y}),e.jsxs(De,{open:O,onClose:k,children:[e.jsx(Ne,{children:"Configure Plugins Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:f.map(n=>e.jsx(Te,{control:e.jsx(Fe,{disabled:["description","actions","status"].includes(n.accessor),checked:z[n.accessor]??!1,onChange:()=>R(n.accessor)}),label:n.Header},n.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:k,children:"Close"})})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Plugins"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(J,{onClick:k,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})})]}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0px",padding:"0px",gap:"0",overflow:"auto"},children:e.jsx(cn,{data:V,columns:f,columnVisibility:z})})]}):e.jsx(Qe,{})}const un=o.memo(pn),mn=r=>`${r.pluginName}::${r.serial}`;function gn({data:r,columns:c,columnVisibility:a}){const i=o.useMemo(()=>{const h=localStorage.getItem("homeDevicesColumnsSortBy");return h?JSON.parse(h):[{id:"name",desc:!1}]},[c]),l=o.useMemo(()=>c.filter(h=>a[h.accessor]),[a,c]),{getTableProps:g,getTableBodyProps:b,headerGroups:t,rows:d,prepareRow:y,state:{sortBy:W}}=Ue.useTable({columns:l,data:r,getRowId:mn,initialState:{sortBy:i}},Ue.useSortBy);return o.useEffect(()=>{localStorage.setItem("homeDevicesColumnsSortBy",JSON.stringify(W))},[W]),e.jsxs("table",{...g(),style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("thead",{style:{border:"none",borderCollapse:"collapse"},children:t.map(h=>e.jsx("tr",{...h.getHeaderGroupProps(),style:{border:"none",borderCollapse:"collapse"},children:h.headers.map(L=>e.jsxs("th",{...L.getHeaderProps(L.noSort?void 0:L.getSortByToggleProps()),style:{border:"none",borderCollapse:"collapse",cursor:L.noSort?"default":"pointer"},children:[L.render("Header"),!L.noSort&&e.jsx("span",{style:{margin:"0px",marginLeft:"5px",padding:"0px"},children:L.isSorted?L.isSortedDesc?e.jsx(te,{path:Tt,size:"15px"}):e.jsx(te,{path:Ft,size:"15px"}):null})]}))}))}),e.jsx("tbody",{...b(),style:{border:"none",borderCollapse:"collapse"},children:d.map((h,L)=>(y(h),e.jsx("tr",{className:L%2===0?"table-content-even":"table-content-odd",...h.getRowProps(),style:{border:"none",borderCollapse:"collapse"},children:h.cells.map(V=>e.jsx("td",{...V.getCellProps(),style:{border:"none",borderCollapse:"collapse"},children:V.render("Cell")}))})))})]})}function hn({storeId:r,setStoreId:c}){const{online:a,sendMessage:i,addListener:l,removeListener:g,getUniqueId:b}=o.useContext(be),[t,d]=o.useState(!1),[y,W]=o.useState(!0),[h,L]=o.useState(null),[V,M]=o.useState([]),[O,u]=o.useState([]),[z,v]=o.useState([]),[f,k]=o.useState([]),[R,C]=o.useState(!1),[m,H]=o.useState({pluginName:!0,name:!0,serial:!0,reachable:!0,powerSource:!0,configUrl:!1,actions:!0}),j=o.useRef(b()),x=[{Header:"Plugin",accessor:"pluginName"},{Header:"Name",accessor:"name"},{Header:"Serial",accessor:"serial"},{Header:"Availability",accessor:"reachable",Cell:({row:S})=>S.original.reachable===!0?"Online":S.original.reachable===!1?e.jsx("span",{style:{color:"red"},children:"Offline"}):"",sortType:(S,p)=>{const E=S.original.reachable===!0?1:S.original.reachable===!1?0:-1,I=p.original.reachable===!0?1:p.original.reachable===!1?0:-1;return E-I}},{Header:"Power",accessor:"powerSource",Cell:({row:S})=>S.original.powerSource==="ac"||S.original.powerSource==="dc"?e.jsx(rr,{fontSize:"small",sx:{color:"var(--primary-color)"}}):S.original.powerSource==="ok"?e.jsx(Ct,{fontSize:"small",sx:{color:"green"}}):S.original.powerSource==="warning"?e.jsx(Ct,{fontSize:"small",sx:{color:"yellow"}}):S.original.powerSource==="critical"?e.jsx(Ct,{fontSize:"small",sx:{color:"red"}}):e.jsx("span",{})},{Header:"Url",accessor:"configUrl"},{Header:"Actions",accessor:"actions",noSort:!0,Cell:({row:S})=>e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[S.original.matter!==void 0?e.jsx($,{title:"Show the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{onClick:()=>c(r===S.original.matter.id?h.matterbridgeInformation.bridgeMode==="bridge"?"Matterbridge":null:S.original.matter.id),"aria-label":"Show the QRCode",sx:{margin:0,padding:0,color:sr(S.original.matter)},children:e.jsx(tr,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),S.original.configUrl?e.jsx($,{title:"Open the configuration page",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(J,{onClick:()=>window.open(S.original.configUrl,"_blank"),"aria-label":"Open config url",sx:{margin:0,padding:0},children:e.jsx(Je,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),S.original.selected!==void 0?e.jsx($,{title:"Select/unselect the device",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Fe,{checked:S.original.selected,onChange:p=>xe(p,S.original),sx:{margin:"0",marginLeft:"8px",padding:"0"},size:"small"})}):e.jsx("div",{style:{width:"20px",height:"20px"}})]})}],w=o.useCallback(S=>{S.selected=void 0;const p=V.find(Y=>Y.name===S.pluginName);if(!p)return console.error(`HomeDevices isSelected: plugin ${S.pluginName} not found for device ${S.deviceName} `),S.selected;const E=p.schemaJson?.properties?.whiteList?.selectFrom;let I=p.configJson?.postfix;return I===""&&(I=void 0),p.hasWhiteList===!0&&p.hasBlackList===!0&&E&&(S.selected=!0,E==="serial"&&p.configJson.whiteList&&p.configJson.whiteList.length>0&&p.configJson.whiteList.includes(I?S.serial.replace("-"+I,""):S.serial)&&(S.selected=!0),E==="serial"&&p.configJson.whiteList&&p.configJson.whiteList.length>0&&!p.configJson.whiteList.includes(I?S.serial.replace("-"+I,""):S.serial)&&(S.selected=!1),E==="serial"&&p.configJson.blackList&&p.configJson.blackList.length>0&&p.configJson.blackList.includes(I?S.serial.replace("-"+I,""):S.serial)&&(S.selected=!1),E==="name"&&p.configJson.whiteList&&p.configJson.whiteList.length>0&&p.configJson.whiteList.includes(S.name)&&(S.selected=!0),E==="name"&&p.configJson.whiteList&&p.configJson.whiteList.length>0&&!p.configJson.whiteList.includes(S.name)&&(S.selected=!1),E==="name"&&p.configJson.blackList&&p.configJson.blackList.length>0&&p.configJson.blackList.includes(S.name)&&(S.selected=!1)),S.selected},[V]);o.useEffect(()=>{const S=p=>{if(p.src==="Matterbridge"&&p.dst==="Frontend"){if(p.method==="refresh_required"&&p.params.changed!=="matter"&&(s&&console.log(`HomeDevices received refresh_required: changed=${p.params.changed} and sending /api/plugins request`),i({id:j.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),p.method==="refresh_required"&&p.params.changed==="matter"&&(s&&console.log(`HomeDevices received refresh_required: changed=${p.params.changed} and setting matter id ${p.params.matter?.id}`),k(E=>{const I=E.findIndex(me=>me.name.replaceAll(" ","")===p.params.matter?.id);if(I<0)return s&&console.debug(`HomeDevices: matter id ${p.params.matter?.id} not found`),E;const Y=[...E];return Y[I]={...Y[I],matter:p.params.matter},s&&console.log(`HomeDevices received refresh_required: changed=${p.params.changed} and set matter id ${p.params.matter?.id}`),Y})),p.method==="restart_required"&&(s&&console.log("HomeDevices received restart_required"),d(!0)),p.method==="restart_not_required"&&(s&&console.log("HomeDevices received restart_not_required"),d(!1)),p.method==="state_update"&&p.params.plugin&&p.params.serialNumber&&p.params.cluster.includes("BasicInformationServer")&&p.params.attribute==="reachable"&&(console.log(`HomeDevices updating device reachability for plugin ${p.params.plugin} serial ${p.params.serialNumber} value ${p.params.value}`),u(E=>E.map(I=>I.pluginName===p.params.plugin&&I.serial===p.params.serialNumber?{...I,reachable:p.params.value}:I))),p.id===j.current&&p.method==="/api/settings"&&(s&&console.log(`HomeDevices (id: ${p.id}) received settings:`,p.response),L(p.response),d(p.response.matterbridgeInformation.restartRequired||p.response.matterbridgeInformation.fixedRestartRequired)),p.id===j.current&&p.method==="/api/plugins"&&(s&&console.log(`HomeDevices (id: ${p.id}) received ${p.response?.length} plugins:`,p.response),p.response)){let E=!0;for(const I of p.response)I.enabled===!0&&(I.loaded!==!0||I.started!==!0||I.error===!0)&&(E=!1);if(!E)return;s&&console.log("HomeDevices reset plugins, devices and selectDevices"),W(!1),M(p.response),u([]),v([]),i({id:j.current,sender:"HomeDevices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}),s&&console.log("HomeDevices sent /api/devices");for(const I of p.response)I.enabled===!0&&I.loaded===!0&&I.started===!0&&I.error!==!0&&(i({id:j.current,sender:"HomeDevices",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:I.name}}),s&&console.log(`HomeDevices sent /api/select/devices for plugin: ${I.name}`))}if(p.id===j.current&&p.method==="/api/devices"&&(s&&console.log(`HomeDevices (id: ${p.id}) received ${p.response?.length} devices:`,p.response),p.response)){for(const E of p.response)E.selected=w(E);u(p.response)}p.id===j.current&&p.method==="/api/select/devices"&&(s&&console.log(`HomeDevices (id: ${p.id}) received ${p.response?.length} selectDevices for plugin ${p.response&&p.response.length>0?p.response[0].pluginName:"without select devices"}:`,p.response),p.response&&p.response.length>0&&v(E=>{const I=E.filter(me=>me.pluginName!==p.response[0].pluginName),Y=p.response.map(me=>({...me,selected:w(me)}));return[...I,...Y]}))}};return l(S),s&&console.log(`HomeDevices added WebSocket listener id ${j.current}`),()=>{g(S),s&&console.log("HomeDevices removed WebSocket listener")}},[V,l,g,i,w]),o.useEffect(()=>{if(O.length===0&&z.length===0){k([]);return}s&&console.log(`HomeDevices mixing devices (${O.length}) and selectDevices (${z.length})`);const S=[];for(const p of O)S.push(p);for(const p of z)O.find(E=>E.pluginName===p.pluginName&&E.serial.includes(p.serial))||S.push(p);S.length>0&&(k(S),s&&console.log(`HomeDevices mixed ${S.length} devices and selectDevices`))},[V,O,z,k]),o.useEffect(()=>{a&&(s&&console.log("HomeDevices sending /api/settings and /api/plugins requests"),i({id:j.current,sender:"HomeDevices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:j.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[a,i]),o.useEffect(()=>{const S=localStorage.getItem("homeDevicesColumnVisibility");if(S){const p=JSON.parse(S);p.powerSource===void 0&&(p.powerSource=!0),H(p),s&&console.log("HomeDevices loaded column visibility from localStorage")}},[]);const q=S=>{H(p=>{const E={...p,[S]:!p[S]};return localStorage.setItem("homeDevicesColumnVisibility",JSON.stringify(E)),s&&console.log("HomeDevices saved column visibility to localStorage",JSON.stringify(E),E),E})},de=()=>{C(!R)},xe=(S,p)=>{console.log(`handleCheckboxChange: checkbox changed to ${S.target.checked} for device ${p.name} serial ${p.serial}`),k(E=>{const I=E.findIndex(me=>me.pluginName===p.pluginName&&me.serial===p.serial);if(I<0)return console.error(`handleCheckboxChange: device not found ${p.name} serial ${p.serial} id ${p.id}`),E;const Y=[...E];return Y[I]={...Y[I],selected:S.target.checked},Y}),S.target.checked?i({id:j.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"selectdevice",plugin:p.pluginName,serial:p.serial,name:p.name}}):i({id:j.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"unselectdevice",plugin:p.pluginName,serial:p.serial,name:p.name}})};return s&&console.log("HomeDevices rendering..."),a?e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",overflow:"hidden"},children:[e.jsxs(De,{open:R,onClose:de,children:[e.jsx(Ne,{children:"Configure Devices Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:x.map(S=>e.jsx(Te,{control:e.jsx(Fe,{disabled:["name","actions"].includes(S.accessor),checked:m[S.accessor],onChange:()=>q(S.accessor)}),label:S.Header},S.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:de,children:"Close"})})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Devices"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(J,{onClick:de,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})})]}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0px",padding:"0px",gap:"0",overflow:"auto"},children:e.jsx(gn,{data:f,columns:x,columnVisibility:m})}),e.jsxs("div",{className:"MbfWindowFooter",style:{borderTop:"1px solid var(--table-border-color)",justifyContent:"space-between"},children:[y&&e.jsx("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",fontSize:"14px",color:"var(--secondary-color)"},children:"Waiting for the plugins to fully load..."}),!y&&e.jsxs("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",fontSize:"14px",color:"var(--secondary-color)"},children:["Registered devices: ",O.length.toString(),"/",f.length.toString()]}),t&&e.jsx("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",fontSize:"14px",color:"var(--secondary-color)"},children:"Restart required"})]})]}):e.jsx(Qe,{})}const fn=o.memo(hn);function xn(){const[r,c]=o.useState(null),[a,i]=o.useState(null),[l,g]=o.useState([]),[b]=o.useState(localStorage.getItem("homePagePlugins")!=="false"),[t,d]=o.useState(localStorage.getItem("homePageMode")??"devices"),[y,W]=o.useState(""),[h,L]=o.useState(!1),[V,M]=o.useState(!1),[O,u]=o.useState(null),{addListener:z,removeListener:v,online:f,sendMessage:k,logFilterLevel:R,logFilterSearch:C,autoScroll:m,getUniqueId:H}=o.useContext(be),j=o.useRef(H());return o.useEffect(()=>{const x=w=>{w.src==="Matterbridge"&&w.dst==="Frontend"&&(fe(w)&&w.method==="refresh_required"&&w.params.changed==="settings"&&(s&&console.log(`Home received refresh_required: changed=${w.params.changed} and sending /api/settings request`),u(null),g([]),k({id:j.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),k({id:j.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),Ve(w)&&w.method==="/api/settings"&&w.id===j.current&&(s&&console.log("Home received settings:",w.response),c(w.response.systemInformation),i(w.response.matterbridgeInformation),w.response.matterbridgeInformation.bridgeMode==="bridge"&&(O||u("Matterbridge")),w.response.matterbridgeInformation.bridgeMode==="childbridge"&&l.length>0&&O===null&&!O&&l.length>0&&l[0].matter?.id&&u(l[0].matter.id),w.response.matterbridgeInformation.matterbridgeVersion&&W(`https://github.com/Luligu/matterbridge/blob/${w.response.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?"dev":"main"}/CHANGELOG.md`),localStorage.getItem("frontendVersion")===null&&w.response.matterbridgeInformation.frontendVersion?localStorage.setItem("frontendVersion",w.response.matterbridgeInformation.frontendVersion):w.response.matterbridgeInformation.frontendVersion!==localStorage.getItem("frontendVersion")&&w.response.matterbridgeInformation.frontendVersion&&(localStorage.setItem("frontendVersion",w.response.matterbridgeInformation.frontendVersion),M(!0)),localStorage.getItem("matterbridgeVersion")===null?localStorage.setItem("matterbridgeVersion",w.response.matterbridgeInformation.matterbridgeVersion):w.response.matterbridgeInformation.matterbridgeVersion!==localStorage.getItem("matterbridgeVersion")&&(localStorage.setItem("matterbridgeVersion",w.response.matterbridgeInformation.matterbridgeVersion),L(!0)),w.response.matterbridgeInformation.shellyBoard&&(localStorage.getItem("homePageMode")||(localStorage.setItem("homePageMode","devices"),d("devices")))),Ve(w)&&w.method==="/api/plugins"&&w.id===j.current&&(s&&console.log(`Home received plugins (${a?.bridgeMode}):`,w.response),g(w.response),a?.bridgeMode==="childbridge"&&w.response.length>0&&!O&&w.response.length>0&&w.response[0].matter?.id&&u(w.response[0].matter.id)))};return z(x),s&&console.log(`Home added WebSocket listener id ${j.current}`),()=>{v(x),s&&console.log("Home removed WebSocket listener")}},[z,v,k,a,l,O]),o.useEffect(()=>{f&&(s&&console.log("Home received online"),k({id:j.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),k({id:j.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[f,k]),s&&console.log("Home rendering..."),!f||!r||!a?e.jsx(Qe,{}):e.jsxs("div",{className:"MbfPageDiv",style:{flexDirection:"row"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"302px",minWidth:"302px",gap:"20px"},children:[e.jsx(rn,{id:O}),e.jsx(Zo,{systemInfo:r,compact:!0})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",gap:"20px"},children:[V&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Frontend Update"})}),e.jsxs("div",{className:"MbfWindowBody",style:{flexDirection:"row",justifyContent:"space-between"},children:[e.jsx("h4",{style:{margin:0},children:"The frontend has been updated. You are viewing an outdated web UI. Please refresh the page now."}),e.jsx("div",{children:e.jsx(ne,{onClick:()=>window.location.reload(),endIcon:e.jsx(Or,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Refresh"})})]})]}),h&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge Update"})}),e.jsxs("div",{className:"MbfWindowBody",style:{flexDirection:"row",justifyContent:"space-between"},children:[e.jsx("h4",{style:{margin:0},children:"Matterbridge has been updated."}),e.jsxs("div",{children:[e.jsx(ne,{onClick:()=>window.open(y,"_blank"),endIcon:e.jsx(er,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Changelog"}),e.jsx(ne,{onClick:()=>window.location.reload(),endIcon:e.jsx(Er,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Close"})]})]})]}),b&&!a.readOnly&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Install plugins"})}),e.jsx(nn,{})]}),b&&e.jsx(un,{storeId:O,setStoreId:u}),t==="devices"&&e.jsx(fn,{storeId:O,setStoreId:u}),t==="logs"&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"1 1 auto",width:"100%",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:"Logs"}),e.jsx("div",{className:"MbfWindowHeaderText",style:{display:"flex",justifyContent:"space-between"},children:e.jsxs("span",{style:{fontWeight:"normal",fontSize:"12px",marginTop:"2px"},children:['Filter: logger level "',R,'" and search "',C,'" Scroll: ',m?"auto":"manual"]})})]}),e.jsx("div",{style:{flex:"1 1 auto",margin:"0px",padding:"10px",overflow:"auto"},children:e.jsx(ar,{})})]})]})]})}const bn=o.memo(xn),Qt={display:"flex",gap:"2px",justifyContent:"space-evenly",width:"100%",height:"40px"},vn={margin:"0",padding:"0",fontSize:"36px",fontWeight:"medium",color:"var(--primary-color)"},yn={margin:"0",padding:"0",fontSize:"20px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},Gt={margin:"0",padding:"0",paddingBottom:"2px",fontSize:"16px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},jn={display:"flex",gap:"2px",justifyContent:"center",width:"100%",height:"18px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},Cn={margin:"0",padding:"0",fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)"},Sn={display:"flex",justifyContent:"center",width:"100%",height:"52px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},wn={margin:"0",padding:"0",fontSize:"14px",fontWeight:"bold",color:"var(--div-text-color)"},Mn={display:"flex",gap:"4px",justifyContent:"center",width:"100%",height:"15px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},Wt={margin:"0",padding:"0px 4px",borderRadius:"5px",textAlign:"center",fontSize:"12px",fontWeight:"normal",color:"var(--secondary-color)"},kn=[256,257,268,269],In=[266,267],Dn=[259,260,261,271,272],Nn=[256,257,268,269,266,267,259,260,261];function G({icon:r,iconColor:c,cluster:a,value:i,unit:l,prefix:g}){return s&&console.log(`Render cluster "${a.clusterName}.${a.attributeName}" value(${typeof i}-${isNaN(i)}) "${i}" unit "${l}"`),g=g??!1,e.jsxs(Z,{sx:Qt,children:[r&&o.cloneElement(r,{key:`${a.clusterId}-${a.attributeId}-icon`,sx:{...vn,color:c??"var(--primary-color)"}}),e.jsxs(Z,{sx:{...Qt,gap:"4px",alignContent:"center",alignItems:"end",justifyContent:"center"},children:[l&&g===!0&&e.jsx(se,{sx:Gt,children:l},`${a.clusterId}-${a.attributeId}-unit`),e.jsx(se,{sx:yn,children:i==null||typeof i=="number"&&isNaN(i)||i==="NaN"?"---":i},`${a.clusterId}-${a.attributeId}-value`),l&&g===!1&&e.jsx(se,{sx:Gt,children:l},`${a.clusterId}-${a.attributeId}-unit`)]},`${a.clusterId}-${a.attributeId}-valueunitbox`)]},`${a.clusterId}-${a.attributeId}-box`)}function Pn({device:r,endpoint:c,id:a,deviceType:i,clusters:l}){const g=["Unknown","Good","Fair","Moderate","Poor","VeryPoor","Ext.Poor"];let b="";return s&&console.log(`Device "${r.name}" endpoint "${c}" id "${a}" deviceType "0x${i.toString(16).padStart(4,"0")}" clusters (${l?.length}):`,l),i===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batVoltage").map(t=>b=`${t.attributeLocalValue} mV`),Nn.includes(i)&&l.filter(t=>t.clusterName==="LevelControl"&&t.attributeName==="currentLevel").map(t=>b=`Level ${t.attributeValue}`),i===514&&l.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>b=`Position ${t.attributeValue/100}%`),i===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedHeatingSetpoint").map(t=>b=`Heat ${t.attributeValue/100}°C `),i===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedCoolingSetpoint").map(t=>b=b+`Cool ${t.attributeValue/100}°C`),i===118&&l.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>b=`${t.attributeLocalValue===0?"No CO detected":"CO alarm!"}`),i===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="voltage").map(t=>b=`${t.attributeLocalValue/1e3} V, `),i===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activeCurrent").map(t=>b=b+`${t.attributeLocalValue/1e3} A, `),i===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activePower").map(t=>b=b+`${t.attributeLocalValue/1e3} W`),e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0px",padding:"5px",width:"150px",height:"150px",borderColor:"var(--div-bg-color)",borderRadius:"5px",justifyContent:"space-between"},children:[i===19&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:t.attributeLocalValue===!0?e.jsx(at,{}):e.jsx(Vr,{}),iconColor:t.attributeLocalValue===!0?"green":"red",cluster:t,value:t.attributeLocalValue===!0?"Online":"Offline"})),i===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batPercentRemaining").map(t=>e.jsx(G,{icon:e.jsx(Ct,{}),cluster:t,value:t.attributeValue/2,unit:"%"})),i===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="wiredCurrentType").map(t=>e.jsx(G,{icon:e.jsx(rr,{}),cluster:t,value:t.attributeLocalValue===0?"AC":"DC"})),i===1293&&l.filter(t=>t.clusterName==="DeviceEnergyManagement"&&t.attributeName==="esaState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:xo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Offline":"Online"})),kn.includes(i)&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(_r,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),In.includes(i)&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(te,{path:bo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),Dn.includes(i)&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(te,{path:vo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),i===115&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:yo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===124&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:jo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===117&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===123&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(Et,{}),cluster:t,value:"Oven"})),i===112&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(Ar,{}),cluster:t,value:"Fridge"})),i===113&&l.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(G,{icon:e.jsx(te,{path:So,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),i===121&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(G,{icon:e.jsx(Et,{}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===122&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="fanMode").map(t=>e.jsx(G,{icon:e.jsx(te,{path:wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),i===120&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(te,{path:zt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Cooktop"})),i===119&&l.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(G,{icon:e.jsx(te,{path:zt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),i===116&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Robot"})),i===514&&l.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>e.jsx(G,{icon:e.jsx(Ur,{}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),i===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(G,{icon:e.jsx(te,{path:ko,size:"40px",color:"var(--primary-color)"}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),i===10&&l.filter(t=>t.clusterName==="DoorLock"&&t.attributeName==="lockState").map(t=>e.jsx(G,{icon:t.attributeValue==="1"?e.jsx(zr,{}):e.jsx(qr,{}),cluster:t,value:t.attributeValue==="1"?"Locked":"Unlocked"})),i===43&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(G,{icon:e.jsx(Br,{}),cluster:t,value:t.attributeValue,unit:"%"})),i===15&&l.filter(t=>t.clusterName==="Switch"&&t.attributeName==="currentPosition").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Io,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeValue,unit:"pos",prefix:!0})),i===39&&l.filter(t=>t.clusterName==="ModeSelect"&&t.attributeName==="currentMode").map(t=>e.jsx(G,{icon:e.jsx(Jr,{}),cluster:t,value:t.attributeValue,unit:"mode",prefix:!0})),i===771&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(G,{icon:e.jsx(Qr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),i===45&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(G,{icon:e.jsx(Vt,{}),cluster:t,value:t.attributeValue,unit:"%"})),i===114&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(G,{icon:e.jsx(Vt,{}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),i===67&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:e.jsx(Gr,{}),cluster:t,value:t.attributeLocalValue===!0?"Leak":"No leak"})),i===65&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:e.jsx(Kr,{}),cluster:t,value:t.attributeLocalValue===!0?"Freeze":"No freeze"})),i===68&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:e.jsx(Yr,{}),cluster:t,value:t.attributeLocalValue===!0?"Rain":"No rain"})),i===1292&&l.filter(t=>t.clusterName==="EnergyEvse"&&t.attributeName==="state").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Do,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Free":"In use"})),i===1295&&l.filter(t=>t.clusterName==="WaterHeaterManagement"&&t.attributeName==="tankPercentage").map(t=>e.jsx(G,{icon:e.jsx(te,{path:No,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Tank "+(t.attributeLocalValue??0)+"%"})),i===777&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Po,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"HeatPump"})),i===23&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Solar"})),i===24&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="featureMap").map(t=>e.jsx(G,{icon:e.jsx(te,{path:To,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Inverter"})),i===118&&l.find(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="featureMap"&&t.attributeLocalValue.smokeAlarm===!0)&&l.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="smokeState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:qt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No smoke":"Smoke!"})),i===118&&l.find(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="featureMap"&&t.attributeLocalValue.smokeAlarm===!1)&&l.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>e.jsx(G,{icon:e.jsx(te,{path:qt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No Co":"Co!"})),i===66&&l.filter(t=>t.clusterName==="ValveConfigurationAndControl"&&t.attributeName==="currentState").map(t=>e.jsx(G,{icon:e.jsx(Xr,{}),cluster:t,value:t.attributeLocalValue===0?"Closed":"Opened"})),i===44&&l.filter(t=>t.clusterName==="AirQuality"&&t.attributeName==="airQuality").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Fo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:g[t.attributeLocalValue??0]})),i===770&&l.filter(t=>t.clusterName==="TemperatureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(Zr,{}),cluster:t,value:t.attributeLocalValue/100,unit:"°C"})),i===775&&l.filter(t=>t.clusterName==="RelativeHumidityMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(te,{path:Lo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),i===774&&l.filter(t=>t.clusterName==="FlowMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(eo,{}),cluster:t,value:t.attributeLocalValue,unit:"l/h"})),i===773&&l.filter(t=>t.clusterName==="PressureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(to,{}),cluster:t,value:t.attributeLocalValue,unit:"hPa"})),i===21&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(G,{icon:t.attributeValue==="true"?e.jsx(ro,{}):e.jsx(oo,{}),cluster:t,value:t.attributeValue==="true"?"Closed":"Opened"})),i===263&&l.filter(t=>t.clusterName==="OccupancySensing"&&t.attributeName==="occupancy").map(t=>e.jsx(G,{icon:t.attributeValue==="{ occupied: true }"?e.jsx(no,{}):e.jsx(io,{}),cluster:t,value:t.attributeValue==="{ occupied: true }"?"Occupied":"Unocc."})),i===262&&l.filter(t=>t.clusterName==="IlluminanceMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(G,{icon:e.jsx(ao,{}),cluster:t,value:Math.round(Math.pow(10,t.attributeValue/1e4)),unit:"lx"})),i===1296&&l.filter(t=>t.clusterName==="ElectricalEnergyMeasurement"&&t.attributeName==="cumulativeEnergyImported").map(t=>e.jsx(G,{icon:e.jsx(so,{}),cluster:t,value:Math.round(t.attributeLocalValue?.energy/1e6),unit:"kwh"})),e.jsx(Z,{sx:jn,children:e.jsx(se,{sx:Cn,children:b})}),e.jsx(Z,{sx:Sn,children:e.jsx(se,{sx:wn,children:r.name})}),e.jsxs(Z,{sx:Mn,children:[s&&e.jsx(se,{sx:Wt,children:c}),e.jsx(se,{sx:Wt,children:a}),s&&e.jsxs(se,{sx:Wt,children:["0x",i.toString(16).padStart(4,"0")]})]})]})}function Wn({filter:r}){const{online:c,sendMessage:a,addListener:i,removeListener:l,getUniqueId:g}=o.useContext(be),[b,t]=o.useState({}),[d,y]=o.useState([]),[W,h]=o.useState([]),[L,V]=o.useState({}),[M,O]=o.useState({}),[u,z]=o.useState({}),[v,f]=o.useState(W),k=o.useRef(g());return o.useEffect(()=>{const R=C=>{if(C.src==="Matterbridge"&&C.dst==="Frontend"){if(C.method==="refresh_required"&&(s&&console.log(`DevicesIcons received refresh_required: changed=${C.params.changed} and sending api requests`),a({id:k.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:k.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:k.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),C.method==="/api/settings"&&C.response&&(s&&console.log("DevicesIcons received settings:",C.response),t(C.response)),C.method==="/api/plugins"&&C.response&&(s&&console.log("DevicesIcons received plugins:",C.response),y(C.response)),C.method==="/api/devices"&&C.response){s&&console.log(`DevicesIcons received ${C.response.length} devices:`,C.response),h(C.response);for(let m of C.response)s&&console.log("DevicesIcons sending /api/clusters"),a({id:k.current,sender:"Icons",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:m.pluginName,endpoint:m.endpoint}})}if(C.method==="/api/clusters"&&C.response){if(console.log(`DevicesIcons received for device "${C.response.deviceName}" serial "${C.response.serialNumber}" deviceType ${C.response.deviceTypes.join(" ")} clusters (${C.response.length}):`,C.response),C.response.length===0)return;const m=C.response.serialNumber;L[m]=[],M[m]=C.response.deviceTypes,u[m]=[];for(let H of C.response.clusters)L[m].find(j=>j.endpoint===H.endpoint)||L[m].push({endpoint:H.endpoint,id:H.id,deviceTypes:H.deviceTypes}),!["FixedLabel","Descriptor","Identify","Groups","PowerTopology"].includes(H.clusterName)&&u[m].push(H);V({...L}),O({...M}),z({...u}),s&&console.log(`DevicesIcons endpoints for "${m}":`,L[m]),s&&console.log(`DevicesIcons deviceTypes for "${m}":`,M[m]),s&&console.log(`DevicesIcons clusters for "${m}":`,u[m])}}};return i(R),s&&console.log("DevicesIcons useEffect webSocket mounted"),()=>{l(R),s&&console.log("DevicesIcons useEffect webSocket unmounted")}},[i,l,a]),o.useEffect(()=>(s&&console.log("DevicesIcons useEffect online mounting"),c&&(s&&console.log("DevicesIcons useEffect online sending api requests"),a({id:k.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:k.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:k.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),s&&console.log("DevicesIcons useEffect online mounted"),()=>{s&&console.log("DevicesIcons useEffect online unmounted")}),[c,a]),o.useEffect(()=>{if(r===""){f(W);return}const R=W.filter(C=>C.name.toLowerCase().includes(r)||C.serial.toLowerCase().includes(r));f(R)},[W,r]),s&&console.log("DevicesIcons rendering..."),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"auto"},children:v.map(R=>L[R.serial]&&L[R.serial].map(C=>C.deviceTypes.map(m=>e.jsx(Pn,{device:R,endpoint:C.endpoint,id:C.id,deviceType:m,clusters:u[R.serial].filter(H=>H.endpoint===C.endpoint)}))))})}const Tn=o.memo(Wn),lr=[{Header:"Plugin name",accessor:"pluginName"},{Header:"Device type",accessor:"type"},{Header:"Endpoint",accessor:"endpoint"},{Header:"Name",accessor:"name"},{Header:"Serial number",accessor:"serial"},{Header:"Unique ID",accessor:"uniqueId"},{Header:"Url",accessor:"configUrl"},{Header:"Config",accessor:"configButton",noSort:!0,Cell:({row:r})=>r.original.configUrl?e.jsx(J,{onClick:()=>window.open(r.original.configUrl,"_blank"),"aria-label":"Open Config",sx:{margin:0,padding:0},children:e.jsx(Je,{fontSize:"small"})}):null},{Header:"Cluster",accessor:"cluster"}],dr=[{Header:"Endpoint",accessor:"endpoint"},{Header:"Id",accessor:"id"},{Header:"Device Types",accessor:"deviceTypes",Cell:({value:r})=>Array.isArray(r)?r.map(c=>`0x${c.toString(16).padStart(4,"0")}`).join(", "):r},{Header:"Cluster Name",accessor:"clusterName"},{Header:"Cluster ID",accessor:"clusterId"},{Header:"Attribute Name",accessor:"attributeName"},{Header:"Attribute ID",accessor:"attributeId"},{Header:"Attribute Value",accessor:"attributeValue",Cell:({value:r})=>e.jsx($,{title:r,componentsProps:{tooltip:{sx:{fontSize:"14px",fontWeight:"normal",color:"#ffffff",backgroundColor:"var(--primary-color)"}}},children:e.jsx("div",{style:{maxWidth:"500px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r})})}],Fn=r=>`${r.pluginName}::${r.uniqueId}`,Ln=r=>`${r.endpoint}::${r.clusterName}::${r.attributeName}`;function Hn({data:r,columnVisibility:c,setPlugin:a,setEndpoint:i,setDeviceName:l}){const[g,b]=o.useState(null),t=o.useMemo(()=>lr.filter(M=>c[M.accessor]),[c]),{getTableProps:d,getTableBodyProps:y,headerGroups:W,rows:h,prepareRow:L}=Ue.useTable({columns:t,data:r,getRowId:Fn},Ue.useSortBy),V=M=>{if(M.id===g){b(null),a(null),i(null),l(null),s&&console.log("Device unclicked:",M.id,"selectedDeviceIndex:",g);return}b(M.id),a(M.original.pluginName),i(M.original.endpoint),l(M.original.name),s&&console.log("Device clicked:",M.id,"selectedDeviceIndex:",g,"pluginName:",M.original.pluginName,"endpoint:",M.original.endpoint)};return e.jsxs("table",{...d(),style:{margin:"-1px",border:"1px solid var(--table-border-color)"},children:[e.jsx("thead",{children:W.map(M=>e.jsx("tr",{...M.getHeaderGroupProps(),children:M.headers.map(O=>e.jsxs("th",{...O.getHeaderProps(O.noSort?void 0:O.getSortByToggleProps()),children:[O.render("Header"),!O.noSort&&e.jsx("span",{style:{margin:"0px",marginLeft:"5px",padding:"0px"},children:O.isSorted?O.isSortedDesc?e.jsx(te,{path:Tt,size:"15px"}):e.jsx(te,{path:Ft,size:"15px"}):null})]}))}))}),e.jsx("tbody",{...y(),children:h.map((M,O)=>(L(M),e.jsx("tr",{className:O%2===0?"table-content-even":"table-content-odd",...M.getRowProps(),onClick:()=>V(M),style:{backgroundColor:g===M.id?"var(--table-selected-bg-color)":"",cursor:"pointer"},children:M.cells.map(u=>e.jsx("td",{...u.getCellProps(),children:u.render("Cell")}))})))})]})}function Rn({data:r,columnVisibility:c}){const a=o.useMemo(()=>dr.filter(d=>c[d.accessor]),[c]),{getTableProps:i,getTableBodyProps:l,headerGroups:g,rows:b,prepareRow:t}=Ue.useTable({columns:a,data:r,getRowId:Ln},Ue.useSortBy);return e.jsxs("table",{...i(),style:{margin:"-1px"},children:[e.jsx("thead",{children:g.map(d=>e.jsx("tr",{...d.getHeaderGroupProps(),children:d.headers.map(y=>e.jsx("th",{...y.getHeaderProps(),children:y.render("Header")}))}))}),e.jsx("tbody",{...l(),children:b.map((d,y)=>(t(d),e.jsx("tr",{className:y%2===0?"table-content-even":"table-content-odd",...d.getRowProps(),children:d.cells.map(W=>e.jsx("td",{...W.getCellProps(),children:W.render("Cell")}))})))})]})}function $n(){const{online:r,sendMessage:c,addListener:a,removeListener:i,getUniqueId:l}=o.useContext(be),[g,b]=o.useState([]),[t,d]=o.useState([]),[y,W]=o.useState(null),[h,L]=o.useState(null),[V,M]=o.useState(null),[O,u]=o.useState(0),[z,v]=o.useState(!1),[f,k]=o.useState({pluginName:!0,type:!0,endpoint:!0,name:!0,serial:!0,uniqueId:!1,configUrl:!1,configButton:!0,cluster:!0}),[R,C]=o.useState(!1),[m,H]=o.useState({endpoint:!0,id:!0,deviceTypes:!0,clusterName:!0,clusterId:!0,attributeName:!0,attributeId:!0,attributeValue:!0}),[j,x]=o.useState(""),[w,q]=o.useState(g),[de,xe]=o.useState("icon"),S=o.useRef(l());o.useEffect(()=>{const U=D=>{if(s&&console.log("Devices received WebSocket Message:",D),D.src==="Matterbridge"&&D.dst==="Frontend"&&(D.method==="refresh_required"&&D.params.changed==="devices"&&(s&&console.log(`Devices received refresh_required: changed=${D.params.changed} and sending /api/devices request`),c({id:S.current,sender:"Devices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),D.method==="/api/devices"&&(s&&console.log(`Devices received ${D.response.length} devices:`,D.response),b(D.response)),D.method==="/api/clusters")){console.log(`Devices received ${D.response.length} clusters:`,D.response),d(D.response.clusters);const P={};for(const N of D.response.clusters)s&&console.log("Cluster:",N.endpoint),P[N.endpoint]?P[N.endpoint]++:P[N.endpoint]=1;u(Object.keys(P).length)}};return a(U),s&&console.log("Devices added WebSocket listener"),()=>{i(U),s&&console.log("Devices removed WebSocket listener")}},[a,i,c]),o.useEffect(()=>{r&&(s&&console.log("Devices sending api requests"),c({id:S.current,sender:"Devices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:S.current,sender:"Devices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:S.current,sender:"Devices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}))},[r,c]),o.useEffect(()=>{y&&h&&(s&&console.log("Devices sending /api/clusters"),c({id:S.current,sender:"Devices",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:y,endpoint:h}}))},[y,h,c]);const p=()=>{v(!z)},E=U=>{k(D=>{const P={...D,[U]:!D[U]};return localStorage.setItem("devicesColumnVisibility",JSON.stringify(P)),P})};o.useEffect(()=>{const U=localStorage.getItem("devicesColumnVisibility");U&&k(JSON.parse(U))},[]);const I=()=>{C(!R)},Y=U=>{H(D=>{const P={...D,[U]:!D[U]};return localStorage.setItem("clustersColumnVisibility",JSON.stringify(P)),P})};o.useEffect(()=>{const U=localStorage.getItem("clustersColumnVisibility");U&&H(JSON.parse(U))},[]);const me=U=>{x(U.target.value.toLowerCase()),localStorage.setItem("devicesFilter",U.target.value.toLowerCase())},Me=U=>{xe(U),localStorage.setItem("devicesViewMode",U)};return o.useEffect(()=>{if(j===""){q(g);return}const U=g.filter(D=>D.name.toLowerCase().includes(j)||D.serial.toLowerCase().includes(j));q(U)},[g,j]),o.useEffect(()=>{const U=localStorage.getItem("devicesFilter");U&&x(U)},[]),o.useEffect(()=>{const U=localStorage.getItem("devicesViewMode");U&&xe(U)},[]),s&&console.log("Devices rendering..."),r?e.jsxs("div",{className:"MbfPageDiv",children:[e.jsxs("div",{className:"MbfWindowBodyRow",style:{justifyContent:"space-between",padding:0,gap:"20px",width:"100%",height:"45px",minHeight:"45px",maxHeight:"45px"},children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(se,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{variant:"outlined",value:j,onChange:me,placeholder:"Enter the device name or serial number",sx:{width:"320px"},InputProps:{style:{backgroundColor:"var(--main-bg-color)"}}})]}),e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(se,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"View mode:"}),e.jsx(J,{onClick:()=>Me("table"),"aria-label":"Table View",disabled:de==="table",children:e.jsx($,{title:"Table View",children:e.jsx(lo,{style:{color:de==="table"?"var(--main-icon-color)":"var(--primary-color)"}})})}),e.jsx(J,{onClick:()=>Me("icon"),"aria-label":"Icon View",disabled:de==="icon",children:e.jsx($,{title:"Icon View (beta)",children:e.jsx(co,{style:{color:de==="icon"?"var(--main-icon-color)":"var(--primary-color)"}})})})]})]}),e.jsxs(De,{open:z,onClose:p,children:[e.jsx(Ne,{children:"Configure Devices Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:lr.map(U=>e.jsx(Te,{control:e.jsx(Fe,{disabled:["pluginName","name","configButton"].includes(U.accessor),checked:f[U.accessor],onChange:()=>E(U.accessor)}),label:U.Header},U.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:p,children:"Close"})})]}),de==="table"&&e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",maxHeight:`${y&&h?"50%":"100%"}`,width:"100%",flex:"1 1 auto",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Registered devices"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(J,{onClick:p,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})})]}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0",padding:"0",gap:"0"},children:e.jsx(Hn,{data:w,columnVisibility:f,setPlugin:W,setEndpoint:L,setDeviceName:M})}),e.jsx("div",{className:"MbfWindowFooter",style:{borderTop:"1px solid var(--table-border-color)",justifyContent:"flex-start"},children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",textAlign:"left"},children:["Total devices: ",w.length.toString()]})})]}),e.jsxs(De,{open:R,onClose:I,children:[e.jsx(Ne,{children:"Configure Clusters Columns"}),e.jsx(Pe,{children:e.jsx(st,{children:dr.map(U=>e.jsx(Te,{control:e.jsx(Fe,{disabled:["clusterName","attributeName","attributeValue"].includes(U.accessor),checked:m[U.accessor],onChange:()=>Y(U.accessor)}),label:U.Header},U.accessor))})}),e.jsx(Le,{children:e.jsx(ne,{onClick:I,children:"Close"})})]}),de==="table"&&y&&h&&e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",height:"50%",maxHeight:"50%",width:"100%",flex:"1 1 auto",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsxs("div",{className:"MbfWindowHeaderText",style:{display:"flex",flexDirection:"row",justifyContent:"space-between"},children:[e.jsxs("p",{style:{margin:"0px",padding:"0px"},children:['Clusters for device "',V,'" on endpoint ',h]}),e.jsx(J,{onClick:I,"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:"Configure columns",children:e.jsx(Je,{style:{color:"var(--header-text-color)",fontSize:"19px"}})})})]})}),e.jsx("div",{className:"MbfWindowBodyColumn",style:{margin:"0",padding:"0",gap:"0"},children:e.jsx(Rn,{data:t,columnVisibility:m})}),e.jsx("div",{className:"MbfWindowFooter",style:{borderTop:"1px solid var(--table-border-color)",justifyContent:"flex-start"},children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontWeight:"normal",textAlign:"left"},children:["Total child endpoints: ",O-1]})})]}),de==="icon"&&e.jsx(Tn,{filter:j,devices:w})]}):e.jsx(Qe,{})}const On=o.memo($n);function En(){const[r,c]=o.useState(localStorage.getItem("logFilterLevel")??"info"),[a,i]=o.useState(localStorage.getItem("logFilterSearch")??"*"),[l,g]=o.useState(localStorage.getItem("logAutoScroll")!=="false"),{setMessages:b,setLogFilters:t,online:d,setAutoScroll:y}=o.useContext(be),W=M=>{c(M.target.value),t(M.target.value,a),localStorage.setItem("logFilterLevel",M.target.value),s&&console.log("handleChangeLevel called with value:",M.target.value)},h=M=>{i(M.target.value),t(r,M.target.value),localStorage.setItem("logFilterSearch",M.target.value),s&&console.log("handleChangeSearch called with value:",M.target.value)},L=M=>{g(M.target.checked),y(M.target.checked),localStorage.setItem("logAutoScroll",M.target.value?"true":"false"),s&&console.log("handleAutoScrollChange called with value:",M.target.checked)},V=()=>{s&&console.log("handleClearLogsClick called"),b([])};return s&&console.log("Logs rendering..."),d?e.jsxs("div",{className:"MbfPageDiv",children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between",margin:"0px",padding:"0px",gap:"10px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(_t,{id:"select-level",style:{color:"var(--div-text-color)"},children:"Filter log by level:"}),e.jsxs(ot,{style:{height:"30px",backgroundColor:"var(--main-bg-color)"},labelId:"select-level",id:"debug-level",value:r,onChange:W,children:[e.jsx(F,{value:"debug",children:"Debug"}),e.jsx(F,{value:"info",children:"Info"}),e.jsx(F,{value:"notice",children:"Notice"}),e.jsx(F,{value:"warn",children:"Warn"}),e.jsx(F,{value:"error",children:"Error"}),e.jsx(F,{value:"fatal",children:"Fatal"})]}),e.jsx(_t,{id:"search",style:{color:"var(--div-text-color)"},children:"Filter log by text:"}),e.jsx(pe,{style:{width:"300px"},size:"small",id:"logsearch",variant:"outlined",value:a,onChange:h,InputProps:{style:{height:"30px",padding:"0 0px",backgroundColor:"var(--main-bg-color)"}}}),e.jsx(Te,{control:e.jsx(Fe,{checked:l,onChange:L}),label:"Auto scroll",style:{color:"var(--div-text-color)"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:e.jsx($,{title:"Clear the logs",children:e.jsx(ne,{onClick:V,endIcon:e.jsx(St,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Clear"})})})]}),e.jsx("div",{style:{flex:"1",overflow:"auto",margin:"0px",padding:"0px"},children:e.jsx(ar,{})})]}):e.jsx(Qe,{})}const Vn=({open:r,ip:c,onClose:a,onSave:i})=>{const l=c?c.split(".").slice(0,3).join(".")+".1":"",[g,b]=o.useState("dhcp"),[t,d]=o.useState({ip:c??"",subnet:"255.255.255.0",gateway:l,dns:l}),y=L=>V=>{d({...t,[L]:V.target.value})},W=()=>{a()},h=()=>{const L=g==="static"?{type:g,...t}:{type:g};i(L),a()};return e.jsxs(De,{open:r,onClose:(L,V)=>{V==="backdropClick"||V==="escapeKeyDown"||a()},maxWidth:"sm",style:{maxWidth:"550px",margin:"auto"},children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:"Network Configuration"})]})}),e.jsxs(Pe,{dividers:!0,children:[e.jsxs(or,{component:"fieldset",fullWidth:!0,children:[e.jsx(Ie,{component:"legend",children:"Select IP Configuration"}),e.jsxs(nr,{row:!0,value:g,onChange:L=>b(L.target.value),children:[e.jsx(Te,{value:"dhcp",control:e.jsx(wt,{}),label:"DHCP"}),e.jsx(Te,{value:"static",control:e.jsx(wt,{}),label:"Static"})]})]}),g==="static"&&e.jsxs(Ae,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"IP Address",fullWidth:!0,value:t.ip,onChange:y("ip")})}),e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"Subnet Mask",fullWidth:!0,value:t.subnet,onChange:y("subnet")})}),e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"Gateway",fullWidth:!0,value:t.gateway,onChange:y("gateway")})}),e.jsx(Ae,{size:6,children:e.jsx(pe,{label:"DNS Server",fullWidth:!0,value:t.dns,onChange:y("dns")})})]})]}),e.jsxs(Le,{children:[e.jsx(ne,{onClick:W,children:"Cancel"}),e.jsx(ne,{variant:"contained",onClick:h,children:"Save"})]})]})},_n=({open:r,onClose:c,onSave:a})=>{const[i,l]=o.useState(""),[g,b]=o.useState(""),t=V=>{l(V.target.value)},d=V=>{b(V.target.value)},y=i.length>0&&i===g,W=()=>{c()},h=()=>{y&&(a(i),c())},L=()=>{a(""),c()};return e.jsxs(De,{open:r,onClose:(V,M)=>{M==="backdropClick"||M==="escapeKeyDown"||c()},maxWidth:"sm",style:{maxWidth:"500px",margin:"auto"},disableEscapeKeyDown:!0,children:[e.jsx(Ne,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:"Change Password"})]})}),e.jsx(Pe,{dividers:!0,children:e.jsx(or,{component:"fieldset",fullWidth:!0,sx:{margin:0,padding:0,gap:"20px"},children:e.jsxs(Ae,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Ae,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"New Password",size:"small",variant:"outlined",fullWidth:!0,value:i,onChange:t})}),e.jsx(Ae,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"Confirm Password",size:"small",variant:"outlined",fullWidth:!0,value:g,onChange:d,error:g!==""&&i!==g,helperText:g!==""&&i!==g?"Passwords do not match":""})})]})})}),e.jsxs(Le,{children:[e.jsx(ne,{onClick:W,children:"Cancel"}),e.jsx(ne,{variant:"contained",onClick:h,disabled:!y,children:"Change"}),e.jsx(ne,{variant:"contained",onClick:L,children:"Reset"})]})]})};function An(){const{online:r,addListener:c,removeListener:a,sendMessage:i,getUniqueId:l}=o.useContext(be),[g,b]=o.useState(null),[t,d]=o.useState(null),y=o.useRef(l());return o.useEffect(()=>{const W=h=>{h.src==="Matterbridge"&&h.dst==="Frontend"&&(h.method==="refresh_required"&&h.params.changed==="settings"&&(s&&console.log(`Settings received refresh_required: changed=${h.params.changed} and sending /api/settings request`),i({id:y.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),h.method==="/api/settings"&&(s&&console.log("Settings received /api/settings:",h.response),b(h.response.matterbridgeInformation),d(h.response.systemInformation)))};return c(W),s&&console.log("Settings added WebSocket listener"),()=>{a(W),s&&console.log("Settings removed WebSocket listener")}},[c,a,i]),o.useEffect(()=>{r&&(s&&console.log("Settings received online"),i({id:y.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[r,i]),g?(s&&console.log("Settings rendering..."),r?e.jsx("div",{className:"MbfPageDiv",children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"20px",width:"100%"},children:[e.jsx(Un,{matterbridgeInfo:g,systemInfo:t}),e.jsx(zn,{matterbridgeInfo:g}),e.jsx(qn,{matterbridgeInfo:g})]})}):e.jsx(Qe,{})):null}function Un({matterbridgeInfo:r,systemInfo:c}){const{sendMessage:a,getUniqueId:i}=o.useContext(be),[l,g]=o.useState("bridge"),[b,t]=o.useState("Info"),[d,y]=o.useState(!1),[W,h]=o.useState("dark"),[L,V]=o.useState(localStorage.getItem("homePagePlugins")!=="false"),[M,O]=o.useState(localStorage.getItem("homePageMode")??"logs"),[u,z]=o.useState(localStorage.getItem("virtualMode")??"outlet"),v=o.useRef(i()),[f,k]=o.useState(!1),R=()=>k(!1),C=I=>{s&&console.log("handleSaveNetConfig called with config:",I),a({id:v.current,sender:"Settings",method:"/api/shellynetconfig",src:"Frontend",dst:"Matterbridge",params:I})},[m,H]=o.useState(!1),j=()=>H(!1),x=I=>{s&&console.log("handleSaveChangePassword called with password:",I),a({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setpassword",value:I}})};o.useEffect(()=>{r.bridgeMode!==void 0&&(g(r.bridgeMode==="bridge"?"bridge":"childbridge"),t(r.loggerLevel.charAt(0).toUpperCase()+r.loggerLevel.slice(1)),y(r.fileLogger),z(r.virtualMode))},[r]),o.useEffect(()=>{const I=localStorage.getItem("frontendTheme");I&&h(I)},[]);const w=I=>{s&&console.log("handleChangeBridgeMode called with value:",I.target.value),g(I.target.value),a({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setbridgemode",value:I.target.value}})},q=I=>{s&&console.log("handleChangeMbLoggerLevel called with value:",I.target.value),t(I.target.value),a({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmbloglevel",value:I.target.value}})},de=I=>{s&&console.log("handleLogOnFileMbChange called with value:",I.target.checked),y(I.target.checked),a({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmblogfile",value:I.target.checked}})},xe=I=>{const Y=I.target.value;s&&console.log("handleChangeTheme called with value:",Y),h(Y),localStorage.setItem("frontendTheme",Y),document.body.setAttribute("frontend-theme",Y)},S=I=>{const Y=I.target.checked;s&&console.log("handleChangeHomePagePlugins called with value:",Y),V(Y),localStorage.setItem("homePagePlugins",Y?"true":"false")},p=I=>{const Y=I.target.value;s&&console.log("handleChangeHomePageMode called with value:",Y),O(Y),localStorage.setItem("homePageMode",Y)},E=I=>{const Y=I.target.value;s&&console.log("handleChangeVirtualMode called with value:",Y),z(Y),localStorage.setItem("virtualMode",Y),a({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setvirtualmode",value:Y}})};return e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge settings"})}),e.jsx(Vn,{open:f,ip:c.ipv4Address,onClose:R,onSave:C}),e.jsx(_n,{open:m,onClose:j,onSave:x}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(Z,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"matterbridgeInfo-mode",children:"Matterbridge mode:"}),e.jsxs(nr,{row:!0,name:"mode-buttons-group",value:l,onChange:w,children:[e.jsx(Te,{value:"bridge",control:e.jsx(wt,{}),label:"Bridge",disabled:r.readOnly===!0}),e.jsx(Te,{value:"childbridge",control:e.jsx(wt,{}),label:"Childbridge",disabled:r.readOnly===!0})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"mblogger-level-label",children:"Logger level:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"mblogger-level-label",id:"mblogger-level",value:b,onChange:q,children:[e.jsx(F,{value:"Debug",children:"Debug"}),e.jsx(F,{value:"Info",children:"Info"}),e.jsx(F,{value:"Notice",children:"Notice"}),e.jsx(F,{value:"Warn",children:"Warn"}),e.jsx(F,{value:"Error",children:"Error"}),e.jsx(F,{value:"Fatal",children:"Fatal"})]}),e.jsx(Te,{style:{padding:"0px",margin:"0px"},control:e.jsx(Fe,{checked:d,onChange:de,name:"logOnFileMb"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-theme-label",children:"Frontend theme:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"frontend-theme-label",id:"frontend-theme",value:W,onChange:xe,children:[e.jsx(F,{value:"classic",children:"Classic"}),e.jsx(F,{value:"light",children:"Light"}),e.jsx(F,{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-home-plugin-label",children:"Home page plugins:"}),e.jsx(Fe,{checked:L,onChange:S,name:"showPlugins"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-home-label",children:"Home page bottom panel:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"frontend-home-label",id:"frontend-home",value:M,onChange:p,children:[e.jsx(F,{value:"logs",children:"Logs"}),e.jsx(F,{value:"devices",children:"Devices"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"10px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"frontend-virtual-label",children:"Virtual devices:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"frontend-virtual-label",id:"frontend-virtual",value:u,onChange:E,children:[e.jsx(F,{value:"disabled",children:"Disabled"}),e.jsx(F,{value:"outlet",children:"Outlet"}),e.jsx(F,{value:"light",children:"Light"}),e.jsx(F,{value:"switch",children:"Switch"}),e.jsx(F,{value:"mounted_switch",children:"Mounted Switch"})]})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>H(!0),children:"Change password"})}),r.shellyBoard&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>k(!0),children:"Configure IP"})})]})})]})}function zn({matterbridgeInfo:r}){const{sendMessage:c,getUniqueId:a}=o.useContext(be),[i,l]=o.useState("Info"),[g,b]=o.useState(!1),[t,d]=o.useState(""),[y,W]=o.useState(""),[h,L]=o.useState(""),[V,M]=o.useState(),[O,u]=o.useState(),[z,v]=o.useState(),f=o.useRef(a());o.useEffect(()=>{r.bridgeMode!==void 0&&(l(["Debug","Info","Notice","Warn","Error","Fatal"][r.matterLoggerLevel]),b(r.matterFileLogger),d(r.matterMdnsInterface),W(r.matterIpv4Address),L(r.matterIpv6Address),M(r.matterPort),u(r.matterDiscriminator),v(r.matterPasscode))},[r]);const k=q=>{s&&console.log("handleChangeMjLoggerLevel called with value:",q.target.value),l(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjloglevel",value:q.target.value}})},R=q=>{s&&console.log("handleLogOnFileMjChange called with value:",q.target.checked),b(q.target.checked),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjlogfile",value:q.target.checked}})},C=q=>{s&&console.log("handleChangeMdnsInterface called with value:",q.target.value),d(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmdnsinterface",value:q.target.value}})},m=q=>{s&&console.log("handleChangeIpv4Address called with value:",q.target.value),W(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv4address",value:q.target.value}})},H=q=>{s&&console.log("handleChangeIpv6Address called with value:",q.target.value),L(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv6address",value:q.target.value}})},j=q=>{s&&console.log("handleChangeMatterPort called with value:",q.target.value),M(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterport",value:q.target.value}})},x=q=>{s&&console.log("handleChangeMatterDiscriminator called with value:",q.target.value),u(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterdiscriminator",value:q.target.value}})},w=q=>{s&&console.log("handleChangemMatterPasscode called with value:",q.target.value),v(q.target.value),c({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterpasscode",value:q.target.value}})};return e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matter settings"})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(Z,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},id:"mjdebug-info",children:"Logger level:"}),e.jsxs(ot,{style:{height:"30px"},labelId:"select-mjlevel",id:"mjdebug-level",value:i,onChange:k,children:[e.jsx(F,{value:"Debug",children:"Debug"}),e.jsx(F,{value:"Info",children:"Info"}),e.jsx(F,{value:"Notice",children:"Notice"}),e.jsx(F,{value:"Warn",children:"Warn"}),e.jsx(F,{value:"Error",children:"Error"}),e.jsx(F,{value:"Fatal",children:"Fatal"})]}),e.jsx(Te,{style:{padding:"0px",margin:"0px"},control:e.jsx(Fe,{checked:g,onChange:R,name:"logOnFileMj"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Mdns interface:"}),e.jsx(pe,{value:t,onChange:C,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Ipv4 address:"}),e.jsx(pe,{value:y,onChange:m,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Ipv6 address:"}),e.jsx(pe,{value:h,onChange:H,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Commissioning port:"}),e.jsx(pe,{value:V,onChange:j,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Commissioning discriminator:"}),e.jsx(pe,{value:O,onChange:x,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ie,{style:{padding:"0px",margin:"0px"},children:"Commissioning passcode:"}),e.jsx(pe,{value:z,onChange:w,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]})]})})]})}function qn({matterbridgeInfo:r}){return e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge info"})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(Z,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[" ",e.jsx(Be,{value:r.matterbridgeVersion,label:"Current Version"}),e.jsx(Be,{value:r.matterbridgeLatestVersion,label:"Latest Version"}),e.jsx(Be,{value:r.homeDirectory,label:"Home Directory"}),e.jsx(Be,{value:r.rootDirectory,label:"Root Directory"}),e.jsx(Be,{value:r.matterbridgeDirectory,label:"Matterbridge Storage Directory"}),e.jsx(Be,{value:r.matterbridgePluginDirectory,label:"Matterbridge Plugin Directory"}),e.jsx(Be,{value:r.globalModulesDirectory,label:"Global Module Directory"})]})})]})}function Be({value:r,label:c}){return e.jsx(pe,{focused:!0,value:r,size:"small",label:c,variant:"standard",sx:{width:"400px"},InputProps:{readOnly:!0,sx:{color:"var(--div-text-color)","&:before":{borderBottomColor:"var(--main-label-color)"},"&:after":{borderBottomColor:"var(--main-label-color)"}}},InputLabelProps:{sx:{marginTop:"3px",color:"var(--main-label-color)","&.Mui-focused":{color:"var(--main-label-color)"}}}})}function Bn(r,c,a){const i=r?.[a],l=c?.[a];return i==null&&l==null?0:i==null?-1:l==null?1:typeof i=="boolean"&&typeof l=="boolean"?i===l?0:i?1:-1:typeof i=="number"&&typeof l=="number"?i-l:String(i).localeCompare(String(l))}function Jn({name:r,columns:c,rows:a,getRowKey:i,footerLeft:l,footerRight:g}){const b=o.useRef(new WeakMap),t=o.useRef(1),d=m=>{if(typeof i=="string"&&m&&m[i]!=null)return m[i];if(typeof i=="function"){const x=i(m);if(x!=null)return x}const H=c?.[0]?.id;if(H&&m&&m[H]!=null)return m[H];console.warn(`MbfTable(${r}): using fallback stable row key; consider providing getRowKey prop for better React performance`);let j=b.current.get(m);return j||(j=`rk_${t.current++}`,b.current.set(m,j)),j},[y,W]=o.useState(localStorage.getItem(`${r}_table_order_by`)||null),[h,L]=o.useState(localStorage.getItem(`${r}_table_order`)||null),[V,M]=o.useState(!1),[O,u]=o.useState(()=>{try{const m=localStorage.getItem(`${r}_column_visibility`);if(m)return JSON.parse(m)}catch{}return{}}),z=o.useMemo(()=>{const m={};for(const H of c)H.hidden||(m[H.id]=H.required?!0:O[H.id]!==!1);return m},[c,O]),v=o.useMemo(()=>{if(!y||!h)return a;const m=c.find(j=>j.id===y);if(!m||m.nosort)return a;const H=a.map((j,x)=>({el:j,index:x}));return H.sort((j,x)=>{const w=Bn(j.el,x.el,y);return w!==0?h==="asc"?w:-w:j.index-x.index}),H.map(j=>j.el)},[a,y,h,c]),f=m=>{if(y!==m||!y){W(m),L("asc"),localStorage.setItem(`${r}_table_order_by`,m),localStorage.setItem(`${r}_table_order`,"asc");return}if(h==="asc"){L("desc"),localStorage.setItem(`${r}_table_order`,"desc");return}W(null),L(null),localStorage.removeItem(`${r}_table_order_by`),localStorage.removeItem(`${r}_table_order`)},k=()=>{M(!V)},R=m=>{u(H=>{const j=c.find(q=>q.id===m);if(j&&j.required)return H;const x=z[m]!==!1,w={...H};x?w[m]=!1:delete w[m];try{localStorage.setItem(`${r}_column_visibility`,JSON.stringify(w))}catch{}return w})},C=()=>{const m={};u(m);try{localStorage.setItem(`${r}_column_visibility`,JSON.stringify(m))}catch{}};return console.log(`Rendering table ${r}${y&&h?` ordered by ${y}:${h}`:""}`),e.jsxs("div",{style:{display:"flex",flexDirection:"column",margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",height:"100%",minHeight:0,overflow:"hidden"},children:[e.jsxs(De,{open:V,onClose:(m,H)=>{H==="backdropClick"||H==="escapeKeyDown"||k()},disableEscapeKeyDown:!0,disableRestoreFocus:!0,children:[e.jsx(Ne,{gap:"20px",children:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"32px",width:"32px"}}),e.jsx("h4",{style:{margin:0},children:`Configure ${r} columns`})]})}),e.jsx(Pe,{children:e.jsx(st,{children:c.filter(m=>!m.hidden).map(m=>e.jsx(Te,{control:e.jsx(Fe,{disabled:!!m.required,checked:m.required?!0:z[m.id]!==!1,onChange:()=>R(m.id)}),label:m.label},m.id))})}),e.jsxs(Le,{children:[e.jsx(ne,{onClick:C,children:"Reset"}),e.jsx(ne,{variant:"contained",onClick:m=>{if(m?.currentTarget&&typeof m.currentTarget.blur=="function")try{m.currentTarget.blur()}catch{}const H=document.activeElement;if(H&&H instanceof HTMLElement&&typeof H.blur=="function")try{H.blur()}catch{}k()},children:"Close"})]})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between",borderBottom:"none"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:r}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(J,{onClick:m=>{if(m?.currentTarget?.blur)try{m.currentTarget.blur()}catch{}k()},"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:`Configure ${r} columns`,children:e.jsx(te,{path:Ho,size:"20px",style:{color:"var(--header-text-color)"}})})})})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",flex:"1 1 auto",minHeight:0,width:"100%",overflow:"auto",margin:"0px",padding:"0px",gap:"0"},children:e.jsxs("table",{"aria-label":`${r} table`,style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{style:{position:"sticky",top:0,zIndex:10,border:"none",color:"var(--header-text-color)",backgroundColor:"var(--header-bg-color"},children:e.jsx("tr",{style:{height:"30px",minHeight:"30px"},children:c.map(m=>{if(m.hidden||!m.required&&z[m.id]===!1)return null;const H=!m.nosort,j=H&&y===m.id&&!!h;return e.jsxs("th",{onClick:H?()=>f(m.id):void 0,style:{margin:"0",padding:"4px 8px",position:"sticky",top:0,minWidth:m.minWidth,maxWidth:m.maxWidth,textAlign:m.align||"left",cursor:H?"pointer":"default",border:"none",color:"var(--header-text-color)",backgroundColor:"var(--header-bg-color)",whiteSpace:m.maxWidth?"nowrap":void 0,overflow:m.maxWidth?"hidden":void 0,textOverflow:m.maxWidth?"ellipsis":void 0},"aria-sort":H?j?h==="asc"?"ascending":"descending":"none":void 0,children:[m.label,j&&e.jsxs("span",{style:{marginLeft:6},children:[h==="asc"&&e.jsx(te,{path:Ft,size:"15px"}),h==="desc"&&e.jsx(te,{path:Tt,size:"15px"})]})]},m.id)})})}),e.jsx("tbody",{children:v.map((m,H)=>{const j=d(m);return e.jsx("tr",{className:H%2===0?"table-content-even":"table-content-odd",style:{height:"30px",minHeight:"30px",border:"none",borderCollapse:"collapse"},children:c.map(x=>{if(x.hidden||!x.required&&z[x.id]===!1)return null;const w=m[x.id];return e.jsx("td",{style:{border:"none",borderCollapse:"collapse",textAlign:x.align||"left",padding:"4px 8px",margin:"0",maxWidth:x.maxWidth,whiteSpace:x.maxWidth?"nowrap":void 0,overflow:x.maxWidth?"hidden":void 0,textOverflow:x.maxWidth?"ellipsis":void 0},children:typeof x.render=="function"?x.render(w,j,m,x):typeof w=="boolean"?e.jsx(Fe,{checked:w,disabled:!0,size:"small",sx:{m:0,p:0,color:"var(--table-text-color)","&.Mui-disabled":{color:"var(--table-text-color)",opacity:.7}}}):x.format&&typeof w=="number"?x.format(w):w!=null?String(w):null},x.id)})},j)})})]})}),e.jsxs("div",{className:"MbfWindowFooter",style:{height:"30px",minHeight:"30px",justifyContent:"space-between",border:"none"},children:[e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:l}),e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:g})]})]})}const Qn=o.memo(Jn);function Gn(){const{online:r,sendMessage:c,addListener:a,removeListener:i,getUniqueId:l}=o.useContext(be),{showSnackbarMessage:g,closeSnackbarMessage:b}=o.useContext(nt),[t,d]=o.useState(null),[y,W]=o.useState(null),[h,L]=o.useState(null),[V,M]=o.useState(null),[O,u]=o.useState({cpuUsage:0}),[z,v]=o.useState({totalMemory:"",freeMemory:"",heapTotal:"",heapUsed:"",external:"",arrayBuffers:"",rss:""}),[f,k]=o.useState({systemUptime:"",processUptime:""}),R=o.useRef(-1),[C,m]=o.useState(()=>cr);R.current||(R.current=l(),console.log("Test uniqueId:",R)),o.useEffect(()=>{console.log("Test useEffect WebSocketMessage mounting");const j=x=>{if(x.src==="Matterbridge"&&x.dst==="Frontend"){if(fe(x)&&x.method==="restart_required"&&(console.log("Test received restart_required"),g("Restart required",0)),fe(x)&&x.method==="refresh_required"&&(console.log(`Test received refresh_required: changed=${x.params.changed} and sending api requests`),g("Refresh required",0),c({id:R.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:R.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:R.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),fe(x)&&x.method==="memory_update"&&(console.log("Test received memory_update",x),v(x.params)),fe(x)&&x.method==="cpu_update"&&(console.log("Test received cpu_update",x),u(x.params)),fe(x)&&x.method==="uptime_update"&&(console.log("Test received uptime_update",x),k(x.params)),Ve(x)&&x.method==="/api/settings"&&x.response&&(console.log("Test received /api/settings:",x.response),g("Test received /api/settings"),d(x.response)),Ve(x)&&x.method==="/api/plugins"&&x.response&&(console.log(`Test received ${x.response.length} plugins:`,x.response),g("Test received /api/plugins"),W(x.response)),Ve(x)&&x.method==="/api/devices"&&x.response){console.log(`Test received ${x.response.length} devices:`,x.response),g("Test received /api/devices"),L(x.response);for(const w of x.response)console.log("Test sending /api/clusters for device:",w.pluginName,w.name,w.endpoint),c({id:R.current,method:"/api/clusters",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{plugin:w.pluginName,endpoint:w.endpoint}})}Ve(x)&&x.method==="/api/clusters"&&x.response&&(console.log(`Test received ${x.response.clusters.length} clusters for device ${x.response.deviceName} endpoint ${x.response.endpoint}:`,x),g("Test received /api/clusters"),M(x.response))}};return a(j),console.log("Test useEffect WebSocketMessage mounted"),()=>{console.log("Test useEffect WebSocketMessage unmounting"),i(j),console.log("Test useEffect WebSocketMessage unmounted")}},[a,i,c,g]),o.useEffect(()=>(console.log("Test useEffect online mounting"),r&&(console.log("Test useEffect online received online"),c({id:R.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:R.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:R.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),console.log("Test useEffect online mounted"),()=>{console.log("Test useEffect online unmounted")}),[r,c,g]);const H=o.useCallback(j=>String(j.code),[]);return console.log("Test rendering..."),r?e.jsx("div",{className:"MbfPageDiv",style:{display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center",height:"100vh"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"20px",width:"100%"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"256px",width:"256px",margin:"10px"}}),e.jsx("p",{children:"Welcome to the Test page of the Matterbridge frontend"}),e.jsx("div",{style:{margin:"0",padding:"0",gap:"0",width:"1200px",maxWidth:"1200px",height:"600px",maxHeight:"600px",overflow:"hidden",backgroundColor:"var(--div-bg-color)",border:"1px solid #0004ffff"},children:e.jsx(Qn,{name:"Test",columns:Yn,rows:C,getRowKey:H,footerLeft:"Left Footer",footerRight:"Right Footer"})}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx(ne,{variant:"contained",color:"primary",onClick:()=>{console.log("Test button clicked"),g("Test button clicked"),b("Refresh required"),b("Restart required"),b("Test permanent message removal")},children:"Test"}),e.jsx(ne,{variant:"outlined",onClick:()=>{m(j=>{const x=j.findIndex(xe=>xe.code==="F123");if(x===-1)return j;const w=j[x],q={...w,population:(w.population||0)+1},de=j.slice();return de[x]=q,de})},children:"Update F123"})]})]})}):e.jsx(Qe,{})}const Kn=o.memo(Gn),Yn=[{id:"name",label:"Name",minWidth:50,maxWidth:100,required:!0},{id:"code",label:"ISO Code",minWidth:100,render:(r,c,a,i)=>e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",borderRadius:"8px",backgroundColor:"var(--chip-bg, #e6f4ff)",color:"var(--chip-fg, #0550ae)",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:"0.85em"},children:String(r)})},{id:"isIsland",label:"Island",minWidth:80,align:"center"},{id:"population",label:"Population",minWidth:170,align:"right",format:r=>r.toLocaleString("en-US")},{id:"size",label:"Size (km²)",minWidth:170,align:"right",format:r=>r.toLocaleString("en-US")},{id:"density",label:"Density",minWidth:170,align:"right",nosort:!0,format:r=>r.toFixed(2)},{id:"virtual",label:"Virtual",align:"right",required:!0,nosort:!0,render:(r,c,a,i)=>a.isIsland?"🏝️":"🏞️"}];function Se(r,c,a,i,l){const g=a/i;return{name:r,code:c,population:a,size:i,density:g,isIsland:l}}const cr=[Se("India","IN",1324171354,3287263,!1),Se("China","CN",1403500365,9596961,!1),Se("Italy","IT",60483973,301340,!1),Se("United States","US",327167434,9833520,!1),Se("Canada is a truly wonderful country","CA",37602103,9984670,!1),Se("Australia","AU",25475400,7692024,!0),Se("Germany","DE",83019200,357578,!1),Se("Ireland","IE",4857e3,70273,!0),Se("Mexico","MX",126577691,1972550,!1),Se("Japan","JP",126317e3,377973,!0),Se("France","FR",67022e3,640679,!1),Se("United Kingdom","GB",67545757,242495,!0),Se("Russia","RU",146793744,17098246,!1),Se("Nigeria","NG",200962417,923768,!1),Se("Brazil","BR",210147125,8515767,!1)],Kt=["Zor","Eld","Myth","Drak","Lum","Xen","Thal","Quor","Vex","Nyx"],Yt=["aria","dor","mere","land","wyn","gard","heim","quess","tor","vale"];for(let r=0;r<2e3;r++){const c=`${Kt[r%Kt.length]}${Yt[r%Yt.length]} ${r}`,a=`F${r.toString().padStart(3,"0")}`,i=Math.floor(Math.random()*1e9),l=Math.floor(Math.random()*1e7),g=Math.random()<.2;cr.push(Se(c,a,i,l,g))}function Xn(r,c){s&&console.log("getCssVariable:",r,"defaultValue",c);const a=getComputedStyle(document.body).getPropertyValue(r).trim();return a||console.error("getCssVariable: undefined",a),a||c}function Zn(r){return po({palette:{primary:{main:r},action:{disabled:"var(--main-label-color)"},text:{disabled:"var(--main-label-color)"}},typography:{fontFamily:"Roboto, Helvetica, Arial, sans-serif"},components:{MuiDialog:{styleOverrides:{paper:{color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)",border:"2px solid var(--div-border-color)",borderRadius:"var(--div-border-radius)",boxShadow:"2px 2px 5px var(--div-shadow-color)"}}},MuiTooltip:{defaultProps:{placement:"top-start",arrow:!0}},MuiButton:{styleOverrides:{root:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)","&:hover":{backgroundColor:"var(--main-button-bg-color)"},"&.Mui-disabled":{color:"var(--main-button-color)",backgroundColor:"var(--main-grey-color)"}},contained:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)"},outlined:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)"},text:{color:"var(--main-button-color)"}},defaultProps:{variant:"contained",size:"small"}},MuiIconButton:{styleOverrides:{root:{color:"var(--main-icon-color)","&:hover .MuiSvgIcon-root":{color:"var(--primary-color)"}}}},MuiCheckbox:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-checked":{color:"var(--primary-color)"}}}},MuiTextField:{defaultProps:{size:"small",variant:"outlined",fullWidth:!0}},MuiOutlinedInput:{styleOverrides:{root:{backgroundColor:"var(--div-bg-color)","& .MuiOutlinedInput-notchedOutline":{borderColor:"var(--main-label-color)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"var(--main-text-color)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"var(--primary-color)"},padding:"0px"},input:{color:"var(--div-text-color)",padding:"4px 8px"}}},MuiInputLabel:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-focused":{color:"var(--primary-color)"}}}},MuiFormLabel:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-focused":{color:"var(--main-label-color)"}}}},MuiFormControl:{styleOverrides:{root:{color:"var(--main-grey-color)"}}},MuiRadio:{styleOverrides:{root:{color:"var(--main-label-color)","&.Mui-checked":{color:"var(--primary-color)"}}}},MuiSelect:{styleOverrides:{root:{backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)",height:"30px","&:hover":{borderColor:"var(--main-text-color)"},"&.Mui-focused":{borderColor:"var(--primary-color)"}}}},MuiMenu:{styleOverrides:{paper:{backgroundColor:"var(--main-menu-bg-color)",padding:"0px",margin:"0px"},list:{padding:"0px"}}},MuiMenuItem:{styleOverrides:{root:{color:"var(--main-menu-color)",backgroundColor:"var(--main-menu-bg-color)","&:hover":{backgroundColor:"var(--main-menu-hover-color)"},"&.Mui-selected":{color:"var(--main-menu-color)",backgroundColor:"var(--main-menu-bg-color)"},"&.Mui-selected:hover":{backgroundColor:"var(--main-menu-hover-color)"}}}},MuiListItemButton:{styleOverrides:{root:{cursor:"pointer","&:hover":{backgroundColor:"var(--main-bg-color)"}}}},MuiListItemIcon:{styleOverrides:{root:{color:"var(--div-text-color)"}}},MuiListItemText:{styleOverrides:{primary:{fontSize:"16px",fontWeight:"bold",color:"var(--div-text-color)"},secondary:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"}}}}})}let s=!1;const ei=()=>{s=!s},pr=o.createContext(void 0);function ti({children:r}){const[c,a]=o.useState(!1),[i,l]=o.useState(""),g=async b=>{try{const t=await fetch("./api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:b})});if(t.ok){const{valid:d}=await t.json();d?a(!0):b!==""&&l("Incorrect password!")}else console.error("Failed to log in:",t.statusText)}catch(t){console.error("Failed to log in:",t)}};return e.jsx(pr.Provider,{value:{loggedIn:c,logIn:g,errorMessage:i},children:r})}function ri(){const[r,c]=o.useState(""),a=o.useContext(pr),[i,l]=o.useState("#1976d2");if(!a)throw new Error("AuthContext not found");const{loggedIn:g,logIn:b,errorMessage:t}=a,d=M=>{M.preventDefault(),b(r)},y={display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",backgroundColor:"var(--main-bg-color)"},W={display:"flex",flexDirection:"column",maxWidth:"400px",margin:"0 auto",padding:"20px",gap:"20px",border:"1px solid var(--div-border-color)",borderRadius:"var(--div-border-radius)",boxShadow:"2px 2px 5px var(--div-shadow-color)",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},h={margin:"10px 0",padding:"3px 3px",fontSize:"14px",width:"230px",border:"1px solid var(--main-label-color)",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"};o.useEffect(()=>{s&&console.log("Setting frontend theme");const M=localStorage.getItem("frontendTheme");s&&console.log("Saved theme:",M),M?document.body.setAttribute("frontend-theme",M):document.body.setAttribute("frontend-theme","dark");const O=Xn("--primary-color","#1976d2");s&&console.log("Primary color from CSS:",O),l(O)},[]);const L=window.location.pathname.includes("/matterbridge/")?"/matterbridge":window.location.href.includes("/api/hassio_ingress/")?window.location.pathname:"/";console.log(`Loading App.js with href="${window.location.href}" and pathname="${window.location.pathname}" >>> baseName="${L}"`);const V=Zn(i);return b(""),g?e.jsx(uo,{theme:V,children:e.jsx(Cr,{dense:!0,maxSnack:10,preventDuplicate:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(qo,{children:e.jsx(Bo,{children:e.jsx(xr,{basename:L,children:e.jsxs("div",{className:"MbfScreen",children:[e.jsx(Qo,{}),e.jsxs(br,{children:[e.jsx(Xe,{path:"/",element:e.jsx(bn,{})}),e.jsx(Xe,{path:"/devices",element:e.jsx(On,{})}),e.jsx(Xe,{path:"/log",element:e.jsx(En,{})}),e.jsx(Xe,{path:"/settings",element:e.jsx(An,{})}),e.jsx(Xe,{path:"/test",element:e.jsx(Kn,{})}),e.jsx(Xe,{path:"*",element:e.jsx(vr,{to:"/"})})]})]})})})})})}):e.jsx("div",{style:y,children:e.jsxs("form",{onSubmit:d,style:W,children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",gap:"20px"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"64px",width:"64px"}}),e.jsx("h3",{style:{color:"var(--div-text-color)"},children:"Welcome to Matterbridge"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:"20px"},children:[e.jsx("input",{type:"text",name:"username",autoComplete:"username",style:{display:"none"},tabIndex:-1}),e.jsx("input",{type:"password",value:r,onChange:M=>c(M.target.value),style:h,placeholder:"password",autoComplete:"current-password"}),e.jsx("button",{type:"submit",style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",borderColor:"var(--div-bg-color)"},children:"Log in"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",margin:0,height:"30px"},children:t&&e.jsx("p",{style:{color:"red"},children:t})})]})})}function oi(){return e.jsx(ti,{children:e.jsx(ri,{})})}yr.createRoot(document.getElementById("root")).render(e.jsx(Xt.StrictMode,{children:e.jsx(oi,{})}));
|