matterbridge 3.2.9-dev-20250922-517cae7 → 3.2.9-dev-20250924-9417698
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 +5 -3
- package/dist/frontend.js +14 -15
- package/dist/frontendTypes.js +5 -21
- package/dist/shelly.js +4 -4
- package/frontend/build/assets/index.js +1 -23
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,23 +1 @@
|
|
|
1
|
-
import{B as e,y as o,Q as tt,S as ar,U as sr,V as Ve,X as lr,Y as dr,H as cr}from"./vendor_node_modules.js";import{u as pr,S as ur}from"./vendor_notistack.js";import{D as Ne,a as Fe,b as Le,B as ie,c as Z,A as mr,I as Q,C as gr,T as R,S as hr,F as At,H as fr,d as Vt,e as Te,R as ut,P as Oe,M as xr,f as Qe,g as I,L as q,h as te,i as rt,V as ot,j as Ie,k as bt,l as br,m as vr,n as pe,o as yr,p as jr,q as mt,r as ne,s as He,K as It,t as Dt,u as ht,v as nt,w as Xe,x as it,W as Ze,y as at,z as st,E as _e,G as Pt,J as Nt,N as Cr,O as wr,Q as Sr,U as Re,X as Ut,Y as Ct,Z as Mr,_ as kr,$ as Ir,a0 as Dr,a1 as qt,a2 as gt,a3 as Pr,a4 as Nr,a5 as Fr,a6 as Lr,a7 as Ft,a8 as Wr,a9 as Tr,aa as $r,ab as Rr,ac as Hr,ad as Or,ae as Er,af as Lt,ag as _r,ah as Ar,ai as Vr,aj as Ur,ak as qr,al as zr,am as Br,an as Qr,ao as Kr,ap as Jr,aq as Gr,ar as Yr,as as Xr,at as Zr,au as eo,av as Wt,aw as Ke,ax as zt,ay as Me,az as Bt,aA as ft,aB as $e,aC as to,aD as ro}from"./vendor_mui.js";import{Q as oo}from"./vendor_qrcode.js";import{I as re,m as Tt,a as no,b as io,c as $t,d as ao,e as so,f as lo,g as co,h as po,i as uo,j as mo,k as go,l as ho,n as fo,o as xo,p as bo,q as Rt,r as vo,s as yo,t as jo,u as Co,v as wo,w as So,x as Mo,y as ko,z as Ht,A as Io,B as Do}from"./vendor_mdi.js";import{F as Po,v as No,e as Fo,a as Lo,g as Wo,b as To,c as $o,d as vt,A as Ro}from"./vendor_rjsf.js";import"./vendor_lodash.js";import"./vendor_emotion.js";(function(){const u=document.createElement("link").relList;if(u&&u.supports&&u.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const v of s)if(v.type==="childList")for(const M of v.addedNodes)M.tagName==="LINK"&&M.rel==="modulepreload"&&i(M)}).observe(document,{childList:!0,subtree:!0});function a(s){const v={};return s.integrity&&(v.integrity=s.integrity),s.referrerPolicy&&(v.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?v.credentials="include":s.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(s){if(s.ep)return;s.ep=!0;const v=a(s);fetch(s.href,v)}})();/**
|
|
2
|
-
* This file contains the types for WebSocket messages.
|
|
3
|
-
*
|
|
4
|
-
* @file frontendTypes.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2025-09-17
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
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 ae(r){return r.id>=0&&r.id<=101}function ge(r){return r.id>101&&r.src==="Matterbridge"&&r.dst==="Frontend"&&("success"in r||"error"in r)}function Ho({open:r,title:u,message:a,onConfirm:i,onCancel:s}){const v=t=>{n&&console.log("Confirmed"),t.preventDefault(),i()},M=t=>{n&&console.log("Canceled"),t.preventDefault(),s()};return e.jsxs(Ne,{open:r,children:[e.jsx(Fe,{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:u})]})}),e.jsxs(Le,{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(ie,{onClick:v,variant:"contained",color:"primary",size:"small",children:"Confirm"}),e.jsx(ie,{onClick:M,variant:"contained",color:"primary",size:"small",children:"Cancel"})]})]})]})}const lt=[],Je=o.createContext(null);function Oo({children:r}){const{enqueueSnackbar:u,closeSnackbar:a}=pr(),i=o.useCallback(f=>{n&&console.log(`UiProvider closeSnackbarMessage: message ${f}`);const y=lt.findIndex(H=>H.message===f);y!==-1&&(a(lt[y].key),lt.splice(y,1),n&&console.log(`UiProvider closeSnackbarMessage: message ${f} removed from persistMessages`))},[a]),s=o.useCallback((f,y,H)=>{n&&console.log(`UiProvider showSnackbarMessage: message ${f} timeout ${y}`);const x=u(f,{variant:"default",autoHideDuration:y==null||y>0?(y??5)*1e3:null,persist:y===0,content:w=>e.jsx(Z,{sx:{margin:"0",padding:"0",width:"300px",marginRight:"30px"},children:e.jsx(mr,{severity:H??"info",variant:"filled",sx:{color:"#fff",fontWeight:"normal",width:"100%",cursor:"pointer",padding:"0px 10px"},onClick:()=>a(w),action:e.jsx(Q,{size:"small",onClick:()=>a(w),sx:{color:"#fff"},children:e.jsx(gr,{fontSize:"small"})}),children:f},w)},w)});y===0&&(n&&console.log(`UiProvider showSnackbarMessage: message ${f} timeout ${y} - persist key ${x}`),lt.push({message:f,key:x}))},[u,a]),[v,M]=o.useState(!1),[t,d]=o.useState(""),[$,L]=o.useState(""),[C,A]=o.useState(""),T=o.useRef(null),W=o.useRef(null),_=()=>{n&&console.log(`UiProvider handle confirm action ${C}`),M(!1),T.current&&T.current(C)},m=()=>{n&&console.log(`UiProvider handle cancel action ${C}`),M(!1),W.current&&W.current(C)},E=o.useCallback((f,y,H,x,w)=>{n&&console.log(`UiProvider showConfirmCancelDialog for command ${H}`),d(f),L(y),A(H),T.current=x,W.current=w,M(!0)},[]),b=o.useMemo(()=>({showSnackbarMessage:s,closeSnackbarMessage:i,closeSnackbar:a,showConfirmCancelDialog:E}),[s,i,a,E]);return e.jsxs(Je.Provider,{value:b,children:[e.jsx(Ho,{open:v,title:t,message:$,onConfirm:_,onCancel:m}),r]})}const Qt=o.createContext(null),be=o.createContext(null);function Eo({children:r}){const[u,a]=o.useState(localStorage.getItem("logFilterLevel")??"info"),[i,s]=o.useState(localStorage.getItem("logFilterSearch")??"*"),[v,M]=o.useState([]),[t,d]=o.useState(1e3),[$,L]=o.useState(!0),[C,A]=o.useState(!1),{showSnackbarMessage:T,closeSnackbarMessage:W,closeSnackbar:_}=o.useContext(Je),m=o.useRef([]),E=o.useRef(null),b=o.useRef(1),f=o.useRef(Math.floor(Math.random()*999e3)+1e3),y=o.useRef(null),H=o.useRef(null),x=o.useRef(null),w=o.useRef(u),z=o.useRef(i),c=o.useMemo(()=>window.location.href.replace(/^http/,"ws"),[]),l=o.useMemo(()=>window.location.href.includes("api/hassio_ingress"),[]),g=100,h=60,F=50,G=300;o.useEffect(()=>{w.current=u},[u]),o.useEffect(()=>{z.current=i},[i]);const ye=o.useCallback(()=>Math.floor(Math.random()*999e3)+1e3,[]),xe=o.useCallback(S=>{if(E.current&&E.current.readyState===WebSocket.OPEN)try{S.id===void 0&&(S.id=f.current);const p=JSON.stringify(S);E.current.send(p),n&&console.log("WebSocket sent message:",S)}catch(p){n&&console.error(`WebSocket error sending message: ${p}`)}else n&&console.error("WebSocket message not sent, WebSocket not connected:",S)},[]),he=o.useCallback((S,p)=>{const ee=`<span style="background-color: #5c0e91; color: white; padding: 1px 5px; font-size: 12px; border-radius: 3px;">${S}</span>`;M(K=>[...K,ee+' <span style="color: var(--main-log-color);">'+p+"</span>"])},[]),X=o.useCallback((S,p)=>{a(S),s(p),he("WebSocket",`Filtering by log level "${S}" and log search "${p}"`)},[he]),se=o.useCallback(S=>{n&&console.log("WebSocket addListener:",S),m.current=[...m.current,S],n&&console.log("WebSocket addListener total listeners:",m.current.length)},[]),N=o.useCallback(S=>{n&&console.log("WebSocket removeListener:",S),m.current=m.current.filter(p=>p!==S),n&&console.log("WebSocket removeListener total listeners:",m.current.length)},[]),O=o.useCallback(()=>{c===""||c===null||c===void 0||(he("WebSocket",`Connecting to WebSocket: ${c}`),E.current=new WebSocket(c),E.current.onmessage=S=>{C||A(!0);try{const p=JSON.parse(S.data);if(p.id===void 0)return;if(p.error&&n&&console.error("WebSocket error message:",p),p.id===f.current&&p.src==="Matterbridge"&&p.dst==="Frontend"&&p.response==="pong"){n&&console.log("WebSocket pong response message:",p,"listeners:",m.current.length),H.current&&clearTimeout(H.current),m.current.forEach(K=>K(p));return}if(p.id===we.RefreshRequired){n&&console.log("WebSocket WS_ID_REFRESH_REQUIRED message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.RestartRequired){n&&console.log("WebSocket WS_ID_RESTART_REQUIRED message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.RestartNotRequired){n&&console.log("WebSocket WS_ID_RESTART_NOT_REQUIRED message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.CpuUpdate){n&&console.log("WebSocket WS_ID_CPU_UPDATE message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.MemoryUpdate){n&&console.log("WebSocket WS_ID_MEMORY_UPDATE message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.UptimeUpdate){n&&console.log("WebSocket WS_ID_UPTIME_UPDATE message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.Snackbar&&p.params&&p.params.message){n&&console.log("WebSocket WS_ID_SNACKBAR message:",p,"listeners:",m.current.length),T(p.params.message,p.params.timeout,p.params.severity);return}else if(p.id===we.CloseSnackbar&&p.params&&p.params.message){n&&console.log("WebSocket WS_ID_CLOSE_SNACKBAR message:",p,"listeners:",m.current.length),W(p.params.message);return}else if(p.id===we.ShellySysUpdate){n&&console.log("WebSocket WS_ID_SHELLY_SYS_UPDATE message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id===we.ShellyMainUpdate){n&&console.log("WebSocket WS_ID_SHELLY_MAIN_UPDATE message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}else if(p.id!==we.Log){n&&console.log("WebSocket message:",p,"listeners:",m.current.length),m.current.forEach(K=>K(p));return}if(!p.params||!p.params.level||!p.params.time||!p.params.name||!p.params.message||["debug","info","notice","warn","error","fatal"].includes(p.params.level)&&(w.current==="info"&&p.params.level==="debug"||w.current==="notice"&&(p.params.level==="debug"||p.params.level==="info")||w.current==="warn"&&(p.params.level==="debug"||p.params.level==="info"||p.params.level==="notice")||w.current==="error"&&(p.params.level==="debug"||p.params.level==="info"||p.params.level==="notice"||p.params.level==="warn")||w.current==="fatal"&&(p.params.level==="debug"||p.params.level==="info"||p.params.level==="notice"||p.params.level==="warn"||p.params.level==="error"))||z.current!=="*"&&z.current!==""&&!p.params.message.toLowerCase().includes(z.current.toLowerCase())&&!p.params.name.toLowerCase().includes(z.current.toLowerCase())||p.params.name==="Commissioning"&&p.params.message.includes("is uncommissioned"))return;M(K=>{const de=`<span style="color: #505050;">[${p.params?.time}]</span>`,le=je=>{switch(je?.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"}},V=je=>{switch(je?.toLowerCase()){case"warn":return"black";default:return"white"}},ue=`${`<span style="background-color: ${le(p.params?.level)}; color: ${V(p.params?.level)}; padding: 1px 5px; font-size: 12px; border-radius: 3px;">${p.params?.level}</span>`} ${de} <span style="color: #09516d;">[${p.params?.name}]</span> <span style="color: var(--main-log-color);">${p.params?.message}</span>`,Y=[...K,ue];return Y.length>t?Y.slice(t/10):Y})}catch(p){console.error(`WebSocketUse error parsing message: ${p}`)}},E.current.onopen=()=>{n&&console.log(`WebSocket: Connected to WebSocket: ${c}`),he("WebSocket",`Connected to WebSocket: ${c}`),A(!0),_(),b.current=1,x.current=setTimeout(()=>{y.current=setInterval(()=>{xe({id:f.current,method:"ping",src:"Frontend",dst:"Matterbridge",params:{}}),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{n&&console.error(`WebSocketUse: No pong response received from WebSocket: ${c}`),he("WebSocket",`No pong response received from WebSocket: ${c}`),A(!1)},1e3*F)},1e3*h)},1e3*G)},E.current.onclose=()=>{n&&console.error(`WebSocket: Disconnected from WebSocket ${l?"with Ingress":""}: ${c}`),he("WebSocket",`Disconnected from WebSocket: ${c}`),A(!1),_(),x.current&&clearTimeout(x.current),H.current&&clearTimeout(H.current),y.current&&clearInterval(y.current),he("WebSocket",`Reconnecting (attempt ${b.current} of ${g}) to WebSocket${l?" (Ingress)":""}: ${c}`),l?setTimeout(D,5e3):b.current===1?D():b.current<g?setTimeout(D,1e3*b.current):he("WebSocket",`Reconnect attempts exceeded limit of ${g} retries, refresh the page to reconnect to: ${c}`),b.current=b.current+1},E.current.onerror=S=>{n&&console.error(`WebSocket: WebSocket error connecting to ${c}:`,S),he("WebSocket",`WebSocket error connecting to ${c}`)})},[c]),D=o.useCallback(()=>{n&&console.log(`WebSocket attemptReconnect ${b.current}/${g} to:`,c),O()},[O]);o.useEffect(()=>(O(),()=>{E.current&&E.current.readyState===WebSocket.OPEN&&E.current.close()}),[O]);const P=o.useMemo(()=>({messages:v,maxMessages:t,autoScroll:$,setMessages:M,setLogFilters:X,setMaxMessages:d,setAutoScroll:L}),[v,M,X]),k=o.useMemo(()=>({maxMessages:t,autoScroll:$,logFilterLevel:u,logFilterSearch:i,setMessages:M,setLogFilters:X,setMaxMessages:d,setAutoScroll:L,online:C,retry:b.current,getUniqueId:ye,addListener:se,removeListener:N,sendMessage:xe,logMessage:he}),[t,$,M,X,d,L,C,b.current,se,N,xe,he]);return e.jsx(Qt.Provider,{value:P,children:e.jsx(be.Provider,{value:k,children:r})})}function _o(){const{showSnackbarMessage:r,showConfirmCancelDialog:u}=o.useContext(Je),{online:a,sendMessage:i,logMessage:s,addListener:v,removeListener:M,getUniqueId:t}=o.useContext(be),[d,$]=o.useState(!1),[L,C]=o.useState(!1),[A,T]=o.useState(!1),[W,_]=o.useState(!1),[m,E]=o.useState(null),b=o.useRef(t()),[f,y]=o.useState(null),[H,x]=o.useState(null),[w,z]=o.useState(null),[c,l]=o.useState(null),[g,h]=o.useState(null),F=()=>{window.open("https://www.buymeacoffee.com/luligugithub","_blank")},G=()=>{window.open("https://github.com/Luligu/matterbridge/blob/main/README.md","_blank")},ye=()=>{m?.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")},xe=()=>{window.open("https://discord.gg/QX58CDe6hd","_blank")},he=()=>{window.open("https://github.com/Luligu/matterbridge","_blank")},X=()=>{i({id:b.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge",restart:!0}})},se=()=>{i({id:b.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge@dev",restart:!0}})},N=()=>{i({id:b.current,sender:"Header",method:"/api/checkupdates",src:"Frontend",dst:"Matterbridge",params:{}})},O=()=>{n&&console.log("Header: handleShellySystemUpdateClick"),s("Matterbridge","Installing system updates..."),i({id:b.current,sender:"Header",method:"/api/shellysysupdate",src:"Frontend",dst:"Matterbridge",params:{}})},D=()=>{n&&console.log("Header: handleShellyMainUpdateClick"),s("Matterbridge","Installing software updates..."),i({id:b.current,sender:"Header",method:"/api/shellymainupdate",src:"Frontend",dst:"Matterbridge",params:{}})},P=()=>{n&&console.log("Header: handleShellyCreateSystemLog"),i({id:b.current,sender:"Header",method:"/api/shellycreatesystemlog",src:"Frontend",dst:"Matterbridge",params:{}})},k=()=>{n&&console.log("Header: handleShellyDownloadSystemLog"),s("Matterbridge","Downloading Shelly system log..."),r("Downloading Shelly system log...",5),window.location.href="./api/shellydownloadsystemlog"},S=()=>{m?.matterbridgeInformation.restartMode===""?i({id:b.current,sender:"Header",method:"/api/restart",src:"Frontend",dst:"Matterbridge",params:{}}):i({id:b.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},p=()=>{i({id:b.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},ee=()=>{i({id:b.current,sender:"Header",method:"/api/reboot",src:"Frontend",dst:"Matterbridge",params:{}})},K=()=>{i({id:b.current,sender:"Header",method:"/api/softreset",src:"Frontend",dst:"Matterbridge",params:{}})},de=()=>{i({id:b.current,sender:"Header",method:"/api/hardreset",src:"Frontend",dst:"Matterbridge",params:{}})},le=B=>{y(B.currentTarget)},V=B=>{n&&console.log("Header: handleMenuClose",B),y(null),B==="download-mblog"?(s("Matterbridge","Downloading matterbridge log..."),r("Downloading matterbridge log...",5),window.location.href="./api/download-mblog"):B==="download-mjlog"?(s("Matterbridge","Downloading matter log..."),r("Downloading matter log...",5),window.location.href="./api/download-mjlog"):B==="view-mblog"?(s("Matterbridge","Loading matterbridge log..."),r("Loading matterbridge log...",5),window.location.href="./api/view-mblog"):B==="view-mjlog"?(s("Matterbridge","Loading matter log..."),r("Loading matter log...",5),window.location.href="./api/view-mjlog"):B==="view-shellylog"?(s("Matterbridge","Loading shelly system log..."),r("Loading shelly system log...",5),window.location.href="./api/shellyviewsystemlog"):B==="download-mbstorage"?(s("Matterbridge","Downloading matterbridge storage..."),r("Downloading matterbridge storage...",5),window.location.href="./api/download-mbstorage"):B==="download-pluginstorage"?(s("Matterbridge","Downloading matterbridge plugins storage..."),r("Downloading matterbridge plugins storage...",5),window.location.href="./api/download-pluginstorage"):B==="download-pluginconfig"?(s("Matterbridge","Downloading matterbridge plugins config..."),r("Downloading matterbridge plugins config...",5),window.location.href="./api/download-pluginconfig"):B==="download-mjstorage"?(s("Matterbridge","Downloading matter storage..."),r("Downloading matter storage...",5),window.location.href="./api/download-mjstorage"):B==="download-backup"?(s("Matterbridge","Downloading backup..."),r("Downloading backup...",10),window.location.href="./api/download-backup"):B==="update"?X():B==="updatedev"?se():B==="updatecheck"?N():B==="shelly-sys-update"?O():B==="shelly-main-update"?D():B==="shelly-create-system-log"?P():B==="shelly-download-system-log"?k():B==="softreset"?K():B==="hardreset"?de():B==="restart"?S():B==="shutdown"?p():B==="reboot"?ee():B==="create-backup"?i({id:b.current,sender:"Header",method:"/api/create-backup",src:"Frontend",dst:"Matterbridge",params:{}}):B==="unregister"?i({id:b.current,sender:"Header",method:"/api/unregister",src:"Frontend",dst:"Matterbridge",params:{}}):B==="reset"?i({id:b.current,sender:"Header",method:"/api/reset",src:"Frontend",dst:"Matterbridge",params:{}}):B==="factoryreset"&&i({id:b.current,sender:"Header",method:"/api/factoryreset",src:"Frontend",dst:"Matterbridge",params:{}})},oe=B=>{n&&console.log("Header: handleMenuCloseCancel:",B),y(null)},ue=B=>{x(B.currentTarget)},Y=()=>{x(null)},je=B=>{z(B.currentTarget)},Se=()=>{z(null)},fe=B=>{l(B.currentTarget)},J=()=>{l(null)},ce=B=>{h(B.currentTarget)},Ce=()=>{h(null)},Ge=()=>{Bn(),n&&console.log("Matterbridge logo clicked: debug is now",n)};return o.useEffect(()=>{const B=j=>{j.src==="Matterbridge"&&j.dst==="Frontend"&&(ge(j)&&j.method==="/api/settings"&&j.id===b.current&&(n&&console.log("Header received settings:",j.response),E(j.response),$(j.response.matterbridgeInformation.restartRequired||j.response.matterbridgeInformation.fixedRestartRequired),C(j.response.matterbridgeInformation.fixedRestartRequired),T(j.response.matterbridgeInformation.updateRequired)),ae(j)&&j.method==="refresh_required"&&j.params.changed==="settings"&&(n&&console.log(`Header received refresh_required: changed=${j.params.changed} and sending /api/settings request`),i({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),ae(j)&&j.method==="restart_required"&&(n&&console.log(`Header received restart_required with fixed: ${j.params.fixed}`),$(!0),j.params.fixed===!0&&C(!0)),ae(j)&&j.method==="restart_not_required"&&(n&&console.log("Header received restart_not_required"),$(!1)),ae(j)&&j.method==="update_required"&&(n&&console.log("Header received update_required"),T(!0),i({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),ae(j)&&j.method==="update_required_dev"&&(n&&console.log("Header received update_required_dev"),_(!0),i({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),ae(j)&&j.id===we.ShellySysUpdate&&(n&&console.log("Header received WS_ID_SHELLY_SYS_UPDATE:"),E(me=>me?{matterbridgeInformation:{...me.matterbridgeInformation,shellySysUpdate:j.params.available},systemInformation:me.systemInformation}:null)),ae(j)&&j.id===we.ShellyMainUpdate&&(n&&console.log("Header received WS_ID_SHELLY_MAIN_UPDATE:"),E(me=>me?{matterbridgeInformation:{...me.matterbridgeInformation,shellyMainUpdate:j.params.available},systemInformation:me.systemInformation}:null)))};return v(B),n&&console.log(`Header added WebSocket listener id ${b.current}`),()=>{M(B),n&&console.log("Header removed WebSocket listener")}},[v,M,i,r]),o.useEffect(()=>{a&&(n&&console.log("Header sending /api/settings requests"),i({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[a,i]),n&&console.log("Header rendering..."),!a||!m?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(tt,{to:"/",className:"nav-link",children:"Home"}),e.jsx(tt,{to:"/devices",className:"nav-link",children:"Devices"}),e.jsx(tt,{to:"/log",className:"nav-link",children:"Logs"}),e.jsx(tt,{to:"/settings",className:"nav-link",children:"Settings"})]})]}),e.jsxs("div",{className:"sub-header",children:[!m.matterbridgeInformation.readOnly&&A&&e.jsx(R,{title:"New Matterbridge version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:X,children:["Update to v.",m.matterbridgeInformation.matterbridgeLatestVersion]})}),!m.matterbridgeInformation.readOnly&&W&&e.jsx(R,{title:"New Matterbridge dev version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:se,children:["Update to new dev v.",m.matterbridgeInformation.matterbridgeDevVersion.split("-dev-")[0]]})}),!m.matterbridgeInformation.readOnly&&e.jsx(R,{title:"Matterbridge version, click to see the changelog",children:e.jsxs("span",{className:"status-information",onClick:ye,children:["v.",m.matterbridgeInformation.matterbridgeVersion]})}),m.matterbridgeInformation.shellyBoard&&e.jsx("img",{src:"Shelly.svg",alt:"Shelly Icon",style:{height:"30px",padding:"0px",margin:"0px",marginRight:"30px"}}),m.matterbridgeInformation.bridgeMode!==""&&m.matterbridgeInformation.readOnly===!1?e.jsx(R,{title:"Bridge mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:m.matterbridgeInformation.bridgeMode})}):null,m.matterbridgeInformation.restartMode!==""&&m.matterbridgeInformation.readOnly===!1?e.jsx(R,{title:"Restart mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:m.matterbridgeInformation.restartMode})}):null,m.matterbridgeInformation.profile&&m.matterbridgeInformation.profile!==""&&m.matterbridgeInformation.readOnly===!1?e.jsx(R,{title:"Current profile",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:m.matterbridgeInformation.profile})}):null]}),e.jsxs("div",{className:"sub-header",style:{gap:"5px"},children:[m.matterbridgeInformation.readOnly===!1?e.jsx(R,{title:"Matterbridge discord group",children:e.jsx("img",{src:"discord.svg",alt:"Discord Logo",style:{cursor:"pointer",height:"25px"},onClick:xe})}):null,m.matterbridgeInformation.readOnly===!1?e.jsx(R,{title:"Give a star to Matterbridge",children:e.jsx(Q,{style:{color:"#FFD700",margin:"0",padding:"0"},onClick:he,children:e.jsx(hr,{})})}):null,m.matterbridgeInformation.readOnly===!1?e.jsx(R,{title:"Sponsor Matterbridge",children:e.jsx(Q,{style:{color:"#b6409c",margin:"0",padding:"0"},onClick:F,children:e.jsx(At,{})})}):null,e.jsx(R,{title:"Matterbridge help",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:G,children:e.jsx(fr,{})})}),e.jsx(R,{title:"Matterbridge changelog",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:ye,children:e.jsx(Vt,{})})}),m.matterbridgeInformation&&!m.matterbridgeInformation.readOnly&&e.jsx(R,{title:"Update matterbridge to latest version",children:e.jsx(Q,{style:{color:A?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:X,children:e.jsx(Te,{})})}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&m.matterbridgeInformation.shellySysUpdate&&e.jsx(R,{title:"Shelly system update",children:e.jsx(Q,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:O,children:e.jsx(Te,{})})}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&m.matterbridgeInformation.shellyMainUpdate&&e.jsx(R,{title:"Shelly software update",children:e.jsx(Q,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:D,children:e.jsx(Te,{})})}),e.jsx(R,{title:"Restart matterbridge",children:e.jsx(Q,{style:{color:d||L?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:S,children:e.jsx(ut,{})})}),m.matterbridgeInformation.restartMode===""?e.jsx(R,{title:"Shut down matterbridge",children:e.jsx(Q,{style:{color:d||L?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:p,children:e.jsx(Oe,{})})}):null,e.jsx(R,{title:"Download, backup and more",children:e.jsx(Q,{onClick:le,children:e.jsx(xr,{style:{color:"var(--main-icon-color)"}})})}),e.jsxs(Qe,{id:"command-menu",anchorEl:f,keepMounted:!0,open:!!f,onClose:()=>V(""),children:[m.matterbridgeInformation&&!m.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>V("update"),children:[e.jsx(q,{children:e.jsx(Te,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Install latest stable",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&!m.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>V("updatedev"),children:[e.jsx(q,{children:e.jsx(Te,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Install latest dev",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&!m.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>V("updatecheck"),children:[e.jsx(q,{children:e.jsx(Te,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Check for updates",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&m.matterbridgeInformation.shellySysUpdate&&e.jsxs(I,{onClick:()=>V("shelly-sys-update"),children:[e.jsx(q,{children:e.jsx(Te,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shelly system update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&m.matterbridgeInformation.shellyMainUpdate&&e.jsxs(I,{onClick:()=>V("shelly-main-update"),children:[e.jsx(q,{children:e.jsx(Te,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shelly software update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>V("restart"),children:[e.jsx(q,{children:e.jsx(ut,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Restart",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation.restartMode===""?e.jsxs(I,{onClick:()=>V("shutdown"),children:[e.jsx(q,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shutdown",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}):null,m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{u("Reboot","Are you sure you want to reboot the Shelly board?","reboot",V,oe)},children:[e.jsx(q,{children:e.jsx(ut,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reboot...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsx(rt,{}),e.jsxs(I,{onClick:je,children:[e.jsx(q,{children:e.jsx(ot,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"View",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(Qe,{id:"sub-menu-view",anchorEl:w,keepMounted:!0,open:!!w,onClose:Se,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{V("view-mblog"),Se()},children:[e.jsx(q,{children:e.jsx(ot,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("view-mjlog"),Se()},children:[e.jsx(q,{children:e.jsx(ot,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{V("view-shellylog"),Se()},children:[e.jsx(q,{children:e.jsx(ot,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(rt,{}),e.jsxs(I,{onClick:fe,children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Download",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(Qe,{id:"sub-menu-download",anchorEl:c,keepMounted:!0,open:!!c,onClose:J,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{V("download-mbstorage"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("download-pluginstorage"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge plugins storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("download-pluginconfig"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge plugins config",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("download-mblog"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("download-mjstorage"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("download-mjlog"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{V("shelly-create-system-log"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Create Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{V("shelly-download-system-log"),J()},children:[e.jsx(q,{children:e.jsx(Ie,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Download Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(rt,{}),e.jsxs(I,{onClick:ue,children:[e.jsx(q,{children:e.jsx(bt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(Qe,{id:"sub-menu-backup",anchorEl:H,keepMounted:!0,open:!!H,onClose:Y,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{V("create-backup"),Y()},children:[e.jsx(q,{children:e.jsx(bt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Create backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{V("download-backup"),Y()},children:[e.jsx(q,{children:e.jsx(bt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Download backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(rt,{}),e.jsxs(I,{onClick:ce,children:[e.jsx(q,{children:e.jsx(br,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(Qe,{id:"sub-menu-reset",anchorEl:g,keepMounted:!0,open:!!g,onClose:Ce,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{Ce(),u("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",V,oe)},children:[e.jsx(q,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset all devices...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{Ce(),u("Reset commissioning and shutdown","Are you sure you want to reset the commissioning? You will have to manually remove Matterbridge from the controller.","reset",V,oe)},children:[e.jsx(q,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset commissioning...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),!m.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>{Ce(),u("Factory reset and shutdown","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","factoryreset",V,oe)},children:[e.jsx(q,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{Ce(),u("Network reset","Are you sure you want to factory reset the network parameters?","softreset",V,oe)},children:[e.jsx(q,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset network...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),m.matterbridgeInformation&&m.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{Ce(),u("Factory reset","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","hardreset",V,oe)},children:[e.jsx(q,{children:e.jsx(Oe,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]})]})]})]})}const Ao=o.memo(_o),Vo=()=>"ontouchstart"in window||typeof window.DocumentTouch<"u"&&document instanceof window.DocumentTouch?(n&&console.log("WebSocketLogs detectTouchscreen = true"),!0):(n&&console.log("WebSocketLogs detectTouchscreen = false"),!1);function Uo(){const{messages:r,autoScroll:u}=o.useContext(Qt),[a,i]=o.useState(!1),s=o.useRef(null),v=o.useMemo(()=>Vo(),[]),M=d=>i(!0),t=d=>i(!1);return o.useEffect(()=>{n&&console.log(`WebSocketLogs autoScroll: ${u} isHovering: ${a}`),u&&!a&&!v&&s.current?.scrollIntoView({behavior:"smooth"})},[r,a,u,v]),e.jsx("div",{style:{margin:"0px",padding:"0px"},children:e.jsxs("ul",{style:{margin:"0px",padding:"0px"},onMouseEnter:M,onMouseLeave:t,children:[r.map((d,$)=>e.jsx("li",{style:{wordWrap:"break-word",maxHeight:"200px",overflow:"hidden"},dangerouslySetInnerHTML:{__html:d}},$)),e.jsx("div",{ref:s})]})})}const Kt=o.memo(Uo);function Ae(){const{retry:r}=o.useContext(be),u=()=>{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("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"256px",width:"256px",margin:"10px",marginBottom:"20px"}}),e.jsx(vr,{style:{color:"var(--primary-color)"}}),e.jsx("div",{style:{marginTop:"20px",color:"var(--primary-color)"},children:e.jsxs("span",{children:["Reconnecting to Matterbridge ","(attempt "+r+")","..."]})})]}):e.jsxs("div",{style:{marginTop:"20px",color:"var(--primary-color)",textAlign:"center"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"256px",width:"256px",margin:"10px",marginBottom:"20px"}}),e.jsx("span",{children:"Unable to connect to Matterbridge after multiple attempts."}),e.jsx("br",{}),e.jsx("span",{children:"Please check your network connection."}),e.jsx("br",{}),e.jsx(ie,{variant:"contained",color:"primary",onClick:u,style:{marginTop:"20px"},children:"Refresh the Page"})]})})})}function qo({value:r,maxChars:u}){let a=r;if(r.length>u&&u>3){const i=u-3,s=r.substring(0,Math.ceil(i/2)),v=r.substring(r.length-Math.floor(i/2),r.length);a=`${s} … ${v}`}return r!==a?e.jsx(R,{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 zo({systemInfo:r,compact:u}){const[a,i]=o.useState(r),{sendMessage:s,addListener:v,removeListener:M}=o.useContext(be);if(n&&console.log("SystemInfoTable:",a,"compact:",u),r&&u&&a.totalMemory&&a.freeMemory){const t=a.totalMemory,d=a.freeMemory;a.freeMemory=`${d} / ${t}`,a.totalMemory=""}if(r&&u&&a.heapTotal&&a.heapUsed){const t=a.heapTotal,d=a.heapUsed;a.heapUsed=`${d} / ${t}`,a.heapTotal=""}if(r&&u&&a.osRelease&&a.osType){const t=a.osType,d=a.osRelease;a.osType=`${t} (${d})`,a.osRelease=""}if(r&&u&&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"&&(ae(d)&&d.method==="memory_update"&&d.params&&d.params.totalMemory&&d.params.freeMemory&&d.params.heapTotal&&d.params.heapUsed&&d.params.rss&&(n&&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($=>({...$,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:""}))),ae(d)&&d.method==="cpu_update"&&d.params&&d.params.cpuUsage&&(n&&console.log("SystemInfoTable received cpu_update",d),a.cpuUsage!==(d.params?.cpuUsage?d.params.cpuUsage.toFixed(2)+" %":"")&&i($=>({...$,cpuUsage:d.params?.cpuUsage?d.params.cpuUsage.toFixed(2)+" %":""}))),ae(d)&&d.method==="uptime_update"&&d.params&&d.params.systemUptime&&d.params.processUptime&&(n&&console.log("SystemInfoTable received uptime_update",d),(a.systemUptime!==d.params?.systemUptime||a.processUptime!==d.params?.processUptime)&&i($=>({...$,systemUptime:d.params?.systemUptime?d.params.systemUptime:"",processUptime:d.params?.processUptime?d.params.processUptime:""}))))};return n&&console.log("SystemInfoTable useEffect WebSocketMessage mounting"),v(t),n&&console.log("SystemInfoTable useEffect WebSocketMessage mounted"),()=>{n&&console.log("SystemInfoTable useEffect WebSocketMessage unmounting"),M(t),n&&console.log("SystemInfoTable useEffect WebSocketMessage unmounted")}},[v,a.cpuUsage,a.freeMemory,a.heapTotal,a.heapUsed,a.processUptime,a.rss,a.systemUptime,a.totalMemory,M,s]),a?(n&&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],$)=>e.jsxs("tr",{className:$%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(qo,{value:typeof d!="string"?d.toString():d,maxChars:25})})]},t))})})})]})):null}const Bo=o.memo(zo),Ot={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"}},Qo=r=>{if(!r)return"";const u=r.toString().replace(/[^0-9]/g,"");if(u.length<5)return u;const a=u.slice(0,4),i=u.slice(4,7),s=u.slice(7,11);return[a,i,s].filter(Boolean).join("-")};function Ko({id:r}){const{online:u,sendMessage:a,addListener:i,removeListener:s,getUniqueId:v}=o.useContext(be),[M,t]=o.useState(null),[d,$]=o.useState(null),L=o.useRef(null),C=o.useRef(v()),{showConfirmCancelDialog:A}=o.useContext(Je);o.useEffect(()=>{n&&console.log(`QRDiv received storeId update "${r}"`),r&&(n&&console.log(`QRDiv sending data request for storeId "${r}"`),t(r),a({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:r,server:!0}}))},[r]),o.useEffect(()=>{const b=f=>{f.src==="Matterbridge"&&f.dst==="Frontend"&&ae(f)&&f.id===we.RefreshRequired&&f.params.changed==="matter"&&f.params.matter&&(n&&console.log(`QRDiv received refresh_required: changed=${f.params.changed} for storeId "${f.params.matter.id}":`,f.params.matter),M===f.params.matter.id&&(n&&console.log(`QRDiv received refresh_required/matter: setting matter data for storeId "${f.params.matter.id}":`,f.params.matter),L.current&&clearTimeout(L.current),f.params.matter.advertising&&f.params.matter.advertiseTime&&f.params.matter.advertiseTime+9e5<=Date.now()&&(f.params.matter.advertising=!1),$(f.params.matter),f.params.matter.advertising&&(n&&console.log(`QRDiv setting matter advertise timeout for storeId "${f.params.matter.id}":`,f.params.matter.advertiseTime+9e5-Date.now()),L.current=setTimeout(()=>{L.current&&clearTimeout(L.current),n&&console.log(`QRDiv clearing advertising state for storeId "${M}" after 15 minutes`),$(y=>y&&{...y,advertising:!1})},f.params.matter.advertiseTime+9e5-Date.now()))))};return i(b),n&&console.log("QRDiv webSocket effect mounted"),()=>{s(b),L.current&&clearTimeout(L.current),n&&console.log("QRDiv webSocket effect unmounted")}},[M]);const T=()=>{n&&console.log(`QRDiv sent matter startCommission for node "${d?.id}"`),d&&a({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,startCommission:!0}})},W=()=>{n&&console.log(`QRDiv sent matter stopCommission for node "${d?.id}"`),d&&a({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,stopCommission:!0}})},_=()=>{n&&console.log(`QRDiv sent matter advertise for node "${d?.id}"`),d&&a({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,advertise:!0}})},m=b=>{n&&console.log(`QRDiv sent matter removeFabric for node "${d?.id}" and fabricIndex ${b}`),d&&a({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:d.id,removeFabric:b}})},E=async()=>{if(!d||!d.manualPairingCode)return;const b=d.manualPairingCode.toString();try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(b);else{const f=document.createElement("textarea");f.value=b,f.style.position="fixed",f.style.opacity="0",document.body.appendChild(f),f.focus(),f.select(),document.execCommand("copy"),document.body.removeChild(f)}n&&console.log("Manual pairing code copied to clipboard")}catch(f){console.error("Failed to copy manual pairing code",f)}};return!d||!u?(n&&console.log("QRDiv rendering undefined state"),null):d.online?d.advertising&&d.qrPairingCode&&d.manualPairingCode?(n&&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(Q,{"aria-label":"send advertising",size:"small",onClick:_,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(R,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(re,{path:Tt,size:"22px"})})}),e.jsx(Q,{"aria-label":"stop pairing",size:"small",onClick:W,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(R,{title:"Turn off pairing",arrow:!0,children:e.jsx(re,{path:no,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:M}),e.jsx(oo,{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: ",Qo(d.manualPairingCode)]}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(R,{title:"Copy manual pairing code",arrow:!0,children:e.jsx(Q,{"aria-label":"copy manual pairing code",size:"small",onClick:E,sx:Ot,children:e.jsx(re,{path:io,size:.85})})})})]})]})):d.commissioned&&d.fabricInformations&&d.sessionInformations?(n&&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(Q,{"aria-label":"send advertising",size:"small",onClick:_,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(R,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(re,{path:Tt,size:"22px"})})}),e.jsx(Q,{"aria-label":"start pairing",size:"small",onClick:T,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(R,{title:"Turn on pairing",arrow:!0,children:e.jsx(re,{path:$t,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:M}),d.fabricInformations.map((b,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: ",b.fabricIndex]}),e.jsx(R,{title:"Remove the fabric. You will also need to remove it from the controller.",arrow:!0,children:e.jsx(Q,{"aria-label":"remove the fabric",size:"small",onClick:()=>A("Remove fabric","Are you sure you want to remove this fabric? You will also need to remove it from the controller.","RemoveFabric",()=>m(b.fabricIndex),()=>{}),sx:{...Ot,padding:"2px"},children:e.jsx(re,{path:ao,size:1})})})]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Vendor: ",b.rootVendorId," ",b.rootVendorName]}),b.label!==""&&e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Label: ",b.label]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Sessions: ",d.sessionInformations?d.sessionInformations.filter(y=>y.fabric?.fabricIndex===b.fabricIndex&&y.isPeerActive===!0).length:"0"," ","subscriptions: ",d.sessionInformations?d.sessionInformations.filter(y=>y.fabric?.fabricIndex===b.fabricIndex&&y.isPeerActive===!0&&y.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?(n&&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:M}),e.jsx(ie,{onClick:T,endIcon:e.jsx(re,{path:$t,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]})})]})):(n&&console.log("QRDiv rendering unknown state"),null):(n&&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:M}),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 Jo=o.memo(Ko);function Go(){const{logMessage:r,sendMessage:u,getUniqueId:a}=o.useContext(be),[i,s]=o.useState("matterbridge-"),[v,M]=o.useState(!1),[t,d]=o.useState(null),$=o.useRef(a()),L=f=>{f.preventDefault(),M(!0)},C=()=>{M(!1)},A=f=>{f.preventDefault(),M(!1);const y=f.dataTransfer.files[0];if(y){r("Plugins",`Installing package ${y.name}. Please wait...`);const H=new FormData;H.append("file",y),H.append("filename",y.name),fetch("./api/uploadpackage",{method:"POST",body:H}).then(x=>x.text()).then(x=>{r("Plugins",`Server response: ${x}`)}).catch(x=>{console.error("Error uploading plugin file:",x),r("Plugins",`Error installing package ${x}`)})}},T=f=>{const y=f.target.files&&f.target.files[0];if(y){r("Plugins",`Uploading package ${y.name}`);const H=new FormData;H.append("file",y),H.append("filename",y.name),fetch("./api/uploadpackage",{method:"POST",body:H}).then(x=>x.text()).then(x=>{r("Plugins",`Server response: ${x}`)}).catch(x=>{console.error("Error uploading plugin file:",x),r("Plugins",`Error uploading package ${x}`)})}},W=()=>{u({id:$.current,sender:"InstallPlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:i,restart:!1}})},_=()=>{document.getElementById("file-upload")?.click()},m=()=>{u({id:$.current,sender:"InstallPlugins",method:"/api/addplugin",src:"Frontend",dst:"Matterbridge",params:{pluginNameOrPath:i}})},E=f=>{d(f.currentTarget)},b=f=>{f!==""&&s(f),d(null)};return n&&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:L,onDragLeave:C,onDrop:A,children:[e.jsx(pe,{value:i,onChange:f=>{s(f.target.value)},size:"small",id:"plugin-name",label:"Plugin name or plugin path",variant:"outlined",fullWidth:!0}),e.jsx(Q,{onClick:E,children:e.jsx(yr,{})}),e.jsxs(Qe,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:!!t,onClose:()=>b(""),children:[e.jsx(I,{onClick:()=>b("matterbridge-zigbee2mqtt"),children:"matterbridge-zigbee2mqtt"}),e.jsx(I,{onClick:()=>b("matterbridge-somfy-tahoma"),children:"matterbridge-somfy-tahoma"}),e.jsx(I,{onClick:()=>b("matterbridge-shelly"),children:"matterbridge-shelly"}),e.jsx(I,{onClick:()=>b("matterbridge-hass"),children:"matterbridge-hass"}),e.jsx(I,{onClick:()=>b("matterbridge-webhooks"),children:"matterbridge-webhooks"}),e.jsx(I,{onClick:()=>b("matterbridge-bthome"),children:"matterbridge-bthome"}),e.jsx(I,{onClick:()=>b("matterbridge-test"),children:"matterbridge-test"}),e.jsx(I,{onClick:()=>b("matterbridge-example-accessory-platform"),children:"matterbridge-example-accessory-platform"}),e.jsx(I,{onClick:()=>b("matterbridge-example-dynamic-platform"),children:"matterbridge-example-dynamic-platform"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-door"),children:"matterbridge-eve-door"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-motion"),children:"matterbridge-eve-motion"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-energy"),children:"matterbridge-eve-energy"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-weather"),children:"matterbridge-eve-weather"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-room"),children:"matterbridge-eve-room"})]}),e.jsx(R,{title:"Install or update a plugin from npm",children:e.jsx(ie,{onClick:W,endIcon:e.jsx(Ie,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Install"})}),e.jsx(R,{title:"Upload and install a plugin from a tarball",children:e.jsx(ie,{onClick:_,endIcon:e.jsx(jr,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Upload"})}),e.jsx(R,{title:"Add an installed plugin",children:e.jsx(ie,{onClick:m,endIcon:e.jsx(mt,{}),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:T})]})}const Yo=o.memo(Go);function Ue({status:r,enabledText:u="Enabled",disabledText:a=void 0,tooltipText:i=void 0,onClick:s}){if(r===void 0)return null;{const v=e.jsx("div",{className:r?"status-enabled":"status-disabled",style:{cursor:"default"},onClick:s,children:r?u:a??u});return i!==void 0?e.jsx(R,{title:i,children:v}):v}}const qe={fontSize:"16px",fontWeight:"bold",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},ze={fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},Xo={fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)",backgroundColor:"var(--div-bg-color)"},Zo={fontSize:"16px",fontWeight:"bold",backgroundColor:"var(--div-bg-color)"},Pe={padding:"0px",margin:"0px"},en="5px 10px 5px 10px",dt={},ve={},ct={},pt={};let Be=[],yt=[];const tn=({open:r,onClose:u,plugin:a})=>{const{sendMessage:i,addListener:s,removeListener:v,getUniqueId:M}=o.useContext(be),t=o.useRef(M()),[d,$]=o.useState(a.configJson),[L,C]=o.useState(null),[A,T]=o.useState({"ui:submitButtonOptions":{submitText:"Confirm"},"ui:globalOptions":{orderable:!0}}),[W,_]=o.useState("");let m={};o.useEffect(()=>{const P=k=>{k.src==="Matterbridge"&&k.dst==="Frontend"&&(ge(k)&&k.id===t.current&&k.method==="/api/select/devices"&&k.response&&(n&&console.log(`ConfigPluginDialog (id: ${k.id}) received ${k.response.length} /api/select/devices:`,k.response),Be=k.response),ge(k)&&k.id===t.current&&k.method==="/api/select/entities"&&k.response&&(n&&console.log(`ConfigPluginDialog (id: ${k.id}) received ${k.response.length} /api/select/entities:`,k.response),yt=k.response))};return s(P),n&&console.log("ConfigPluginDialog added WebSocket listener id:",t.current),d&&L&&L.properties&&(Object.keys(L.properties).forEach(k=>{Object.keys(L.properties[k]).forEach(S=>{S.startsWith("ui:")&&(A[k]={},A[k][S]=L.properties[k][S],delete L.properties[k][S])})}),T(A)),a.name&&a.configJson&&a.schemaJson&&($(a.configJson),C(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}}),n&&console.log('HomePlugins sent "/api/select/devices" and "/api/select/entities" for plugin:',a.name)),()=>{v(P),n&&console.log("ConfigPluginDialog removed WebSocket listener")}},[s,d,a,v,L,i,A]);const E=(P,k)=>{m=P.formData},b=P=>{n&&console.log("ConfigPluginDialog handleSaveChanges:",P.formData),$(P.formData),a.configJson=P.formData,a.restartRequired=!0,i({id:t.current,sender:"ConfigPlugin",method:"/api/savepluginconfig",src:"Frontend",dst:"Matterbridge",params:{pluginName:P.formData.name,formData:P.formData}}),u()};function f(P){const{id:k,label:S,onKeyChange:p,onDropPropertyClick:ee,disabled:K,schema:de,children:le,registry:V,readonly:oe,required:ue}=P,{templates:Y}=V,{RemoveButton:je}=Y.ButtonTemplates;if(!(Ro in de))return e.jsx(Z,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:le});const fe=({target:J})=>p(J&&J.value);return e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",flexGrow:1,padding:0,margin:0,border:"none"},children:[e.jsx(pe,{id:`${k}-key`,name:`${k}-key`,required:ue,disabled:K||oe,defaultValue:S,onBlur:oe?void 0:fe,type:"text",variant:"outlined",sx:{width:"250px",minWidth:"250px",maxWidth:"250px",marginRight:"20px"}}),e.jsx(Z,{sx:{flex:1},children:le}),e.jsx(je,{disabled:K||oe,onClick:ee(S),registry:V})]})}function y(P){const{children:k,description:S,displayLabel:p,errors:ee,help:K,hidden:de,registry:le,uiSchema:V}=P,oe=To(V),ue=$o("WrapIfAdditionalTemplate",le,oe);return de?e.jsx("div",{style:{display:"none"},children:k}):e.jsx(Z,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:e.jsxs(ue,{...P,children:[p===!0&&S,k,ee,K]})})}function H(P){const{description:k}=P;return k?e.jsx(ne,{sx:ze,children:k}):null}function x(P){const{required:k,title:S}=P;return S?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsxs(ne,{sx:qe,children:["Title ",S," ",k&&e.jsx("mark",{children:"***"})]})}):null}function w(P){const{help:k}=P;return k?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsx(ne,{sx:Xo,children:k})}):null}function z(P){const{errors:k}=P;return k?e.jsxs(Z,{sx:{padding:"10px",margin:"10px",border:"1px solid grey"},children:[e.jsx(ne,{color:"error",sx:Zo,children:"Please fix the following errors:"}),e.jsx(Xe,{children:k.map((S,p)=>e.jsxs(Cr,{children:[e.jsx(q,{children:e.jsx(wr,{color:"error"})}),e.jsx(te,{primary:S.stack})]},p))})]}):null}function c(P){const{errors:k}=P;return k?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:k.map((S,p)=>e.jsxs(ne,{color:"error",variant:"body2",sx:{marginLeft:1},children:["This field ",S]},p))}):null}function l(P){const{id:k,name:S,_schema:p,_uiSchema:ee,value:K,options:de,label:le,type:V,placeholder:oe,required:ue,disabled:Y,readonly:je,autofocus:Se,onChange:fe,onChangeOverride:J,onBlur:ce,onFocus:Ce,_rawErrors:Ge,_hideError:B,_registry:j,_formContext:me}=P,Ye=({target:{value:ke}})=>fe(ke===""?de.emptyValue:ke),We=({target:ke})=>ce(k,ke&&ke.value),et=({target:ke})=>Ce(k,ke&&ke.value);return e.jsx(Z,{sx:{padding:"0px",margin:"0px"},children:e.jsx(pe,{id:k,name:k,label:oe&&oe!==""?le:void 0,variant:"outlined",placeholder:oe&&oe!==""?oe:le,required:ue,disabled:Y||je,autoFocus:Se,value:K||K===0?K:"",type:V,autoComplete:V==="password"?"current-password":S,onChange:J||Ye,onBlur:We,onFocus:et,fullWidth:!0})})}function g(P){return console.log("ArrayFieldTitleTemplate:",P),null}function h(P){return console.log("ArrayFieldDescriptionTemplate:",P),null}function F(P){return console.log("ArrayFieldItemTemplate:",P),null}function G(P){const{canAdd:k,onAddClick:S,schema:p,title:ee}=P,[K,de]=o.useState(!1),[le,V]=o.useState(!1),[oe,ue]=o.useState(!1),[Y,je]=o.useState(""),Se=j=>{je(j.target.value)},fe=()=>{n&&console.log("ArrayFieldTemplate: handleDialogDeviceToggle filter:",Y,"selectDevices:",Be),de(!K)},J=()=>{n&&console.log("ArrayFieldTemplate: handleDialogEntityToggle filter:",Y,"selectEntities:",yt),V(!le)},ce=()=>{n&&console.log("ArrayFieldTemplate: handleDialogDeviceEntityToggle filter:",Y,"selectDevices:",Be),ue(!oe)},Ce=j=>{de(!1),p.selectFrom==="serial"?p.items.default=j.serial:p.selectFrom==="name"&&(p.items.default=j.name),S()},Ge=j=>{V(!1),p.selectEntityFrom==="name"?p.items.default=j.name:p.selectEntityFrom==="description"&&(p.items.default=j.description),S()},B=j=>{ue(!1),p.selectDeviceEntityFrom==="name"?p.items.default=j.name:p.selectDeviceEntityFrom==="description"&&(p.items.default=j.description),S()};return e.jsxs(Z,{sx:{margin:"0px",padding:"5px 10px 5px 10px",border:"1px solid grey"},children:[ee&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[ee&&e.jsx(ne,{sx:qe,children:ee}),k&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[p.selectFrom&&e.jsx(R,{title:"Add a device from the list",children:e.jsx(Q,{onClick:fe,size:"small",color:"primary",sx:Pe,children:e.jsx(nt,{})})}),p.selectEntityFrom&&e.jsx(R,{title:"Add an entity from the list",children:e.jsx(Q,{onClick:J,size:"small",color:"primary",sx:Pe,children:e.jsx(nt,{})})}),p.selectDeviceEntityFrom&&e.jsx(R,{title:"Add a device entity from the list",children:e.jsx(Q,{onClick:ce,size:"small",color:"primary",sx:Pe,children:e.jsx(nt,{})})}),e.jsx(R,{title:"Add a new item",children:e.jsx(Q,{onClick:S,size:"small",color:"primary",sx:Pe,children:e.jsx(mt,{})})})]})]}),p.description&&e.jsx(ne,{sx:ze,children:p.description}),P.items.map(j=>e.jsxs(Z,{sx:{margin:"2px 0px",padding:"0px",display:"flex",alignItems:"center"},children:[e.jsx(Z,{sx:{flexGrow:1,marginRight:"10px"},children:j.children}),e.jsx(Q,{disabled:!j.hasMoveUp,onClick:j.onReorderClick(j.index,j.index-1),size:"small",color:"primary",sx:Pe,children:e.jsx(Dt,{})}),e.jsx(Q,{disabled:!j.hasMoveDown,onClick:j.onReorderClick(j.index,j.index+1),size:"small",color:"primary",sx:Pe,children:e.jsx(It,{})}),e.jsx(Q,{onClick:j.onDropIndexClick(j.index),size:"small",color:"primary",sx:Pe,children:e.jsx(ht,{})})]},j.index)),e.jsxs(Ne,{open:K,onClose:fe,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Fe,{children:"Select a device"}),e.jsxs(Le,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ne,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:Y,onChange:Se,placeholder:"Enter serial or name"})]}),e.jsx(Xe,{dense:!0,children:Be.filter(j=>j.serial.toLowerCase().includes(Y.toLowerCase())||j.name.toLowerCase().includes(Y.toLowerCase())).map((j,me)=>e.jsxs(it,{onClick:()=>Ce(j),sx:dt,children:[j.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ze,{style:ve})}),j.icon==="ble"&&e.jsx(q,{children:e.jsx(at,{style:ve})}),j.icon==="hub"&&e.jsx(q,{children:e.jsx(st,{style:ve})}),e.jsx(te,{primary:j.name,secondary:j.serial,primaryTypographyProps:{style:ct},secondaryTypographyProps:{style:pt}})]},me))})]}),e.jsx(_e,{children:e.jsx(ie,{onClick:fe,children:"Close"})})]}),e.jsxs(Ne,{open:le,onClose:J,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Fe,{children:"Select an entity"}),e.jsxs(Le,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ne,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:Y,onChange:Se,placeholder:"Enter name or description"})]}),e.jsx(Xe,{dense:!0,children:yt.filter(j=>j.name.toLowerCase().includes(Y.toLowerCase())||j.description.toLowerCase().includes(Y.toLowerCase())).map((j,me)=>e.jsxs(it,{onClick:()=>Ge(j),sx:dt,children:[j.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ze,{style:ve})}),j.icon==="ble"&&e.jsx(q,{children:e.jsx(at,{style:ve})}),j.icon==="hub"&&e.jsx(q,{children:e.jsx(st,{style:ve})}),j.icon==="component"&&e.jsx(q,{children:e.jsx(Pt,{style:ve})}),j.icon==="matter"&&e.jsx(q,{children:e.jsx(Nt,{style:ve})}),e.jsx(te,{primary:j.name,secondary:j.description,primaryTypographyProps:{style:ct},secondaryTypographyProps:{style:pt}})]},me))})]}),e.jsx(_e,{children:e.jsx(ie,{onClick:J,children:"Close"})})]}),e.jsxs(Ne,{open:oe,onClose:ce,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsxs(Fe,{children:["Select an entity for ",ee]}),e.jsx(Le,{children:e.jsx(Xe,{dense:!0,children:Be.filter(j=>j.serial===ee||j.name===ee).map(j=>j.entities?.map((me,Ye)=>e.jsxs(it,{onClick:()=>B(me),sx:dt,children:[me.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ze,{style:ve})}),me.icon==="ble"&&e.jsx(q,{children:e.jsx(at,{style:ve})}),me.icon==="hub"&&e.jsx(q,{children:e.jsx(st,{style:ve})}),me.icon==="component"&&e.jsx(q,{children:e.jsx(Pt,{style:ve})}),me.icon==="matter"&&e.jsx(q,{children:e.jsx(Nt,{style:ve})}),e.jsx(te,{primary:me.name,secondary:me.description,primaryTypographyProps:{style:ct},secondaryTypographyProps:{style:pt}})]},Ye)))})}),e.jsx(_e,{children:e.jsx(ie,{onClick:ce,children:"Close"})})]})]})}function ye(P){const{onAddClick:k,schema:S,properties:p,title:ee,description:K}=P,[de,le]=o.useState(!1),[V,oe]=o.useState(""),ue=J=>{oe(J.target.value)},Y=()=>{le(!de)},je=J=>{n&&console.log(`ObjectFieldTemplate: handleSelectValue value "${J.serial}" for schema "${S.selectFrom}"`),le(!1);let ce="";S.selectFrom==="serial"?ce=J.serial:S.selectFrom==="name"&&(ce=J.name),_(ce),n&&console.log(`ObjectFieldTemplate: handleSelectValue newkey "${ce}"`),k(S)()},Se=()=>{k(S)()},fe=!S.additionalProperties;return n&&console.log(`ObjectFieldTemplate: isRoot ${fe} newkey "${W}"`),!fe&&W!==""&&(n&&console.log("ObjectFieldTemplate: newkey",W,"properties",p),p.forEach(J=>{if(J.name==="newKey"&&J.content.key==="newKey"&&J.content.props.name==="newKey"&&J.content.props.onKeyChange&&W!==""){n&&console.log("ObjectFieldTemplate: newkey onKeyChange",W);const ce=W;_(""),J.content.props.onKeyChange(ce)}})),e.jsxs(Z,{sx:{margin:"0px",padding:fe?"10px":"5px 10px 0px 10px",border:fe?"none":"1px solid grey"},children:[S.title&&fe&&e.jsx(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(ne,{sx:qe,children:S.title})}),ee&&!fe&&e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[e.jsx(ne,{sx:qe,children:ee}),e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[S.selectFrom&&e.jsx(R,{title:"Add a device from the list",children:e.jsx(Q,{onClick:Y,size:"small",color:"primary",sx:Pe,children:e.jsx(nt,{})})}),e.jsx(R,{title:"Add a new item",children:e.jsx(Q,{onClick:Se,size:"small",color:"primary",sx:Pe,children:e.jsx(mt,{})})})]})]}),S.description&&e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(ne,{sx:ze,children:S.description})}),p.map(({content:J,name:ce,hidden:Ce})=>!Ce&&e.jsxs(Z,{sx:{margin:"0px",marginBottom:"10px",padding:["object","array","boolean"].includes(S.properties[ce].type)?"0px":en,border:["object","array","boolean"].includes(S.properties[ce].type)?"none":"1px solid grey"},children:[!["object","array","boolean"].includes(S.properties[ce].type)&&e.jsx(ne,{sx:qe,children:ce}),e.jsx(Z,{sx:{flexGrow:1,padding:"0px",margin:"0px"},children:J})]},ce)),e.jsxs(Ne,{open:de,onClose:Y,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Fe,{children:"Select a device"}),e.jsxs(Le,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ne,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:V,onChange:ue,placeholder:"Enter serial or name"})]}),e.jsx(Xe,{dense:!0,children:Be.filter(J=>J.serial.toLowerCase().includes(V.toLowerCase())||J.name.toLowerCase().includes(V.toLowerCase())).map((J,ce)=>e.jsxs(it,{onClick:()=>je(J),sx:dt,children:[J.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ze,{style:ve})}),J.icon==="ble"&&e.jsx(q,{children:e.jsx(at,{style:ve})}),J.icon==="hub"&&e.jsx(q,{children:e.jsx(st,{style:ve})}),e.jsx(te,{primary:J.name,secondary:J.serial,primaryTypographyProps:{style:ct},secondaryTypographyProps:{style:pt}})]},ce))})]}),e.jsx(_e,{children:e.jsx(ie,{onClick:Y,children:"Close"})})]})]})}function xe(P){const{uiSchema:k}=P,{submitText:S,norender:p}=Wo(k);return p?null:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",margin:"10px",padding:"0px",gap:"20px"},children:[e.jsx(ie,{type:"submit",variant:"contained",color:"primary",children:S}),e.jsx(ie,{variant:"contained",color:"primary",onClick:u,children:"Cancel"})]})}function he(P){const{className:k,disabled:S,onClick:p,registry:ee,style:K,uiSchema:de,...le}=P;return e.jsx(R,{title:"Remove the item",children:e.jsx(Q,{disabled:S,size:"small",color:"primary",onClick:p,children:e.jsx(ht,{})})})}function X(P){const{className:k,disabled:S,onClick:p,registry:ee,uiSchema:K,...de}=P;return e.jsx(R,{title:"Add an item",children:e.jsx(Q,{size:"small",color:"primary",onClick:p,children:e.jsx(mt,{})})})}function se(P){const{disabled:k,onClick:S,registry:p,style:ee,uiSchema:K,...de}=P;return e.jsx(R,{title:"Move up the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:S,children:e.jsx(Dt,{})})})}function N(P){const{disabled:k,onClick:S,registry:p,style:ee,uiSchema:K,...de}=P;return e.jsx(R,{title:"Move down the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:S,children:e.jsx(It,{})})})}function O(P){const{id:k,name:S,value:p,schema:ee,readonly:K,onChange:de}=P,[le,V]=o.useState(),oe=Y=>{n&&console.log(`CheckboxWidget ${S} onChangeField:`,Y),V(Y&&Y!==""?Y:void 0)},ue=()=>{n&&console.log(`CheckboxWidget onClick plugin="${a.name}" action="${S}" value="${le}"`),i({id:t.current,sender:"ConfigPlugin",method:"/api/action",src:"Frontend",dst:"Matterbridge",params:{plugin:a.name,action:S,value:le,formData:m,id:k}}),ee.buttonClose===!0?u():ee.buttonSave===!0&&b({formData:d})};return ee.buttonText&&ee.description?e.jsxs(Z,{sx:{margin:"0px",padding:"10px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(ne,{sx:ze,children:ee.description}),e.jsx(ie,{variant:"contained",color:"primary",onClick:()=>ue(),children:ee.buttonText})]}):ee.buttonField&&ee.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(ne,{sx:ze,children:ee.description}),e.jsx(pe,{id:S+"-input",name:S,label:ee.textLabel,placeholder:ee.textPlaceholder,onChange:Y=>oe(Y.target.value),sx:{width:"250px",minWidth:"250px",maxWidth:"250px"}}),e.jsx(ie,{id:S+"-button",variant:"contained",color:"primary",disabled:le===void 0,onClick:()=>ue(),children:ee.buttonField})]}):e.jsxs(Z,{sx:{margin:"0px",padding:"5px 10px",border:"1px solid grey"},children:[S&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",gap:"10px",display:"flex",justifyContent:"flex-start",alignItems:"center"},children:[e.jsx(ne,{sx:qe,children:S}),e.jsx(He,{checked:p,readOnly:K,onChange:()=>de(!p),sx:{padding:"0px",margin:"0px"}})]}),ee.description&&e.jsx(ne,{sx:ze,children:ee.description})]})}function D({schema:P,id:k,name:S,options:p,label:ee,hideLabel:K,required:de,disabled:le,placeholder:V,readonly:oe,value:ue,multiple:Y,autofocus:je,onChange:Se,onBlur:fe,onFocus:J,errorSchema:ce,rawErrors:Ce=[],registry:Ge,uiSchema:B,hideError:j,formContext:me,...Ye}){const{enumOptions:We,enumDisabled:et,emptyValue:ke}=p;Y=typeof Y>"u"?!1:!!Y;const wt=Y?[]:"",St=typeof ue>"u"||Y&&ue.length<1||!Y&&ue===wt,Gt=({target:{value:De}})=>Se(vt(De,We,ke)),Yt=({target:De})=>fe(k,vt(De&&De.value,We,ke)),Xt=({target:De})=>J(k,vt(De&&De.value,We,ke)),Mt=Fo(ue,We,Y),{InputLabelProps:Zt,SelectProps:er,autocomplete:tr,...rr}=Ye,or=!Y&&P.default===void 0;return e.jsxs(pe,{id:k,name:k,value:!St&&typeof Mt<"u"?Mt:wt,required:de,disabled:le||oe,autoFocus:je,autoComplete:tr,placeholder:V,error:Ce.length>0,onChange:Gt,onBlur:Yt,onFocus:Xt,...rr,select:!0,InputLabelProps:{...Zt,shrink:!St},SelectProps:{...er,multiple:Y},"aria-describedby":Lo(k),children:[or&&e.jsx(I,{value:"",children:V}),Array.isArray(We)&&We.map(({value:De,label:nr},kt)=>{const ir=Array.isArray(et)&&et.indexOf(De)!==-1;return e.jsx(I,{value:String(kt),disabled:ir,children:nr},kt)})]})}return n&&console.log("ConfigPluginDialog rendering..."),!r||!L||!d?null:e.jsxs(Ne,{open:r,onClose:u,slotProps:{paper:{sx:{maxWidth:"800px"}}},children:[e.jsx(Fe,{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(Le,{style:{padding:"0px",margin:"0px",width:"800px",height:"600px",overflow:"auto"},children:e.jsx(Po,{schema:L,formData:d,uiSchema:A,validator:No,templates:{FieldTemplate:y,BaseInputTemplate:l,TitleFieldTemplate:x,DescriptionFieldTemplate:H,FieldHelpTemplate:w,FieldErrorTemplate:c,ErrorListTemplate:z,WrapIfAdditionalTemplate:f,ArrayFieldTitleTemplate:g,ArrayFieldDescriptionTemplate:h,ArrayFieldItemTemplate:F,ArrayFieldTemplate:G,ObjectFieldTemplate:ye,ButtonTemplates:{SubmitButton:xe,RemoveButton:he,AddButton:X,MoveUpButton:se,MoveDownButton:N}},widgets:{CheckboxWidget:O,SelectWidget:D},onChange:E,onSubmit:b})})]})};function Jt(r){if(n&&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 u=0,a=0;for(const i of r.sessionInformations??[])i.fabric&&i.isPeerActive===!0&&u++,i.numberOfActiveSubscriptions>0&&(a+=i.numberOfActiveSubscriptions);return r.commissioned===!0&&r.fabricInformations&&r.sessionInformations&&(u===0||a===0)?"var(--secondary-color)":"var(--div-text-color)"}function rn(r,u,a){const i=r?.[a],s=u?.[a];return i==null&&s==null?0:i==null?-1:s==null?1:typeof i=="boolean"&&typeof s=="boolean"?i===s?0:i?1:-1:typeof i=="number"&&typeof s=="number"?i-s:String(i).localeCompare(String(s))}function on({name:r,title:u,columns:a,rows:i,getRowKey:s,footerLeft:v,footerRight:M,onRowClick:t}){const d=o.useRef(new WeakMap),$=o.useRef(1),L=c=>{if(typeof s=="string"&&c&&c[s]!=null)return c[s];if(typeof s=="function"){const h=s(c);if(h!=null)return h}const l=a?.[0]?.id;if(l&&c&&c[l]!=null)return c[l];console.warn(`MbfTable(${r}): using fallback stable row key; consider providing getRowKey prop for better React performance`);let g=d.current.get(c);return g||(g=`rk_${$.current++}`,d.current.set(c,g)),g},[C,A]=o.useState(localStorage.getItem(`${r}_table_order_by`)||null),[T,W]=o.useState(localStorage.getItem(`${r}_table_order`)||null),[_,m]=o.useState(!1),[E,b]=o.useState(()=>{try{const c=localStorage.getItem(`${r}_column_visibility`);if(c)return JSON.parse(c)}catch{}return{}}),f=o.useMemo(()=>{const c={};for(const l of a)l.hidden||(c[l.id]=l.required?!0:E[l.id]!==!1);return c},[a,E]),y=o.useMemo(()=>{if(!C||!T)return i;const c=a.find(g=>g.id===C);if(!c||c.noSort)return i;const l=i.map((g,h)=>({el:g,index:h}));return l.sort((g,h)=>{let F;return typeof c.comparator=="function"?F=c.comparator(g.el,h.el):F=rn(g.el,h.el,C),F!==0?T==="asc"?F:-F:g.index-h.index}),l.map(g=>g.el)},[i,C,T,a]),H=c=>{if(C!==c||!C){A(c),W("asc"),localStorage.setItem(`${r}_table_order_by`,c),localStorage.setItem(`${r}_table_order`,"asc");return}if(T==="asc"){W("desc"),localStorage.setItem(`${r}_table_order`,"desc");return}A(null),W(null),localStorage.removeItem(`${r}_table_order_by`),localStorage.removeItem(`${r}_table_order`)},x=()=>{m(!_)},w=c=>{b(l=>{const g=a.find(G=>G.id===c);if(g&&g.required)return l;const h=f[c]!==!1,F={...l};h?F[c]=!1:delete F[c];try{localStorage.setItem(`${r}_column_visibility`,JSON.stringify(F))}catch{}return F})},z=()=>{b({});try{localStorage.removeItem(`${r}_column_visibility`)}catch{}m(!1)};return n&&console.log(`Rendering table ${r}${C&&T?` ordered by ${C}:${T}`:""}`),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(Ne,{open:_,onClose:(c,l)=>{l==="backdropClick"||l==="escapeKeyDown"||x()},disableEscapeKeyDown:!0,disableRestoreFocus:!0,children:[e.jsx(Fe,{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(Le,{children:e.jsx(Sr,{children:a.filter(c=>!c.hidden).map(c=>e.jsx(Re,{control:e.jsx(He,{disabled:!!c.required,checked:c.required?!0:f[c.id]!==!1,onChange:()=>w(c.id)}),label:c.label},c.id))})}),e.jsxs(_e,{children:[e.jsx(ie,{onClick:z,children:"Reset"}),e.jsx(ie,{variant:"contained",onClick:c=>{if(c?.currentTarget&&typeof c.currentTarget.blur=="function")try{c.currentTarget.blur()}catch{}const l=document.activeElement;if(l&&l instanceof HTMLElement&&typeof l.blur=="function")try{l.blur()}catch{}x()},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}),u&&e.jsx("p",{className:"MbfWindowHeaderText",children:u}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(Q,{onClick:c=>{if(c?.currentTarget?.blur)try{c.currentTarget.blur()}catch{}x()},"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx(R,{title:`Configure ${r} columns`,children:e.jsx(re,{path:so,size:"20px",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:a.map(c=>{if(c.hidden||!c.required&&f[c.id]===!1)return null;const l=!c.noSort,g=l&&C===c.id&&!!T;return e.jsxs("th",{onClick:l?()=>H(c.id):void 0,style:{margin:"0",padding:"5px 10px",position:"sticky",top:0,minWidth:c.minWidth,maxWidth:c.maxWidth,textAlign:c.align||"left",cursor:l?"pointer":"default",border:"none",color:"var(--header-text-color)",backgroundColor:"var(--header-bg-color)",whiteSpace:c.maxWidth?"nowrap":void 0,overflow:c.maxWidth?"hidden":void 0,textOverflow:c.maxWidth?"ellipsis":void 0},"aria-sort":l?g?T==="asc"?"ascending":"descending":"none":void 0,children:[c.label,g&&e.jsxs("span",{style:{marginLeft:6},children:[T==="asc"&&e.jsx(re,{path:lo,size:"15px"}),T==="desc"&&e.jsx(re,{path:co,size:"15px"})]})]},c.id)})})}),e.jsx("tbody",{children:y.map((c,l)=>{const g=L(c);return e.jsx("tr",{className:l%2===0?"table-content-even":"table-content-odd",onClick:t?h=>t(c,g,h):void 0,style:{height:"30px",minHeight:"30px",border:"none",borderCollapse:"collapse",cursor:t?"pointer":void 0},children:a.map(h=>{if(h.hidden||!h.required&&f[h.id]===!1)return null;const F=c[h.id];return e.jsx("td",{style:{border:"none",borderCollapse:"collapse",textAlign:h.align||"left",padding:"5px 10px",margin:"0",maxWidth:h.maxWidth,whiteSpace:h.maxWidth?"nowrap":void 0,overflow:h.maxWidth?"hidden":void 0,textOverflow:h.maxWidth?"ellipsis":void 0},children:typeof h.render=="function"?h.render(F,g,c,h):typeof F=="boolean"?e.jsx(He,{checked:F,disabled:!0,size:"small",sx:{m:0,p:0,color:"var(--table-text-color)","&.Mui-disabled":{color:"var(--table-text-color)",opacity:.7}}}):h.format&&typeof F=="number"?h.format(F):F!=null?String(F):null},h.id)})},g)})})]})}),(v||M)&&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:v}),e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:M})]})]})}function nn(r){return o.memo(r)}const xt=nn(on);function an({storeId:r,setStoreId:u}){const{online:a,sendMessage:i,addListener:s,removeListener:v,getUniqueId:M}=o.useContext(be),{showConfirmCancelDialog:t}=o.useContext(Je),d=o.useRef(M()),[$,L]=o.useState(null),[C,A]=o.useState(null),[T,W]=o.useState([]),_=[{label:"Name",id:"name",required:!0,render:(N,O,D,P)=>e.jsx(R,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>c(D),children:D.name})})},{label:"Description",id:"description",render:(N,O,D,P)=>e.jsx(R,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>c(D),children:D.description})})},{label:"Version",id:"version",render:(N,O,D,P)=>e.jsxs(e.Fragment,{children:[D.latestVersion!==void 0&&D.latestVersion!==D.version&&C&&!C.readOnly&&e.jsx(R,{title:"New plugin stable version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>y(D),children:["Update to v.",D.latestVersion]})}),D.version.includes("-dev-")&&D.devVersion!==void 0&&D.devVersion!==D.version&&C&&!C.readOnly&&e.jsx(R,{title:"New plugin dev version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>H(D),children:["Update to new dev v.",D.devVersion.split("-dev-")[0]]})}),e.jsx(R,{title:"Plugin version",children:e.jsx("span",{children:D.version})})]})},{label:"Author",id:"author",render:(N,O,D,P)=>e.jsx(e.Fragment,{children:D.author?D.author.replace("https://github.com/",""):"Unknown"})},{label:"Type",id:"type",render:(N,O,D,P)=>e.jsx(e.Fragment,{children:D.type?D.type.replace("Platform",""):"Unknown"})},{label:"Devices",id:"registeredDevices"},{label:"Actions",id:"actions",required:!0,noSort:!0,render:(N,O,D,P)=>e.jsxs("div",{style:{margin:"0px",padding:"0px",gap:"4px",display:"flex",flexDirection:"row"},children:[C&&C.bridgeMode==="childbridge"&&!D.error&&D.enabled&&e.jsx(R,{title:"Shows the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:Jt(D.matter)},onClick:()=>{D.matter?.id&&u(D.matter?.id)},size:"small",children:e.jsx(Ut,{})})}),C&&C.bridgeMode==="childbridge"&&!D.error&&D.enabled&&e.jsx(R,{title:"Restart the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0",padding:"0",width:"19px",height:"19px"},onClick:()=>w(D),size:"small",children:e.jsx(ut,{})})}),e.jsx(R,{title:"Plugin config",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{disabled:D.restartRequired===!0,style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>he(D),size:"small",children:e.jsx(Ct,{})})}),C&&!C.readOnly&&e.jsx(R,{title:"Remove the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{E("Remove plugin","Are you sure? This will also remove all devices and configuration from the controller.","remove",D)},size:"small",children:e.jsx(ht,{})})}),D.enabled?e.jsx(R,{title:"Disable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{E("Disable plugin","Are you sure? This will also remove all devices and configuration from the controller.","disable",D)},size:"small",children:e.jsx(Mr,{})})}):e.jsx(e.Fragment,{}),D.enabled?e.jsx(e.Fragment,{}):e.jsx(R,{title:"Enable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>z(D),size:"small",children:e.jsx(kr,{})})}),e.jsx(R,{title:"Open the plugin help",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>g(D),size:"small",children:e.jsx(Ir,{})})}),e.jsx(R,{title:"Open the plugin version history",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>h(D),size:"small",children:e.jsx(Dr,{})})}),C&&!C.readOnly&&e.jsx(R,{title:"Sponsor the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:"#b6409c"},onClick:()=>l(D),size:"small",children:e.jsx(At,{})})})]})},{label:"Status",id:"status",required:!0,noSort:!0,render:(N,O,D,P)=>e.jsx("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",margin:"0",padding:"0",gap:"5px",width:"auto",maxWidth:"max-content"},children:D.error?e.jsx(e.Fragment,{children:e.jsx(Ue,{status:!1,enabledText:"Error",disabledText:"Error",tooltipText:"The plugin is in error state. Check the log!"})}):e.jsx(e.Fragment,{children:D.enabled===!1?e.jsx(e.Fragment,{children:e.jsx(Ue,{status:D.enabled,enabledText:"Enabled",disabledText:"Disabled",tooltipText:"Whether the plugin is enable or disabled"})}):e.jsx(e.Fragment,{children:D.loaded&&D.started&&D.configured?e.jsx(e.Fragment,{children:e.jsx(Ue,{status:D.loaded,enabledText:"Running",tooltipText:"Whether the plugin is running"})}):e.jsxs(e.Fragment,{children:[e.jsx(Ue,{status:D.loaded,enabledText:"Loaded",tooltipText:"Whether the plugin has been loaded"}),e.jsx(Ue,{status:D.started,enabledText:"Started",tooltipText:"Whether the plugin started"}),e.jsx(Ue,{status:D.configured,enabledText:"Configured",tooltipText:"Whether the plugin has been configured"})]})})})})}];o.useEffect(()=>{const N=O=>{O.src==="Matterbridge"&&O.dst==="Frontend"&&(ae(O)&&O.method==="refresh_required"&&O.params.changed==="plugins"&&(n&&console.log(`HomePlugins received refresh_required: changed=${O.params.changed} and sending /api/plugins request`),i({id:d.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),ae(O)&&O.method==="refresh_required"&&O.params.changed==="matter"&&(n&&console.log(`HomePlugins received refresh_required: changed=${O.params.changed} and setting matter id ${O.params.matter?.id}`),W(D=>{const P=D.findIndex(S=>S.matter?.id===O.params.matter?.id);if(P<0)return n&&console.log(`HomePlugins received refresh_required: changed=${O.params.changed} and matter id ${O.params.matter?.id} not found`),D;n&&console.log(`HomePlugins received refresh_required: changed=${O.params.changed} set matter id ${O.params.matter?.id}`);const k=[...D];return k[P]={...k[P],matter:O.params.matter},k})),ae(O)&&O.method==="refresh_required"&&O.params.changed==="settings"&&(n&&console.log(`HomePlugins received refresh_required: changed=${O.params.changed} and sending /api/settings request`),i({id:d.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),ge(O)&&O.id===d.current&&O.method==="/api/settings"&&(n&&console.log(`HomePlugins (id: ${O.id}) received settings:`,O.response),L(O.response.systemInformation),A(O.response.matterbridgeInformation)),ge(O)&&O.id===d.current&&O.method==="/api/plugins"&&(n&&console.log(`HomePlugins (id: ${O.id}) received ${O.response.length} plugins:`,O.response),W(O.response)))};return s(N),n&&console.log("HomePlugins added WebSocket listener id:",d.current),()=>{v(N),n&&console.log("HomePlugins removed WebSocket listener")}},[s,v,i]),o.useEffect(()=>{a&&(n&&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]);const m=o.useRef(null),E=(N,O,D,P)=>{n&&console.log(`handleActionWithConfirmCancel ${D} ${P.name}`),m.current=P,t(N,O,D,b,f)},b=N=>{n&&console.log(`handleConfirm action confirmed ${N} ${m.current?.name}`),N==="remove"&&m.current?x(m.current):N==="disable"&&m.current&&z(m.current),m.current=null},f=N=>{n&&console.log(`handleCancel action canceled ${N} ${m.current?.name}`),m.current=null},y=N=>{n&&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}})},H=N=>{n&&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}})},x=N=>{n&&console.log("handleRemovePlugin plugin:",N.name),i({id:d.current,sender:"HomePlugins",method:"/api/removeplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:N.name}})},w=N=>{n&&console.log("handleRestartPlugin plugin:",N.name),i({id:d.current,sender:"HomePlugins",method:"/api/restartplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:N.name}})},z=N=>{n&&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}}))},c=N=>{n&&console.log(`handleHomepagePlugin plugin: ${N.name} homepage: ${N.homepage}`),N.homepage&&window.open(N.homepage,"_blank")},l=N=>{n&&console.log("handleSponsorPlugin plugin:",N.name,"funding:",N.funding),N.funding&&window.open(N.funding,"_blank")},g=N=>{n&&console.log("handleHelpPlugin plugin:",N.name,"help:",N.help),N.help&&window.open(N.help,"_blank")},h=N=>{n&&console.log("handleChangelogPlugin plugin:",N.name,"changelog:",N.changelog),N.changelog&&window.open(N.changelog,"_blank")},[F,G]=o.useState(),[ye,xe]=o.useState(!1),he=N=>{n&&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}}),G(N),X()},X=()=>{xe(!0)},se=()=>{xe(!1)};return n&&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:[F&&e.jsx(tn,{open:ye,onClose:se,plugin:F}),e.jsx(xt,{name:"Plugins",columns:_,rows:T,footerRight:"",footerLeft:""})]}):e.jsx(Ae,{})}const sn=o.memo(an),ln=r=>`${r.pluginName}::${r.serial}`;function dn({storeId:r,setStoreId:u}){const{online:a,sendMessage:i,addListener:s,removeListener:v,getUniqueId:M}=o.useContext(be),[t,d]=o.useState(!1),[$,L]=o.useState(!0),[C,A]=o.useState(null),[T,W]=o.useState([]),[_,m]=o.useState([]),[E,b]=o.useState([]),[f,y]=o.useState([]),H=o.useRef(M()),x=[{label:"Plugin",id:"pluginName"},{label:"Name",id:"name",required:!0},{label:"Serial",id:"serial"},{label:"Availability",id:"availability",render:(c,l,g,h)=>g.reachable===!0?"Online":g.reachable===!1?e.jsx("span",{style:{color:"red"},children:"Offline"}):"",comparator:(c,l)=>{const g=c.reachable===!0?1:c.reachable===!1?0:-1,h=l.reachable===!0?1:l.reachable===!1?0:-1;return g-h}},{label:"Power",id:"powerSource",render:(c,l,g,h)=>g.powerSource==="ac"||g.powerSource==="dc"?e.jsx(qt,{fontSize:"small",sx:{color:"var(--primary-color)"}}):g.powerSource==="ok"?e.jsx(gt,{fontSize:"small",sx:{color:"green"}}):g.powerSource==="warning"?e.jsx(gt,{fontSize:"small",sx:{color:"yellow"}}):g.powerSource==="critical"?e.jsx(gt,{fontSize:"small",sx:{color:"red"}}):e.jsx("span",{})},{label:"Url",id:"configUrl"},{label:"Actions",id:"selected",required:!0,render:(c,l,g,h)=>e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[g.matter!==void 0?e.jsx(R,{title:"Show the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{onClick:()=>u(r===g.matter?.id?C?.matterbridgeInformation.bridgeMode==="bridge"?"Matterbridge":null:g.matter?.id||null),"aria-label":"Show the QRCode",sx:{margin:0,padding:0,color:Jt(g.matter)},children:e.jsx(Ut,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),g.configUrl?e.jsx(R,{title:"Open the configuration page",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{onClick:()=>window.open(g.configUrl,"_blank"),"aria-label":"Open config url",sx:{margin:0,padding:0},children:e.jsx(Ct,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),g.selected!==void 0?e.jsx(R,{title:"Select/unselect the device",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(He,{checked:g.selected,onChange:F=>z(F,g),sx:{margin:"0",marginLeft:"8px",padding:"0"},size:"small"})}):e.jsx("div",{style:{width:"20px",height:"20px"}})]})}],w=o.useCallback(c=>{c.selected=void 0;const l=T.find(F=>F.name===c.pluginName);if(!l)return console.error(`HomeDevices isSelected: plugin ${c.pluginName} not found for device ${c.name} `),c.selected;const g=l.schemaJson?.properties?.whiteList?.selectFrom;let h=l.configJson.postfix;return h===""&&(h=void 0),l.hasWhiteList===!0&&l.hasBlackList===!0&&g&&(c.selected=!0,g==="serial"&&l.configJson.whiteList&&l.configJson.whiteList.length>0&&l.configJson.whiteList.includes(h?c.serial.replace("-"+h,""):c.serial)&&(c.selected=!0),g==="serial"&&l.configJson.whiteList&&l.configJson.whiteList.length>0&&!l.configJson.whiteList.includes(h?c.serial.replace("-"+h,""):c.serial)&&(c.selected=!1),g==="serial"&&l.configJson.blackList&&l.configJson.blackList.length>0&&l.configJson.blackList.includes(h?c.serial.replace("-"+h,""):c.serial)&&(c.selected=!1),g==="name"&&l.configJson.whiteList&&l.configJson.whiteList.length>0&&l.configJson.whiteList.includes(c.name)&&(c.selected=!0),g==="name"&&l.configJson.whiteList&&l.configJson.whiteList.length>0&&!l.configJson.whiteList.includes(c.name)&&(c.selected=!1),g==="name"&&l.configJson.blackList&&l.configJson.blackList.length>0&&l.configJson.blackList.includes(c.name)&&(c.selected=!1)),c.selected},[T]);o.useEffect(()=>{const c=l=>{if(l.src==="Matterbridge"&&l.dst==="Frontend"){if(ae(l)&&l.method==="refresh_required"&&l.params.changed!=="matter"&&(n&&console.log(`HomeDevices received refresh_required: changed=${l.params.changed} and sending /api/plugins request`),i({id:H.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),ae(l)&&l.method==="refresh_required"&&l.params.changed==="matter"&&(n&&console.log(`HomeDevices received refresh_required: changed=${l.params.changed} and setting matter id ${l.params.matter?.id}`),y(g=>{const h=g.findIndex(G=>G.name.replaceAll(" ","")===l.params.matter?.id);if(h<0)return n&&console.debug(`HomeDevices: matter id ${l.params.matter?.id} not found`),g;const F=[...g];return F[h]={...F[h],matter:l.params.matter},n&&console.log(`HomeDevices received refresh_required: changed=${l.params.changed} and set matter id ${l.params.matter?.id}`),F})),ae(l)&&l.method==="restart_required"&&(n&&console.log("HomeDevices received restart_required"),d(!0)),ae(l)&&l.method==="restart_not_required"&&(n&&console.log("HomeDevices received restart_not_required"),d(!1)),ae(l)&&l.method==="state_update"&&l.params.plugin&&l.params.serialNumber&&l.params.cluster.includes("BasicInformationServer")&&l.params.attribute==="reachable"&&(console.log(`HomeDevices updating device reachability for plugin ${l.params.plugin} serial ${l.params.serialNumber} value ${l.params.value}`),m(g=>g.map(h=>h.pluginName===l.params.plugin&&h.serial===l.params.serialNumber?{...h,reachable:l.params.value}:h))),ge(l)&&l.id===H.current&&l.method==="/api/settings"&&(n&&console.log(`HomeDevices (id: ${l.id}) received settings:`,l.response),A(l.response),d(l.response.matterbridgeInformation.restartRequired||l.response.matterbridgeInformation.fixedRestartRequired)),ge(l)&&l.id===H.current&&l.method==="/api/plugins"&&(n&&console.log(`HomeDevices (id: ${l.id}) received ${l.response?.length} plugins:`,l.response),l.response)){let g=!0;for(const h of l.response)h.enabled===!0&&(h.loaded!==!0||h.started!==!0||h.error===!0)&&(g=!1);if(!g)return;n&&console.log("HomeDevices reset plugins, devices and selectDevices"),L(!1),W(l.response),m([]),b([]),i({id:H.current,sender:"HomeDevices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}),n&&console.log("HomeDevices sent /api/devices");for(const h of l.response)h.enabled===!0&&h.loaded===!0&&h.started===!0&&h.error!==!0&&(i({id:H.current,sender:"HomeDevices",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:h.name}}),n&&console.log(`HomeDevices sent /api/select/devices for plugin: ${h.name}`))}if(ge(l)&&l.id===H.current&&l.method==="/api/devices"&&(n&&console.log(`HomeDevices (id: ${l.id}) received ${l.response?.length} devices:`,l.response),l.response)){for(const g of l.response)g.selected=w(g);m(l.response)}ge(l)&&l.id===H.current&&l.method==="/api/select/devices"&&(n&&console.log(`HomeDevices (id: ${l.id}) received ${l.response?.length} selectDevices for plugin ${l.response&&l.response.length>0?l.response[0].pluginName:"without select devices"}:`,l.response),l.response&&l.response.length>0&&b(g=>{const h=g.filter(G=>G.pluginName!==l.response[0].pluginName),F=l.response.map(G=>({...G,selected:w(G)}));return[...h,...F]}))}};return s(c),n&&console.log(`HomeDevices added WebSocket listener id ${H.current}`),()=>{v(c),n&&console.log("HomeDevices removed WebSocket listener")}},[T,s,v,i,w]),o.useEffect(()=>{if(_.length===0&&E.length===0){y([]);return}n&&console.log(`HomeDevices mixing devices (${_.length}) and selectDevices (${E.length})`);const c=[];for(const l of _)c.push(l);for(const l of E)_.find(g=>g.pluginName===l.pluginName&&g.serial.includes(l.serial))||c.push(l);c.length>0&&(y(c),n&&console.log(`HomeDevices mixed ${c.length} devices and selectDevices`))},[T,_,E,y]),o.useEffect(()=>{a&&(n&&console.log("HomeDevices sending /api/settings and /api/plugins requests"),i({id:H.current,sender:"HomeDevices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),i({id:H.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[a,i]);const z=(c,l)=>{console.log(`handleCheckboxChange: checkbox changed to ${c.target.checked} for device ${l.name} serial ${l.serial}`),y(g=>{const h=g.findIndex(G=>G.pluginName===l.pluginName&&G.serial===l.serial);if(h<0)return console.error(`handleCheckboxChange: device not found ${l.name} serial ${l.serial}`),g;const F=[...g];return F[h]={...F[h],selected:c.target.checked},F}),c.target.checked?i({id:H.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"selectdevice",plugin:l.pluginName,serial:l.serial,name:l.name}}):i({id:H.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"unselectdevice",plugin:l.pluginName,serial:l.serial,name:l.name}})};return n&&console.log("HomeDevices rendering..."),a?e.jsx("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",overflow:"hidden"},children:e.jsx(xt,{name:"Devices",getRowKey:ln,rows:f,columns:x,footerLeft:$?"Waiting for the plugins to fully load...":`Registered devices: ${_.length.toString()}/${f.length.toString()}`,footerRight:t?"Restart required":""})}):e.jsx(Ae,{})}const cn=o.memo(dn);function pn(){const[r,u]=o.useState(null),[a,i]=o.useState(null),[s,v]=o.useState([]),[M]=o.useState(localStorage.getItem("homePagePlugins")!=="false"),[t,d]=o.useState(localStorage.getItem("homePageMode")??"devices"),[$,L]=o.useState(""),[C,A]=o.useState(!1),[T,W]=o.useState(!1),[_,m]=o.useState(null),{addListener:E,removeListener:b,online:f,sendMessage:y,logFilterLevel:H,logFilterSearch:x,autoScroll:w,getUniqueId:z}=o.useContext(be),c=o.useRef(z());return o.useEffect(()=>{const l=g=>{g.src==="Matterbridge"&&g.dst==="Frontend"&&(ae(g)&&g.method==="refresh_required"&&g.params.changed==="settings"&&(n&&console.log(`Home received refresh_required: changed=${g.params.changed} and sending /api/settings request`),m(null),v([]),y({id:c.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),y({id:c.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),ge(g)&&g.method==="/api/settings"&&g.id===c.current&&(n&&console.log("Home received settings:",g.response),u(g.response.systemInformation),i(g.response.matterbridgeInformation),g.response.matterbridgeInformation.bridgeMode==="bridge"&&(_||m("Matterbridge")),g.response.matterbridgeInformation.bridgeMode==="childbridge"&&s.length>0&&_===null&&!_&&s.length>0&&s[0].matter?.id&&m(s[0].matter.id),g.response.matterbridgeInformation.matterbridgeVersion&&L(`https://github.com/Luligu/matterbridge/blob/${g.response.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?"dev":"main"}/CHANGELOG.md`),localStorage.getItem("frontendVersion")===null&&g.response.matterbridgeInformation.frontendVersion?localStorage.setItem("frontendVersion",g.response.matterbridgeInformation.frontendVersion):g.response.matterbridgeInformation.frontendVersion!==localStorage.getItem("frontendVersion")&&g.response.matterbridgeInformation.frontendVersion&&(localStorage.setItem("frontendVersion",g.response.matterbridgeInformation.frontendVersion),W(!0)),localStorage.getItem("matterbridgeVersion")===null?localStorage.setItem("matterbridgeVersion",g.response.matterbridgeInformation.matterbridgeVersion):g.response.matterbridgeInformation.matterbridgeVersion!==localStorage.getItem("matterbridgeVersion")&&(localStorage.setItem("matterbridgeVersion",g.response.matterbridgeInformation.matterbridgeVersion),A(!0)),g.response.matterbridgeInformation.shellyBoard&&(localStorage.getItem("homePageMode")||(localStorage.setItem("homePageMode","devices"),d("devices")))),ge(g)&&g.method==="/api/plugins"&&g.id===c.current&&(n&&console.log(`Home received plugins (${a?.bridgeMode}):`,g.response),v(g.response),a?.bridgeMode==="childbridge"&&g.response.length>0&&!_&&g.response.length>0&&g.response[0].matter?.id&&m(g.response[0].matter.id)))};return E(l),n&&console.log(`Home added WebSocket listener id ${c.current}`),()=>{b(l),n&&console.log("Home removed WebSocket listener")}},[E,b,y,a,s,_]),o.useEffect(()=>{f&&(n&&console.log("Home received online"),y({id:c.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),y({id:c.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[f,y]),n&&console.log("Home rendering..."),!f||!r||!a?e.jsx(Ae,{}):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(Jo,{id:_}),e.jsx(Bo,{systemInfo:r,compact:!0})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",gap:"20px"},children:[T&&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(ie,{onClick:()=>window.location.reload(),endIcon:e.jsx(Pr,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Refresh"})})]})]}),C&&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(ie,{onClick:()=>window.open($,"_blank"),endIcon:e.jsx(Vt,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Changelog"}),e.jsx(ie,{onClick:()=>window.location.reload(),endIcon:e.jsx(Nr,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Close"})]})]})]}),M&&!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(Yo,{})]}),M&&e.jsx(sn,{storeId:_,setStoreId:m}),t==="devices"&&e.jsx(cn,{storeId:_,setStoreId:m}),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 "',H,'" and search "',x,'" Scroll: ',w?"auto":"manual"]})})]}),e.jsx("div",{style:{flex:"1 1 auto",margin:"0px",padding:"10px",overflow:"auto"},children:e.jsx(Kt,{})})]})]})]})}const un=o.memo(pn),Et={display:"flex",gap:"2px",justifyContent:"space-evenly",width:"100%",height:"40px"},mn={margin:"0",padding:"0",fontSize:"36px",fontWeight:"medium",color:"var(--primary-color)"},gn={margin:"0",padding:"0",fontSize:"20px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},_t={margin:"0",padding:"0",paddingBottom:"2px",fontSize:"16px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},hn={display:"flex",gap:"2px",justifyContent:"center",width:"100%",height:"18px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},fn={margin:"0",padding:"0",fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)"},xn={display:"flex",justifyContent:"center",width:"100%",height:"52px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},bn={margin:"0",padding:"0",fontSize:"14px",fontWeight:"bold",color:"var(--div-text-color)"},vn={display:"flex",gap:"4px",justifyContent:"center",width:"100%",height:"15px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},jt={margin:"0",padding:"0px 4px",borderRadius:"5px",textAlign:"center",fontSize:"12px",fontWeight:"normal",color:"var(--secondary-color)"},yn=[256,257,268,269],jn=[266,267],Cn=[259,260,261,271,272],wn=[256,257,268,269,266,267,259,260,261];function U({icon:r,iconColor:u,cluster:a,value:i,unit:s,prefix:v}){return n&&console.log(`Render cluster "${a.clusterName}.${a.attributeName}" value(${typeof i}-${isNaN(i)}) "${i}" unit "${s}"`),v=v??!1,e.jsxs(Z,{sx:Et,children:[r&&o.cloneElement(r,{key:`${a.clusterId}-${a.attributeId}-icon`,sx:{...mn,color:u??"var(--primary-color)"}}),e.jsxs(Z,{sx:{...Et,gap:"4px",alignContent:"center",alignItems:"end",justifyContent:"center"},children:[s&&v===!0&&e.jsx(ne,{sx:_t,children:s},`${a.clusterId}-${a.attributeId}-unit`),e.jsx(ne,{sx:gn,children:i==null||typeof i=="number"&&isNaN(i)||i==="NaN"?"---":i},`${a.clusterId}-${a.attributeId}-value`),s&&v===!1&&e.jsx(ne,{sx:_t,children:s},`${a.clusterId}-${a.attributeId}-unit`)]},`${a.clusterId}-${a.attributeId}-valueunitbox`)]},`${a.clusterId}-${a.attributeId}-box`)}function Sn({device:r,endpoint:u,id:a,deviceType:i,clusters:s}){const v=["Unknown","Good","Fair","Moderate","Poor","VeryPoor","Ext.Poor"];let M="";return n&&console.log(`Device "${r.name}" endpoint "${u}" id "${a}" deviceType "0x${i.toString(16).padStart(4,"0")}" clusters (${s?.length}):`,s),i===17&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batVoltage").map(t=>M=`${t.attributeLocalValue} mV`),wn.includes(i)&&s.filter(t=>t.clusterName==="LevelControl"&&t.attributeName==="currentLevel").map(t=>M=`Level ${t.attributeValue}`),i===514&&s.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>M=`Position ${t.attributeLocalValue/100}%`),i===769&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedHeatingSetpoint").map(t=>M=`Heat ${t.attributeLocalValue/100}°C `),i===769&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedCoolingSetpoint").map(t=>M=M+`Cool ${t.attributeLocalValue/100}°C`),i===118&&s.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>M=`${t.attributeLocalValue===0?"No CO detected":"CO alarm!"}`),i===1296&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="voltage").map(t=>M=`${t.attributeLocalValue/1e3} V, `),i===1296&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activeCurrent").map(t=>M=M+`${t.attributeLocalValue/1e3} A, `),i===1296&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activePower").map(t=>M=M+`${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&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(U,{icon:t.attributeLocalValue===!0?e.jsx(Ze,{}):e.jsx(Fr,{}),iconColor:t.attributeLocalValue===!0?"green":"red",cluster:t,value:t.attributeLocalValue===!0?"Online":"Offline"})),i===17&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batPercentRemaining").map(t=>e.jsx(U,{icon:e.jsx(gt,{}),cluster:t,value:t.attributeLocalValue/2,unit:"%"})),i===17&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="wiredCurrentType").map(t=>e.jsx(U,{icon:e.jsx(qt,{}),cluster:t,value:t.attributeLocalValue===0?"AC":"DC"})),i===1293&&s.filter(t=>t.clusterName==="DeviceEnergyManagement"&&t.attributeName==="esaState").map(t=>e.jsx(U,{icon:e.jsx(re,{path:po,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Offline":"Online"})),yn.includes(i)&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(U,{icon:e.jsx(Lr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),jn.includes(i)&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(U,{icon:e.jsx(re,{path:uo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),Cn.includes(i)&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(U,{icon:e.jsx(re,{path:mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),i===115&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(U,{icon:e.jsx(re,{path:go,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===124&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(U,{icon:e.jsx(re,{path:ho,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===117&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(U,{icon:e.jsx(re,{path:fo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===123&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(U,{icon:e.jsx(Ft,{}),cluster:t,value:"Oven"})),i===112&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(U,{icon:e.jsx(Wr,{}),cluster:t,value:"Fridge"})),i===113&&s.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(U,{icon:e.jsx(re,{path:xo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),i===121&&s.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(U,{icon:e.jsx(Ft,{}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),i===122&&s.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="fanMode").map(t=>e.jsx(U,{icon:e.jsx(re,{path:bo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),i===120&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(U,{icon:e.jsx(re,{path:Rt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Cooktop"})),i===119&&s.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(U,{icon:e.jsx(re,{path:Rt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),i===116&&s.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(U,{icon:e.jsx(re,{path:vo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Robot"})),i===514&&s.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>e.jsx(U,{icon:e.jsx(Tr,{}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),i===769&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(U,{icon:e.jsx(re,{path:yo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),i===10&&s.filter(t=>t.clusterName==="DoorLock"&&t.attributeName==="lockState").map(t=>e.jsx(U,{icon:t.attributeValue==="1"?e.jsx($r,{}):e.jsx(Rr,{}),cluster:t,value:t.attributeValue==="1"?"Locked":"Unlocked"})),i===43&&s.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(U,{icon:e.jsx(Hr,{}),cluster:t,value:t.attributeValue,unit:"%"})),i===15&&s.filter(t=>t.clusterName==="Switch"&&t.attributeName==="currentPosition").map(t=>e.jsx(U,{icon:e.jsx(re,{path:jo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeValue,unit:"pos",prefix:!0})),i===39&&s.filter(t=>t.clusterName==="ModeSelect"&&t.attributeName==="currentMode").map(t=>e.jsx(U,{icon:e.jsx(Or,{}),cluster:t,value:t.attributeValue,unit:"mode",prefix:!0})),i===771&&s.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(U,{icon:e.jsx(Er,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),i===45&&s.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(U,{icon:e.jsx(Lt,{}),cluster:t,value:t.attributeValue,unit:"%"})),i===114&&s.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(U,{icon:e.jsx(Lt,{}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),i===67&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(U,{icon:e.jsx(_r,{}),cluster:t,value:t.attributeLocalValue===!0?"Leak":"No leak"})),i===65&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(U,{icon:e.jsx(Ar,{}),cluster:t,value:t.attributeLocalValue===!0?"Freeze":"No freeze"})),i===68&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(U,{icon:e.jsx(Vr,{}),cluster:t,value:t.attributeLocalValue===!0?"Rain":"No rain"})),i===1292&&s.filter(t=>t.clusterName==="EnergyEvse"&&t.attributeName==="state").map(t=>e.jsx(U,{icon:e.jsx(re,{path:Co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Free":"In use"})),i===1295&&s.filter(t=>t.clusterName==="WaterHeaterManagement"&&t.attributeName==="tankPercentage").map(t=>e.jsx(U,{icon:e.jsx(re,{path:wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Tank "+(t.attributeLocalValue??0)+"%"})),i===777&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(U,{icon:e.jsx(re,{path:So,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"HeatPump"})),i===23&&s.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(U,{icon:e.jsx(re,{path:Mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Solar"})),i===24&&s.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="featureMap").map(t=>e.jsx(U,{icon:e.jsx(re,{path:ko,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Inverter"})),i===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(U,{icon:e.jsx(re,{path:Ht,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No smoke":"Smoke!"})),i===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(U,{icon:e.jsx(re,{path:Ht,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No Co":"Co!"})),i===66&&s.filter(t=>t.clusterName==="ValveConfigurationAndControl"&&t.attributeName==="currentState").map(t=>e.jsx(U,{icon:e.jsx(Ur,{}),cluster:t,value:t.attributeLocalValue===0?"Closed":"Opened"})),i===44&&s.filter(t=>t.clusterName==="AirQuality"&&t.attributeName==="airQuality").map(t=>e.jsx(U,{icon:e.jsx(re,{path:Io,size:"40px",color:"var(--primary-color)"}),cluster:t,value:v[t.attributeLocalValue??0]})),i===770&&s.filter(t=>t.clusterName==="TemperatureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(U,{icon:e.jsx(qr,{}),cluster:t,value:t.attributeLocalValue/100,unit:"°C"})),i===775&&s.filter(t=>t.clusterName==="RelativeHumidityMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(U,{icon:e.jsx(re,{path:Do,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),i===774&&s.filter(t=>t.clusterName==="FlowMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(U,{icon:e.jsx(zr,{}),cluster:t,value:t.attributeLocalValue,unit:"l/h"})),i===773&&s.filter(t=>t.clusterName==="PressureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(U,{icon:e.jsx(Br,{}),cluster:t,value:t.attributeLocalValue,unit:"hPa"})),i===21&&s.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(U,{icon:t.attributeValue==="true"?e.jsx(Qr,{}):e.jsx(Kr,{}),cluster:t,value:t.attributeValue==="true"?"Closed":"Opened"})),i===263&&s.filter(t=>t.clusterName==="OccupancySensing"&&t.attributeName==="occupancy").map(t=>e.jsx(U,{icon:t.attributeValue==="{ occupied: true }"?e.jsx(Jr,{}):e.jsx(Gr,{}),cluster:t,value:t.attributeValue==="{ occupied: true }"?"Occupied":"Unocc."})),i===262&&s.filter(t=>t.clusterName==="IlluminanceMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(U,{icon:e.jsx(Yr,{}),cluster:t,value:Math.round(Math.pow(10,t.attributeLocalValue/1e4)),unit:"lx"})),i===1296&&s.filter(t=>t.clusterName==="ElectricalEnergyMeasurement"&&t.attributeName==="cumulativeEnergyImported").map(t=>e.jsx(U,{icon:e.jsx(Xr,{}),cluster:t,value:Math.round(t.attributeLocalValue?.energy/1e6),unit:"kwh"})),e.jsx(Z,{sx:hn,children:e.jsx(ne,{sx:fn,children:M})}),e.jsx(Z,{sx:xn,children:e.jsx(ne,{sx:bn,children:r.name})}),e.jsxs(Z,{sx:vn,children:[n&&e.jsx(ne,{sx:jt,children:u}),e.jsx(ne,{sx:jt,children:a}),n&&e.jsxs(ne,{sx:jt,children:["0x",i.toString(16).padStart(4,"0")]})]})]})}function Mn({filter:r}){const{online:u,sendMessage:a,addListener:i,removeListener:s,getUniqueId:v}=o.useContext(be),[M,t]=o.useState(null),[d,$]=o.useState([]),[L,C]=o.useState([]),[A,T]=o.useState(L),[W,_]=o.useState({}),[m,E]=o.useState({}),[b,f]=o.useState({}),y=o.useRef(v());o.useEffect(()=>{const x=w=>{if(w.src==="Matterbridge"&&w.dst==="Frontend"){if(ae(w)&&w.method==="refresh_required"&&(n&&console.log(`DevicesIcons received refresh_required: changed=${w.params.changed} and sending api requests`),a({id:y.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:y.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:y.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),ge(w)&&w.method==="/api/settings"&&w.response&&(n&&console.log("DevicesIcons received settings:",w.response),t(w.response)),ge(w)&&w.method==="/api/plugins"&&w.response&&(n&&console.log("DevicesIcons received plugins:",w.response),$(w.response)),ge(w)&&w.method==="/api/devices"&&w.response){n&&console.log(`DevicesIcons received ${w.response.length} devices:`,w.response),C(w.response);for(const z of w.response)n&&console.log("DevicesIcons sending /api/clusters"),a({id:y.current,sender:"Icons",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:z.pluginName,endpoint:z.endpoint||0}})}if(ge(w)&&w.method==="/api/clusters"&&w.response){if(n&&console.log(`DevicesIcons received for device "${w.response.deviceName}" serial "${w.response.serialNumber}" deviceType ${w.response.deviceTypes.join(" ")} clusters (${w.response.clusters.length}):`,w.response),w.response.clusters.length===0)return;const z=w.response.serialNumber;W[z]=[],m[z]=w.response.deviceTypes,b[z]=[];for(const c of w.response.clusters)W[z].find(l=>l.endpoint===c.endpoint)||W[z].push({endpoint:c.endpoint,id:c.id,deviceTypes:c.deviceTypes}),!["FixedLabel","Descriptor","Identify","Groups","PowerTopology"].includes(c.clusterName)&&b[z].push(c);_({...W}),E({...m}),f({...b}),n&&console.log(`DevicesIcons endpoints for "${z}":`,W[z]),n&&console.log(`DevicesIcons deviceTypes for "${z}":`,m[z]),n&&console.log(`DevicesIcons clusters for "${z}":`,b[z])}}};return i(x),n&&console.log("DevicesIcons useEffect webSocket mounted"),()=>{s(x),n&&console.log("DevicesIcons useEffect webSocket unmounted")}},[i,s,a]),o.useEffect(()=>(n&&console.log("DevicesIcons useEffect online mounting"),u&&(n&&console.log("DevicesIcons useEffect online sending api requests"),a({id:y.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:y.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),a({id:y.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),n&&console.log("DevicesIcons useEffect online mounted"),()=>{n&&console.log("DevicesIcons useEffect online unmounted")}),[u,a]),o.useEffect(()=>{if(r===""){T(L);return}const x=L.filter(w=>w.name.toLowerCase().includes(r)||w.serial.toLowerCase().includes(r));T(x)},[L,r]);const H=o.memo(Sn);return n&&console.log("DevicesIcons rendering..."),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"auto"},children:A.map(x=>W[x.serial]&&W[x.serial].map(w=>w.deviceTypes.map(z=>e.jsx(H,{device:x,endpoint:w.endpoint,id:w.id,deviceType:z,clusters:b[x.serial].filter(c=>c.endpoint===w.endpoint)},`${x.pluginName}-${x.uniqueId}-${z}`))))})}const kn=o.memo(Mn),In=[{label:"Plugin name",id:"pluginName",required:!0},{label:"Device type",id:"type"},{label:"Endpoint",id:"endpoint",align:"right"},{label:"Name",id:"name",required:!0},{label:"Serial number",id:"serial"},{label:"Unique ID",id:"uniqueId"},{label:"Url",id:"configUrl"},{label:"Config",id:"configButton",noSort:!0,render:(r,u,a,i)=>a.configUrl?e.jsx(Q,{onClick:()=>window.open(a.configUrl,"_blank"),"aria-label":"Open Config",sx:{margin:0,padding:0},children:e.jsx(Ct,{fontSize:"small"})}):null},{label:"Cluster",id:"cluster"}],Dn=[{label:"Endpoint",id:"endpoint",required:!0},{label:"Id",id:"id"},{label:"Device Types",id:"deviceTypes",render:(r,u,a,i)=>Array.isArray(r)?e.jsx(e.Fragment,{children:r.map(s=>`0x${s.toString(16).padStart(4,"0")}`).join(", ")}):e.jsx(e.Fragment,{children:r})},{label:"Cluster Name",id:"clusterName",required:!0},{label:"Cluster ID",id:"clusterId"},{label:"Attribute Name",id:"attributeName",required:!0},{label:"Attribute ID",id:"attributeId"},{label:"Attribute Value",id:"attributeValue",required:!0,render:(r,u,a,i)=>e.jsx(R,{title:String(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:String(r)})})}],Pn=r=>`${r.pluginName}::${r.uniqueId}`,Nn=r=>`${r.endpoint}::${r.clusterName}::${r.attributeName}`;function Fn(){const{online:r,sendMessage:u,addListener:a,removeListener:i,getUniqueId:s}=o.useContext(be),[v,M]=o.useState([]),[t,d]=o.useState(v),[$,L]=o.useState([]),[C,A]=o.useState(0),[T,W]=o.useState(""),[_,m]=o.useState("icon"),[E,b]=o.useState(null),[f,y]=o.useState(null),[H,x]=o.useState(null),[w,z]=o.useState(null),c=o.useRef(s());o.useEffect(()=>{const F=G=>{if(n&&console.log("Devices received WebSocket Message:",G),G.src==="Matterbridge"&&G.dst==="Frontend"&&(ae(G)&&G.method==="refresh_required"&&G.params.changed==="devices"&&(n&&console.log(`Devices received refresh_required: changed=${G.params.changed} and sending /api/devices request`),u({id:c.current,sender:"Devices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),ge(G)&&G.method==="/api/devices"&&(n&&console.log(`Devices received ${G.response.length} devices:`,G.response),M(G.response)),ge(G)&&G.method==="/api/clusters")){n&&console.log(`Clusters received ${G.response.clusters.length} clusters for plugin ${G.response.plugin}:`,G.response),L(G.response.clusters);const ye={};for(const xe of G.response.clusters)n&&console.log("Cluster:",xe.endpoint),ye[xe.endpoint]?ye[xe.endpoint]++:ye[xe.endpoint]=1;A(Object.keys(ye).length)}};return a(F),n&&console.log("Devices added WebSocket listener"),()=>{i(F),n&&console.log("Devices removed WebSocket listener")}},[a,i,u]),o.useEffect(()=>{r&&(n&&console.log("Devices sending api requests"),u({id:c.current,sender:"Devices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:c.current,sender:"Devices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:c.current,sender:"Devices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}))},[r,u]),o.useEffect(()=>{E&&f&&(n&&console.log("Devices sending /api/clusters"),u({id:c.current,sender:"Devices",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:E,endpoint:Number(f)}}))},[E,f,u]),o.useEffect(()=>{if(T===""){d(v);return}const F=v.filter(G=>G.name.toLowerCase().includes(T)||G.serial.toLowerCase().includes(T));d(F)},[v,T]),o.useEffect(()=>{const F=localStorage.getItem("devicesFilter");F&&W(F)},[]),o.useEffect(()=>{const F=localStorage.getItem("devicesViewMode");F&&m(F)},[]);const l=F=>{W(F.target.value.toLowerCase()),localStorage.setItem("devicesFilter",F.target.value.toLowerCase())},g=F=>{m(F),localStorage.setItem("devicesViewMode",F)},h=F=>{if(F.uniqueId===w){z(null),b(null),y(null),x(null);return}z(F.uniqueId),b(F.pluginName),y(F.endpoint?F.endpoint.toString():null),x(F.name)};return n&&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(ne,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{variant:"outlined",value:T,onChange:l,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(ne,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"View mode:"}),e.jsx(Q,{onClick:()=>g("table"),"aria-label":"Table View",disabled:_==="table",children:e.jsx(R,{title:"Table View",children:e.jsx(Zr,{style:{color:_==="table"?"var(--main-icon-color)":"var(--primary-color)"}})})}),e.jsx(Q,{onClick:()=>g("icon"),"aria-label":"Icon View",disabled:_==="icon",children:e.jsx(R,{title:"Icon View (beta)",children:e.jsx(eo,{style:{color:_==="icon"?"var(--main-icon-color)":"var(--primary-color)"}})})})]})]}),_==="table"&&e.jsx("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",maxHeight:`${E&&f?"50%":"100%"}`,width:"100%",flex:"1 1 auto",overflow:"hidden"},children:e.jsx(xt,{name:"Registered devices",getRowKey:Pn,onRowClick:h,rows:t,columns:In,footerLeft:`Total devices: ${t.length.toString()}`})}),_==="table"&&E&&f&&e.jsx("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(xt,{name:"Clusters",title:H||"",getRowKey:Nn,rows:$,columns:Dn,footerLeft:`Total child endpoints: ${C-1}`})}),_==="icon"&&e.jsx(kn,{filter:T})]}):e.jsx(Ae,{})}const Ln=o.memo(Fn);function Wn(){const[r,u]=o.useState(localStorage.getItem("logFilterLevel")??"info"),[a,i]=o.useState(localStorage.getItem("logFilterSearch")??"*"),[s,v]=o.useState(localStorage.getItem("logAutoScroll")!=="false"),{setMessages:M,setLogFilters:t,online:d,setAutoScroll:$}=o.useContext(be),L=W=>{u(W.target.value),t(W.target.value,a),localStorage.setItem("logFilterLevel",W.target.value),n&&console.log("handleChangeLevel called with value:",W.target.value)},C=W=>{i(W.target.value),t(r,W.target.value),localStorage.setItem("logFilterSearch",W.target.value),n&&console.log("handleChangeSearch called with value:",W.target.value)},A=W=>{v(W.target.checked),$(W.target.checked),localStorage.setItem("logAutoScroll",W.target.value?"true":"false"),n&&console.log("handleAutoScrollChange called with value:",W.target.checked)},T=()=>{n&&console.log("handleClearLogsClick called"),M([])};return n&&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(Wt,{id:"select-level",style:{color:"var(--div-text-color)"},children:"Filter log by level:"}),e.jsxs(Ke,{style:{height:"30px",backgroundColor:"var(--main-bg-color)"},labelId:"select-level",id:"debug-level",value:r,onChange:L,children:[e.jsx(I,{value:"debug",children:"Debug"}),e.jsx(I,{value:"info",children:"Info"}),e.jsx(I,{value:"notice",children:"Notice"}),e.jsx(I,{value:"warn",children:"Warn"}),e.jsx(I,{value:"error",children:"Error"}),e.jsx(I,{value:"fatal",children:"Fatal"})]}),e.jsx(Wt,{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:C,InputProps:{style:{height:"30px",padding:"0 0px",backgroundColor:"var(--main-bg-color)"}}}),e.jsx(Re,{control:e.jsx(He,{checked:s,onChange:A}),label:"Auto scroll",style:{color:"var(--div-text-color)"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:e.jsx(R,{title:"Clear the logs",children:e.jsx(ie,{onClick:T,endIcon:e.jsx(ht,{}),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(Kt,{})})]}):e.jsx(Ae,{})}const Tn=o.memo(Wn),$n=({open:r,ip:u,onClose:a,onSave:i})=>{const s=u?u.split(".").slice(0,3).join(".")+".1":"",[v,M]=o.useState("dhcp"),[t,d]=o.useState({ip:u??"",subnet:"255.255.255.0",gateway:s,dns:s}),$=A=>T=>{d({...t,[A]:T.target.value})},L=()=>{a()},C=()=>{i({type:v,...t}),a()};return e.jsxs(Ne,{open:r,onClose:(A,T)=>{T==="backdropClick"||T==="escapeKeyDown"||a()},maxWidth:"sm",style:{maxWidth:"550px",margin:"auto"},children:[e.jsx(Fe,{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(Le,{dividers:!0,children:[e.jsxs(zt,{component:"fieldset",fullWidth:!0,children:[e.jsx(Me,{component:"legend",children:"Select IP Configuration"}),e.jsxs(Bt,{row:!0,value:v,onChange:A=>M(A.target.value),children:[e.jsx(Re,{value:"dhcp",control:e.jsx(ft,{}),label:"DHCP"}),e.jsx(Re,{value:"static",control:e.jsx(ft,{}),label:"Static"})]})]}),v==="static"&&e.jsxs($e,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx($e,{size:6,children:e.jsx(pe,{label:"IP Address",fullWidth:!0,value:t.ip,onChange:$("ip")})}),e.jsx($e,{size:6,children:e.jsx(pe,{label:"Subnet Mask",fullWidth:!0,value:t.subnet,onChange:$("subnet")})}),e.jsx($e,{size:6,children:e.jsx(pe,{label:"Gateway",fullWidth:!0,value:t.gateway,onChange:$("gateway")})}),e.jsx($e,{size:6,children:e.jsx(pe,{label:"DNS Server",fullWidth:!0,value:t.dns,onChange:$("dns")})})]})]}),e.jsxs(_e,{children:[e.jsx(ie,{onClick:L,children:"Cancel"}),e.jsx(ie,{variant:"contained",onClick:C,children:"Save"})]})]})},Rn=({open:r,onClose:u,onSave:a})=>{const[i,s]=o.useState(""),[v,M]=o.useState(""),t=T=>{s(T.target.value)},d=T=>{M(T.target.value)},$=i.length>0&&i===v,L=()=>{u()},C=()=>{$&&(a(i),u())},A=()=>{a(""),u()};return e.jsxs(Ne,{open:r,onClose:(T,W)=>{W==="backdropClick"||W==="escapeKeyDown"||u()},maxWidth:"sm",style:{maxWidth:"500px",margin:"auto"},disableEscapeKeyDown:!0,children:[e.jsx(Fe,{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(Le,{dividers:!0,children:e.jsx(zt,{component:"fieldset",fullWidth:!0,sx:{margin:0,padding:0,gap:"20px"},children:e.jsxs($e,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx($e,{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($e,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"Confirm Password",size:"small",variant:"outlined",fullWidth:!0,value:v,onChange:d,error:v!==""&&i!==v,helperText:v!==""&&i!==v?"Passwords do not match":""})})]})})}),e.jsxs(_e,{children:[e.jsx(ie,{onClick:L,children:"Cancel"}),e.jsx(ie,{variant:"contained",onClick:C,disabled:!$,children:"Change"}),e.jsx(ie,{variant:"contained",onClick:A,children:"Reset"})]})]})};function Hn(){const{online:r,addListener:u,removeListener:a,sendMessage:i,getUniqueId:s}=o.useContext(be),[v,M]=o.useState(null),[t,d]=o.useState(null),$=o.useRef(s());return o.useEffect(()=>{const L=C=>{C.src==="Matterbridge"&&C.dst==="Frontend"&&(ae(C)&&C.method==="refresh_required"&&C.params.changed==="settings"&&(n&&console.log(`Settings received refresh_required: changed=${C.params.changed} and sending /api/settings request`),i({id:$.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),ge(C)&&C.method==="/api/settings"&&(n&&console.log("Settings received /api/settings:",C.response),M(C.response.matterbridgeInformation),d(C.response.systemInformation)))};return u(L),n&&console.log("Settings added WebSocket listener"),()=>{a(L),n&&console.log("Settings removed WebSocket listener")}},[u,a,i]),o.useEffect(()=>{r&&(n&&console.log("Settings received online"),i({id:$.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[r,i]),v?(n&&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(On,{matterbridgeInfo:v,systemInfo:t}),e.jsx(En,{matterbridgeInfo:v}),e.jsx(_n,{matterbridgeInfo:v})]})}):e.jsx(Ae,{})):null}function On({matterbridgeInfo:r,systemInfo:u}){const{sendMessage:a,getUniqueId:i}=o.useContext(be),[s,v]=o.useState("bridge"),[M,t]=o.useState("Info"),[d,$]=o.useState(!1),[L,C]=o.useState("dark"),[A,T]=o.useState(localStorage.getItem("homePagePlugins")!=="false"),[W,_]=o.useState(localStorage.getItem("homePageMode")??"devices"),[m,E]=o.useState(localStorage.getItem("virtualMode")??"outlet"),b=o.useRef(i()),[f,y]=o.useState(!1),H=()=>y(!1),x=X=>{n&&console.log("handleSaveNetConfig called with config:",X),a({id:b.current,sender:"Settings",method:"/api/shellynetconfig",src:"Frontend",dst:"Matterbridge",params:X})},[w,z]=o.useState(!1),c=()=>z(!1),l=X=>{n&&console.log("handleSaveChangePassword called with password:",X),a({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setpassword",value:X}})};o.useEffect(()=>{r&&(v(r.bridgeMode==="bridge"?"bridge":"childbridge"),t(r.loggerLevel.charAt(0).toUpperCase()+r.loggerLevel.slice(1)),$(r.fileLogger),E(r.virtualMode))},[r]),o.useEffect(()=>{const X=localStorage.getItem("frontendTheme");X&&C(X)},[]);const g=X=>{n&&console.log("handleChangeBridgeMode called with value:",X.target.value),v(X.target.value),a({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setbridgemode",value:X.target.value}})},h=X=>{n&&console.log("handleChangeMbLoggerLevel called with value:",X.target.value),t(X.target.value),a({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmbloglevel",value:X.target.value}})},F=X=>{n&&console.log("handleLogOnFileMbChange called with value:",X.target.checked),$(X.target.checked),a({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmblogfile",value:X.target.checked}})},G=X=>{const se=X.target.value;n&&console.log("handleChangeTheme called with value:",se),C(se),localStorage.setItem("frontendTheme",se),document.body.setAttribute("frontend-theme",se)},ye=X=>{const se=X.target.checked;n&&console.log("handleChangeHomePagePlugins called with value:",se),T(se),localStorage.setItem("homePagePlugins",se?"true":"false")},xe=X=>{const se=X.target.value;n&&console.log("handleChangeHomePageMode called with value:",se),_(se),localStorage.setItem("homePageMode",se)},he=X=>{const se=X.target.value;n&&console.log("handleChangeVirtualMode called with value:",se),E(se),localStorage.setItem("virtualMode",se),a({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setvirtualmode",value:se}})};return!r||!u?null: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($n,{open:f,ip:u.ipv4Address,onClose:H,onSave:x}),e.jsx(Rn,{open:w,onClose:c,onSave:l}),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(Me,{style:{padding:"0px",margin:"0px"},id:"matterbridgeInfo-mode",children:"Matterbridge mode:"}),e.jsxs(Bt,{row:!0,name:"mode-buttons-group",value:s,onChange:g,children:[e.jsx(Re,{value:"bridge",control:e.jsx(ft,{}),label:"Bridge",disabled:r.readOnly===!0}),e.jsx(Re,{value:"childbridge",control:e.jsx(ft,{}),label:"Childbridge",disabled:r.readOnly===!0})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Me,{style:{padding:"0px",margin:"0px"},id:"mblogger-level-label",children:"Logger level:"}),e.jsxs(Ke,{style:{height:"30px"},labelId:"mblogger-level-label",id:"mblogger-level",value:M,onChange:h,children:[e.jsx(I,{value:"Debug",children:"Debug"}),e.jsx(I,{value:"Info",children:"Info"}),e.jsx(I,{value:"Notice",children:"Notice"}),e.jsx(I,{value:"Warn",children:"Warn"}),e.jsx(I,{value:"Error",children:"Error"}),e.jsx(I,{value:"Fatal",children:"Fatal"})]}),e.jsx(Re,{style:{padding:"0px",margin:"0px"},control:e.jsx(He,{checked:d,onChange:F,name:"logOnFileMb"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Me,{style:{padding:"0px",margin:"0px"},id:"frontend-theme-label",children:"Frontend theme:"}),e.jsxs(Ke,{style:{height:"30px"},labelId:"frontend-theme-label",id:"frontend-theme",value:L,onChange:G,children:[e.jsx(I,{value:"classic",children:"Classic"}),e.jsx(I,{value:"light",children:"Light"}),e.jsx(I,{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Me,{style:{padding:"0px",margin:"0px"},id:"frontend-home-plugin-label",children:"Home page plugins:"}),e.jsx(He,{checked:A,onChange:ye,name:"showPlugins"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Me,{style:{padding:"0px",margin:"0px"},id:"frontend-home-label",children:"Home page bottom panel:"}),e.jsxs(Ke,{style:{height:"30px"},labelId:"frontend-home-label",id:"frontend-home",value:W,onChange:xe,children:[e.jsx(I,{value:"logs",children:"Logs"}),e.jsx(I,{value:"devices",children:"Devices"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"10px"},children:[e.jsx(Me,{style:{padding:"0px",margin:"0px"},id:"frontend-virtual-label",children:"Virtual devices:"}),e.jsxs(Ke,{style:{height:"30px"},labelId:"frontend-virtual-label",id:"frontend-virtual",value:m,onChange:he,children:[e.jsx(I,{value:"disabled",children:"Disabled"}),e.jsx(I,{value:"outlet",children:"Outlet"}),e.jsx(I,{value:"light",children:"Light"}),e.jsx(I,{value:"switch",children:"Switch"}),e.jsx(I,{value:"mounted_switch",children:"Mounted Switch"})]})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ie,{variant:"contained",color:"primary",onClick:()=>z(!0),children:"Change password"})}),r.shellyBoard&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ie,{variant:"contained",color:"primary",onClick:()=>y(!0),children:"Configure IP"})})]})})]})}function En({matterbridgeInfo:r}){const{sendMessage:u,getUniqueId:a}=o.useContext(be),[i,s]=o.useState("Info"),[v,M]=o.useState(!1),[t,d]=o.useState(""),[$,L]=o.useState(""),[C,A]=o.useState(""),[T,W]=o.useState(""),[_,m]=o.useState(""),[E,b]=o.useState(""),f=o.useRef(a());o.useEffect(()=>{r&&(s(["Debug","Info","Notice","Warn","Error","Fatal"][r.matterLoggerLevel]),M(r.matterFileLogger),d(r.matterMdnsInterface||""),L(r.matterIpv4Address||""),A(r.matterIpv6Address||""),W(r.matterPort?r.matterPort.toString():""),m(r.matterDiscriminator?r.matterDiscriminator.toString():""),b(r.matterPasscode?r.matterPasscode.toString():""))},[r]);const y=h=>{n&&console.log("handleChangeMjLoggerLevel called with value:",h.target.value),s(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjloglevel",value:h.target.value}})},H=h=>{n&&console.log("handleLogOnFileMjChange called with value:",h.target.checked),M(h.target.checked),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjlogfile",value:h.target.checked}})},x=h=>{n&&console.log("handleChangeMdnsInterface called with value:",h.target.value),d(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmdnsinterface",value:h.target.value}})},w=h=>{n&&console.log("handleChangeIpv4Address called with value:",h.target.value),L(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv4address",value:h.target.value}})},z=h=>{n&&console.log("handleChangeIpv6Address called with value:",h.target.value),A(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv6address",value:h.target.value}})},c=h=>{n&&console.log("handleChangeMatterPort called with value:",h.target.value),W(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterport",value:h.target.value}})},l=h=>{n&&console.log("handleChangeMatterDiscriminator called with value:",h.target.value),m(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterdiscriminator",value:h.target.value}})},g=h=>{n&&console.log("handleChangemMatterPasscode called with value:",h.target.value),b(h.target.value),u({id:f.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterpasscode",value:h.target.value}})};return r?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(Me,{style:{padding:"0px",margin:"0px"},id:"mjdebug-info",children:"Logger level:"}),e.jsxs(Ke,{style:{height:"30px"},labelId:"select-mjlevel",id:"mjdebug-level",value:i,onChange:y,children:[e.jsx(I,{value:"Debug",children:"Debug"}),e.jsx(I,{value:"Info",children:"Info"}),e.jsx(I,{value:"Notice",children:"Notice"}),e.jsx(I,{value:"Warn",children:"Warn"}),e.jsx(I,{value:"Error",children:"Error"}),e.jsx(I,{value:"Fatal",children:"Fatal"})]}),e.jsx(Re,{style:{padding:"0px",margin:"0px"},control:e.jsx(He,{checked:v,onChange:H,name:"logOnFileMj"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Me,{style:{padding:"0px",margin:"0px"},children:"Mdns interface:"}),e.jsx(pe,{value:t,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(Me,{style:{padding:"0px",margin:"0px"},children:"Ipv4 address:"}),e.jsx(pe,{value:$,onChange:w,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(Me,{style:{padding:"0px",margin:"0px"},children:"Ipv6 address:"}),e.jsx(pe,{value:C,onChange:z,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(Me,{style:{padding:"0px",margin:"0px"},children:"Commissioning port:"}),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(Me,{style:{padding:"0px",margin:"0px"},children:"Commissioning discriminator:"}),e.jsx(pe,{value:_,onChange:l,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(Me,{style:{padding:"0px",margin:"0px"},children:"Commissioning passcode:"}),e.jsx(pe,{value:E,onChange:g,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:r.readOnly===!0,style:{height:"30px",padding:"0"}}})]})]})})]}):null}function _n({matterbridgeInfo:r}){return r?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(Ee,{value:r.matterbridgeVersion,label:"Current Version"}),e.jsx(Ee,{value:r.matterbridgeLatestVersion,label:"Latest Version"}),e.jsx(Ee,{value:r.homeDirectory,label:"Home Directory"}),e.jsx(Ee,{value:r.rootDirectory,label:"Root Directory"}),e.jsx(Ee,{value:r.matterbridgeDirectory,label:"Matterbridge Storage Directory"}),e.jsx(Ee,{value:r.matterbridgePluginDirectory,label:"Matterbridge Plugin Directory"}),e.jsx(Ee,{value:r.globalModulesDirectory,label:"Global Module Directory"})]})})]}):null}function Ee({value:r,label:u}){return e.jsx(pe,{focused:!0,value:r,size:"small",label:u,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)"}}}})}const An=o.memo(Hn);function Vn(){const{online:r,sendMessage:u,addListener:a,removeListener:i,getUniqueId:s}=o.useContext(be),{showSnackbarMessage:v}=o.useContext(Je),[M,t]=o.useState(null),[d,$]=o.useState([]),[L,C]=o.useState([]),[A,T]=o.useState(null),[W,_]=o.useState({cpuUsage:0}),[m,E]=o.useState({totalMemory:"",freeMemory:"",heapTotal:"",heapUsed:"",external:"",arrayBuffers:"",rss:""}),[b,f]=o.useState({systemUptime:"",processUptime:""}),y=o.useRef(s());return console.log("Test uniqueId:",y),o.useEffect(()=>{console.log("Test useEffect WebSocketMessage mounting");const H=x=>{if(x.src==="Matterbridge"&&x.dst==="Frontend"){if(ae(x)&&x.method==="restart_required"&&(console.log("Test received restart_required"),v("Restart required",0)),ae(x)&&x.method==="refresh_required"&&(console.log(`Test received refresh_required: changed=${x.params.changed} and sending api requests`),v("Refresh required",0),u({id:y.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:y.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:y.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),ae(x)&&x.method==="memory_update"&&(console.log("Test received memory_update",x),E(x.params)),ae(x)&&x.method==="cpu_update"&&(console.log("Test received cpu_update",x),_(x.params)),ae(x)&&x.method==="uptime_update"&&(console.log("Test received uptime_update",x),f(x.params)),ge(x)&&x.method==="/api/settings"&&x.response&&(console.log("Test received /api/settings:",x.response),v("Test received /api/settings",0),t(x.response)),ge(x)&&x.method==="/api/plugins"&&x.response&&(console.log(`Test received ${x.response.length} plugins:`,x.response),v("Test received /api/plugins",0),$(x.response)),ge(x)&&x.method==="/api/devices"&&x.response){console.log(`Test received ${x.response.length} devices:`,x.response),v("Test received /api/devices",0),C(x.response);for(const w of x.response)console.log("Test sending /api/clusters for device:",w.pluginName,w.name,w.endpoint),u({id:y.current,method:"/api/clusters",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{plugin:w.pluginName,endpoint:w.endpoint||0}})}ge(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),v(`Test received /api/clusters for ${x.response.plugin}::${x.response.deviceName}`,0),T(x.response))}};return a(H),console.log("Test useEffect WebSocketMessage mounted"),()=>{console.log("Test useEffect WebSocketMessage unmounting"),i(H),console.log("Test useEffect WebSocketMessage unmounted")}},[a,i,u,v]),o.useEffect(()=>(console.log("Test useEffect online mounting"),r&&(console.log("Test useEffect online received online"),u({id:y.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:y.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:y.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),console.log("Test useEffect online mounted"),()=>{console.log("Test useEffect online unmounted")}),[r,u,v]),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(Ae,{})}const Un=o.memo(Vn);function qn(r,u){n&&console.log("getCssVariable:",r,"defaultValue",u);const a=getComputedStyle(document.body).getPropertyValue(r).trim();return a||console.error("getCssVariable: undefined",a),a||u}function zn(r){return to({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 n=!1;const Bn=()=>{n=!n};function Qn({setLoggedIn:r}){const[u,a]=o.useState(""),[i,s]=o.useState(""),v={display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",backgroundColor:"var(--main-bg-color)"},M={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)"},t={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)"},d=async L=>{try{const C=await fetch("./api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:L})});if(C.ok){const{valid:A}=await C.json();A?r(!0):L!==""&&s("Incorrect password!")}else console.error("Failed to log in:",C.statusText)}catch(C){console.error("Failed to log in:",C)}},$=L=>{L.preventDefault(),d(u)};return d(""),e.jsx("div",{style:v,children:e.jsxs("form",{onSubmit:$,style:M,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:u,onChange:L=>a(L.target.value),style:t,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:i&&e.jsx("p",{style:{color:"red"},children:i})})]})})}function Kn(){const[r,u]=o.useState(!1);n&&console.log("Setting frontend theme");const a=localStorage.getItem("frontendTheme");n&&console.log("Saved theme:",a),a?document.body.setAttribute("frontend-theme",a):document.body.setAttribute("frontend-theme","dark");const i=qn("--primary-color","#1976d2");n&&console.log("Primary color from CSS:",i);const s=zn(i),v=window.location.pathname.includes("/matterbridge/")?"/matterbridge":window.location.href.includes("/api/hassio_ingress/")?window.location.pathname:"/";return n&&(console.log("Loading App..."),console.log("- production mode"),console.log(`- with href = "${window.location.href}"`),console.log(`- pathname = "${window.location.pathname}"`),console.log(`- baseName = "${v}"`)),r?e.jsx(ro,{theme:s,children:e.jsx(ur,{dense:!0,maxSnack:10,preventDuplicate:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Oo,{children:e.jsx(Eo,{children:e.jsx(ar,{basename:v,children:e.jsxs("div",{className:"MbfScreen",children:[e.jsx(Ao,{}),e.jsxs(sr,{children:[e.jsx(Ve,{path:"/",element:e.jsx(un,{})}),e.jsx(Ve,{path:"/devices",element:e.jsx(Ln,{})}),e.jsx(Ve,{path:"/log",element:e.jsx(Tn,{})}),e.jsx(Ve,{path:"/settings",element:e.jsx(An,{})}),e.jsx(Ve,{path:"/test",element:e.jsx(Un,{})}),e.jsx(Ve,{path:"*",element:e.jsx(lr,{to:"/"})})]})]})})})})})}):e.jsx(Qn,{setLoggedIn:u})}dr.createRoot(document.getElementById("root")).render(e.jsx(cr.StrictMode,{children:e.jsx(Kn,{})}));
|
|
1
|
+
import{B as e,y as r,Q as Xe,S as nr,U as ir,V as Ve,X as sr,Y as ar,H as lr}from"./vendor_node_modules.js";import{u as dr,S as cr}from"./vendor_notistack.js";import{D as Ie,a as De,b as Ne,B as ae,c as Y,A as pr,I as Q,C as ur,T,S as mr,F as Vt,H as gr,d as Et,e as We,R as dt,P as Re,M as hr,f as ze,g as I,L as z,h as te,i as Ze,V as et,j as Se,k as ht,l as fr,m as xr,n as de,o as br,p as vr,q as ct,r as se,s as Te,K as St,t as Mt,u as ut,v as tt,w as Je,x as rt,W as Ge,y as ot,z as nt,E as Oe,G as kt,J as It,N as yr,O as jr,Q as Cr,U as Fe,X as At,Y as vt,Z as wr,_ as Sr,$ as Mr,a0 as kr,a1 as _t,a2 as pt,a3 as Ir,a4 as Dr,a5 as Nr,a6 as Pr,a7 as Dt,a8 as Wr,a9 as Lr,aa as Fr,ab as Tr,ac as $r,ad as Rr,ae as Hr,af as Nt,ag as Or,ah as Vr,ai as Er,aj as Ar,ak as _r,al as qr,am as zr,an as Ur,ao as Br,ap as Qr,aq as Kr,ar as Jr,as as Gr,at as Yr,au as Xr,av as Pt,aw as Ue,ax as qt,ay as be,az as zt,aA as mt,aB as Le,aC as Zr,aD as eo}from"./vendor_mui.js";import{Q as to}from"./vendor_qrcode.js";import{I as re,m as Wt,a as ro,b as oo,c as Lt,d as no,e as io,f as so,g as ao,h as lo,i as co,j as po,k as uo,l as mo,n as go,o as ho,p as fo,q as Ft,r as xo,s as bo,t as vo,u as yo,v as jo,w as Co,x as wo,y as So,z as Tt,A as Mo,B as ko}from"./vendor_mdi.js";import{F as Io,v as Do,e as No,a as Po,g as Wo,b as Lo,c as Fo,d as ft,A as To}from"./vendor_rjsf.js";import"./vendor_lodash.js";import"./vendor_emotion.js";(function(){const u=document.createElement("link").relList;if(u&&u.supports&&u.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))o(l);new MutationObserver(l=>{for(const y of l)if(y.type==="childList")for(const g of y.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&o(g)}).observe(document,{childList:!0,subtree:!0});function c(l){const y={};return l.integrity&&(y.integrity=l.integrity),l.referrerPolicy&&(y.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?y.credentials="include":l.crossOrigin==="anonymous"?y.credentials="omit":y.credentials="same-origin",y}function o(l){if(l.ep)return;l.ep=!0;const y=c(l);fetch(l.href,y)}})();function $o({open:i,title:u,message:c,onConfirm:o,onCancel:l}){const y=t=>{n&&console.log("Confirmed"),t.preventDefault(),o()},g=t=>{n&&console.log("Canceled"),t.preventDefault(),l()};return e.jsxs(Ie,{open:i,children:[e.jsx(De,{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:u})]})}),e.jsxs(Ne,{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:c})}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-around"},children:[e.jsx(ae,{onClick:y,variant:"contained",color:"primary",size:"small",children:"Confirm"}),e.jsx(ae,{onClick:g,variant:"contained",color:"primary",size:"small",children:"Cancel"})]})]})]})}const it=[],Be=r.createContext(null);function Ro({children:i}){const{enqueueSnackbar:u,closeSnackbar:c}=dr(),o=r.useCallback(v=>{n&&console.log(`UiProvider closeSnackbarMessage: message ${v}`);const w=it.findIndex(F=>F.message===v);w!==-1&&(c(it[w].key),it.splice(w,1),n&&console.log(`UiProvider closeSnackbarMessage: message ${v} removed from persistMessages`))},[c]),l=r.useCallback((v,w,F)=>{n&&console.log(`UiProvider showSnackbarMessage: message ${v} timeout ${w}`);const C=u(v,{variant:"default",autoHideDuration:w==null||w>0?(w??5)*1e3:null,persist:w===0,content:G=>e.jsx(Y,{sx:{margin:"0",padding:"0",width:"300px",marginRight:"30px"},children:e.jsx(pr,{severity:F??"info",variant:"filled",sx:{color:"#fff",fontWeight:"normal",width:"100%",cursor:"pointer",padding:"0px 10px"},onClick:()=>c(G),action:e.jsx(Q,{size:"small",onClick:()=>c(G),sx:{color:"#fff"},children:e.jsx(ur,{fontSize:"small"})}),children:v},G)},G)});w===0&&(n&&console.log(`UiProvider showSnackbarMessage: message ${v} timeout ${w} - persist key ${C}`),it.push({message:v,key:C}))},[u,c]),[y,g]=r.useState(!1),[t,x]=r.useState(""),[N,p]=r.useState(""),[j,O]=r.useState(""),$=r.useRef(null),P=r.useRef(null),U=()=>{n&&console.log(`UiProvider handle confirm action ${j}`),g(!1),$.current&&$.current(j)},h=()=>{n&&console.log(`UiProvider handle cancel action ${j}`),g(!1),P.current&&P.current(j)},V=r.useCallback((v,w,F,C,G)=>{n&&console.log(`UiProvider showConfirmCancelDialog for command ${F}`),x(v),p(w),O(F),$.current=C,P.current=G,g(!0)},[]),b=r.useMemo(()=>({showSnackbarMessage:l,closeSnackbarMessage:o,closeSnackbar:c,showConfirmCancelDialog:V}),[l,o,c,V]);return e.jsxs(Be.Provider,{value:b,children:[e.jsx($o,{open:y,title:t,message:N,onConfirm:U,onCancel:h}),i]})}const Ut=r.createContext(null),ge=r.createContext(null);function Ho({children:i}){const[u,c]=r.useState(localStorage.getItem("logFilterLevel")??"info"),[o,l]=r.useState(localStorage.getItem("logFilterSearch")??"*"),[y,g]=r.useState([]),[t,x]=r.useState(1e3),[N,p]=r.useState(!0),[j,O]=r.useState(!1),{showSnackbarMessage:$,closeSnackbarMessage:P,closeSnackbar:U}=r.useContext(Be),h=r.useRef([]),V=r.useRef(null),b=r.useRef(1),v=r.useRef(Math.floor(Math.random()*999e3)+1e3),w=r.useRef(null),F=r.useRef(null),C=r.useRef(null),G=r.useRef(u),A=r.useRef(o),a=r.useRef(0),s=r.useRef(null),d=r.useMemo(()=>window.location.href.replace(/^http/,"ws"),[]),m=r.useMemo(()=>window.location.href.includes("api/hassio_ingress"),[]),R=100,pe=60,Ce=50,we=300,ye=10;r.useEffect(()=>(n&&console.log("WebSocket messages started counter interval"),s.current=setInterval(()=>{a.current>0&&(n&&console.log(`WebSocket messages received in the last ${ye} seconds: ${a.current*(60/ye)} messages/minute`),a.current=0)},ye*1e3),()=>{n&&console.log("WebSocket messages stopped counter interval"),s.current&&clearInterval(s.current),s.current=null}),[]),r.useEffect(()=>{G.current=u},[u]),r.useEffect(()=>{A.current=o},[o]);const X=r.useCallback(()=>Math.floor(Math.random()*999e3)+1e3,[]),ie=r.useCallback(K=>{if(V.current&&V.current.readyState===WebSocket.OPEN)try{n&&console.log(`WebSocket sending message with id ${K.id}:`,K),K.id===void 0&&(K.id=v.current);const f=JSON.stringify(K);V.current.send(f),n&&console.log("WebSocket sent message:",K)}catch(f){n&&console.error(`WebSocket error sending message: ${f}`)}else n&&console.error("WebSocket message not sent, WebSocket not connected:",K)},[]),M=r.useCallback((K,f)=>{g(ne=>[...ne,{level:K,time:"",name:"",message:f}])},[]),E=r.useCallback((K,f)=>{c(K),l(f),M("WebSocket",`Filtering by log level "${K}" and log search "${f}"`)},[M]),W=r.useCallback((K,f)=>{n&&console.log(`WebSocket addListener id ${f}:`,K),(f==null||isNaN(f)||f===0)&&console.error("WebSocket addListener called without id, listener not added:",K),h.current=[...h.current,{listener:K,id:f}],n&&console.log("WebSocket addListener total listeners:",h.current.length)},[]),D=r.useCallback(K=>{n&&console.log("WebSocket removeListener:",K),h.current=h.current.filter(f=>f.listener!==K),n&&console.log("WebSocket removeListener total listeners:",h.current.length)},[]),S=r.useCallback(()=>{d===""||d===null||d===void 0||(M("WebSocket",`Connecting to WebSocket: ${d}`),V.current=new WebSocket(d),V.current.onmessage=K=>{j||O(!0),a.current+=1;try{const f=JSON.parse(K.data);if(f.id===void 0||f.src===void 0||f.dst===void 0){n&&console.error("WebSocket undefined message id/src/dst:",f);return}if(f.src!=="Matterbridge"||f.dst!=="Frontend"){n&&console.error("WebSocket invalid message src/dst:",f);return}if(f.error){n&&console.error("WebSocket error message response:",f);return}if(f.id===v.current&&f.method==="pong"&&f.response==="pong"){n&&console.log(`WebSocket pong response message id ${f.id}:`,f),F.current&&clearTimeout(F.current),F.current=null;return}else if(f.method==="snackbar"&&f.response&&f.response.message){n&&console.log(`WebSocket message id ${f.id} method ${f.method}:`,f),$(f.response.message,f.response.timeout,f.response.severity);return}else if(f.method==="close_snackbar"&&f.response&&f.response.message){n&&console.log(`WebSocket message id ${f.id} method ${f.method}:`,f),P(f.response.message);return}else if(f.method==="log"){if(!f.response||!f.response.level||!f.response.time||!f.response.name||!f.response.message||["debug","info","notice","warn","error","fatal"].includes(f.response.level)&&(G.current==="info"&&f.response.level==="debug"||G.current==="notice"&&(f.response.level==="debug"||f.response.level==="info")||G.current==="warn"&&(f.response.level==="debug"||f.response.level==="info"||f.response.level==="notice")||G.current==="error"&&(f.response.level==="debug"||f.response.level==="info"||f.response.level==="notice"||f.response.level==="warn")||G.current==="fatal"&&(f.response.level==="debug"||f.response.level==="info"||f.response.level==="notice"||f.response.level==="warn"||f.response.level==="error"))||A.current!=="*"&&A.current!==""&&!f.response.message.toLowerCase().includes(A.current.toLowerCase())&&!f.response.name.toLowerCase().includes(A.current.toLowerCase())||f.response.name==="Commissioning"&&f.response.message.includes("is uncommissioned"))return;g(H=>{const oe=[...H,{level:f.response.level,time:f.response.time,name:f.response.name,message:f.response.message}];return oe.length>t*2?oe.slice(t):oe})}else{if(n&&console.log(`WebSocket received message id ${f.id} method ${f.method}:`,f),f.id===0)h.current.forEach(ne=>ne.listener(f));else{const ne=h.current.find(H=>H.id===f.id);ne?ne.listener(f):n&&console.debug(`WebSocket no listener found for message id ${f.id}:`,f)}return}}catch(f){console.error(`WebSocketUse error parsing message: ${f}`)}},V.current.onopen=()=>{n&&console.log(`WebSocket: Connected to WebSocket: ${d}`),M("WebSocket",`Connected to WebSocket: ${d}`),O(!0),U(),b.current=1,C.current=setTimeout(()=>{w.current=setInterval(()=>{ie({id:v.current,method:"ping",src:"Frontend",dst:"Matterbridge",params:{}}),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{n&&console.error(`WebSocketUse: No pong response received from WebSocket: ${d}`),M("WebSocket",`No pong response received from WebSocket: ${d}`),O(!1)},1e3*Ce)},1e3*pe)},1e3*we)},V.current.onclose=()=>{n&&console.error(`WebSocket: Disconnected from WebSocket ${m?"with Ingress":""}: ${d}`),M("WebSocket",`Disconnected from WebSocket: ${d}`),O(!1),U(),C.current&&clearTimeout(C.current),F.current&&clearTimeout(F.current),w.current&&clearInterval(w.current),M("WebSocket",`Reconnecting (attempt ${b.current} of ${R}) to WebSocket${m?" (Ingress)":""}: ${d}`),m?setTimeout(L,5e3):b.current===1?L():b.current<R?setTimeout(L,1e3*b.current):M("WebSocket",`Reconnect attempts exceeded limit of ${R} retries, refresh the page to reconnect to: ${d}`),b.current=b.current+1},V.current.onerror=K=>{n&&console.error(`WebSocket: WebSocket error connecting to ${d}:`,K),M("WebSocket",`WebSocket error connecting to ${d}`)})},[d]),L=r.useCallback(()=>{n&&console.log(`WebSocket attemptReconnect ${b.current}/${R} to:`,d),S()},[S]);r.useEffect(()=>(S(),()=>{V.current&&V.current.readyState===WebSocket.OPEN&&V.current.close()}),[S]);const _=r.useMemo(()=>({messages:y,maxMessages:t,autoScroll:N,setMessages:g,setLogFilters:E,setMaxMessages:x,setAutoScroll:p}),[y,g,E]),Z=r.useMemo(()=>({maxMessages:t,autoScroll:N,logFilterLevel:u,logFilterSearch:o,setMessages:g,setLogFilters:E,setMaxMessages:x,setAutoScroll:p,online:j,retry:b.current,getUniqueId:X,addListener:W,removeListener:D,sendMessage:ie,logMessage:M}),[t,N,g,E,x,p,j,b.current,W,D,ie,M]);return e.jsx(Ut.Provider,{value:_,children:e.jsx(ge.Provider,{value:Z,children:i})})}function Oo(){const{showSnackbarMessage:i,showConfirmCancelDialog:u}=r.useContext(Be),{online:c,sendMessage:o,logMessage:l,addListener:y,removeListener:g,getUniqueId:t}=r.useContext(ge),[x,N]=r.useState(!1),[p,j]=r.useState(!1),[O,$]=r.useState(!1),[P,U]=r.useState(!1),[h,V]=r.useState(null),b=r.useRef(t()),[v,w]=r.useState(null),[F,C]=r.useState(null),[G,A]=r.useState(null),[a,s]=r.useState(null),[d,m]=r.useState(null),R=()=>{window.open("https://www.buymeacoffee.com/luligugithub","_blank")},pe=()=>{window.open("https://github.com/Luligu/matterbridge/blob/main/README.md","_blank")},Ce=()=>{h?.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")},we=()=>{window.open("https://discord.gg/QX58CDe6hd","_blank")},ye=()=>{window.open("https://github.com/Luligu/matterbridge","_blank")},X=()=>{o({id:b.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge",restart:!0}})},ie=()=>{o({id:b.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge@dev",restart:!0}})},M=()=>{o({id:b.current,sender:"Header",method:"/api/checkupdates",src:"Frontend",dst:"Matterbridge",params:{}})},E=()=>{n&&console.log("Header: handleShellySystemUpdateClick"),l("Matterbridge","Installing system updates..."),o({id:b.current,sender:"Header",method:"/api/shellysysupdate",src:"Frontend",dst:"Matterbridge",params:{}})},W=()=>{n&&console.log("Header: handleShellyMainUpdateClick"),l("Matterbridge","Installing software updates..."),o({id:b.current,sender:"Header",method:"/api/shellymainupdate",src:"Frontend",dst:"Matterbridge",params:{}})},D=()=>{n&&console.log("Header: handleShellyCreateSystemLog"),o({id:b.current,sender:"Header",method:"/api/shellycreatesystemlog",src:"Frontend",dst:"Matterbridge",params:{}})},S=()=>{n&&console.log("Header: handleShellyDownloadSystemLog"),l("Matterbridge","Downloading Shelly system log..."),i("Downloading Shelly system log...",5),window.location.href="./api/shellydownloadsystemlog"},L=()=>{h?.matterbridgeInformation.restartMode===""?o({id:b.current,sender:"Header",method:"/api/restart",src:"Frontend",dst:"Matterbridge",params:{}}):o({id:b.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},_=()=>{o({id:b.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},Z=()=>{o({id:b.current,sender:"Header",method:"/api/reboot",src:"Frontend",dst:"Matterbridge",params:{}})},K=()=>{o({id:b.current,sender:"Header",method:"/api/softreset",src:"Frontend",dst:"Matterbridge",params:{}})},f=()=>{o({id:b.current,sender:"Header",method:"/api/hardreset",src:"Frontend",dst:"Matterbridge",params:{}})},ne=B=>{w(B.currentTarget)},H=B=>{n&&console.log("Header: handleMenuClose",B),w(null),B==="download-mblog"?(l("Matterbridge","Downloading matterbridge log..."),i("Downloading matterbridge log...",5),window.location.href="./api/download-mblog"):B==="download-mjlog"?(l("Matterbridge","Downloading matter log..."),i("Downloading matter log...",5),window.location.href="./api/download-mjlog"):B==="view-mblog"?(l("Matterbridge","Loading matterbridge log..."),i("Loading matterbridge log...",5),window.location.href="./api/view-mblog"):B==="view-mjlog"?(l("Matterbridge","Loading matter log..."),i("Loading matter log...",5),window.location.href="./api/view-mjlog"):B==="view-shellylog"?(l("Matterbridge","Loading shelly system log..."),i("Loading shelly system log...",5),window.location.href="./api/shellyviewsystemlog"):B==="download-mbstorage"?(l("Matterbridge","Downloading matterbridge storage..."),i("Downloading matterbridge storage...",5),window.location.href="./api/download-mbstorage"):B==="download-pluginstorage"?(l("Matterbridge","Downloading matterbridge plugins storage..."),i("Downloading matterbridge plugins storage...",5),window.location.href="./api/download-pluginstorage"):B==="download-pluginconfig"?(l("Matterbridge","Downloading matterbridge plugins config..."),i("Downloading matterbridge plugins config...",5),window.location.href="./api/download-pluginconfig"):B==="download-mjstorage"?(l("Matterbridge","Downloading matter storage..."),i("Downloading matter storage...",5),window.location.href="./api/download-mjstorage"):B==="download-backup"?(l("Matterbridge","Downloading backup..."),i("Downloading backup...",10),window.location.href="./api/download-backup"):B==="update"?X():B==="updatedev"?ie():B==="updatecheck"?M():B==="shelly-sys-update"?E():B==="shelly-main-update"?W():B==="shelly-create-system-log"?D():B==="shelly-download-system-log"?S():B==="softreset"?K():B==="hardreset"?f():B==="restart"?L():B==="shutdown"?_():B==="reboot"?Z():B==="create-backup"?o({id:b.current,sender:"Header",method:"/api/create-backup",src:"Frontend",dst:"Matterbridge",params:{}}):B==="unregister"?o({id:b.current,sender:"Header",method:"/api/unregister",src:"Frontend",dst:"Matterbridge",params:{}}):B==="reset"?o({id:b.current,sender:"Header",method:"/api/reset",src:"Frontend",dst:"Matterbridge",params:{}}):B==="factoryreset"&&o({id:b.current,sender:"Header",method:"/api/factoryreset",src:"Frontend",dst:"Matterbridge",params:{}})},oe=B=>{n&&console.log("Header: handleMenuCloseCancel:",B),w(null)},ue=B=>{C(B.currentTarget)},ee=()=>{C(null)},je=B=>{A(B.currentTarget)},xe=()=>{A(null)},me=B=>{s(B.currentTarget)},J=()=>{s(null)},le=B=>{m(B.currentTarget)},fe=()=>{m(null)},Qe=()=>{Bn(),n&&console.log("Matterbridge logo clicked: debug is now",n)};return r.useEffect(()=>{const B=k=>{n&&console.log("Header received WebSocket Message:",k),k.method==="/api/settings"&&k.id===b.current?(n&&console.log("Header received settings:",k.response),V(k.response),N(k.response.matterbridgeInformation.restartRequired||k.response.matterbridgeInformation.fixedRestartRequired),j(k.response.matterbridgeInformation.fixedRestartRequired),$(k.response.matterbridgeInformation.updateRequired)):k.method==="refresh_required"&&k.response.changed==="settings"?(n&&console.log(`Header received refresh_required: changed=${k.response.changed} and sending /api/settings request`),o({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})):k.method==="restart_required"?(n&&console.log(`Header received restart_required with fixed: ${k.response.fixed}`),N(!0),k.response.fixed===!0&&j(!0)):k.method==="restart_not_required"?(n&&console.log("Header received restart_not_required"),N(!1)):k.method==="update_required"?(n&&console.log("Header received update_required"),k.response.devVersion===!0?U(!0):$(!0),o({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})):k.method==="shelly_sys_update"?(n&&console.log("Header received WS_ID_SHELLY_SYS_UPDATE:"),V(ce=>ce?{matterbridgeInformation:{...ce.matterbridgeInformation,shellySysUpdate:k.response.available},systemInformation:ce.systemInformation}:null)):k.method==="shelly_main_update"&&(n&&console.log("Header received WS_ID_SHELLY_MAIN_UPDATE:"),V(ce=>ce?{matterbridgeInformation:{...ce.matterbridgeInformation,shellyMainUpdate:k.response.available},systemInformation:ce.systemInformation}:null))};return y(B,b.current),n&&console.log(`Header added WebSocket listener id ${b.current}`),()=>{g(B),n&&console.log("Header removed WebSocket listener")}},[y,g,o,i]),r.useEffect(()=>{c&&(n&&console.log("Header sending /api/settings requests"),o({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,o]),n&&console.log("Header rendering..."),!c||!h?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:Qe}),e.jsx("h2",{style:{fontSize:"22px",color:"var(--main-icon-color)",margin:"0px"},children:"Matterbridge"}),e.jsxs("nav",{children:[e.jsx(Xe,{to:"/",className:"nav-link",children:"Home"}),e.jsx(Xe,{to:"/devices",className:"nav-link",children:"Devices"}),e.jsx(Xe,{to:"/log",className:"nav-link",children:"Logs"}),e.jsx(Xe,{to:"/settings",className:"nav-link",children:"Settings"})]})]}),e.jsxs("div",{className:"sub-header",children:[!h.matterbridgeInformation.readOnly&&O&&e.jsx(T,{title:"New Matterbridge version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:X,children:["Update to v.",h.matterbridgeInformation.matterbridgeLatestVersion]})}),!h.matterbridgeInformation.readOnly&&P&&e.jsx(T,{title:"New Matterbridge dev version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:ie,children:["Update to new dev v.",h.matterbridgeInformation.matterbridgeDevVersion.split("-dev-")[0]]})}),!h.matterbridgeInformation.readOnly&&e.jsx(T,{title:"Matterbridge version, click to see the changelog",children:e.jsxs("span",{className:"status-information",onClick:Ce,children:["v.",h.matterbridgeInformation.matterbridgeVersion]})}),h.matterbridgeInformation.shellyBoard&&e.jsx("img",{src:"Shelly.svg",alt:"Shelly Icon",style:{height:"30px",padding:"0px",margin:"0px",marginRight:"30px"}}),h.matterbridgeInformation.bridgeMode!==""&&h.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Bridge mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:h.matterbridgeInformation.bridgeMode})}):null,h.matterbridgeInformation.restartMode!==""&&h.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Restart mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:h.matterbridgeInformation.restartMode})}):null,h.matterbridgeInformation.profile&&h.matterbridgeInformation.profile!==""&&h.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Current profile",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:h.matterbridgeInformation.profile})}):null]}),e.jsxs("div",{className:"sub-header",style:{gap:"5px"},children:[h.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Matterbridge discord group",children:e.jsx("img",{src:"discord.svg",alt:"Discord Logo",style:{cursor:"pointer",height:"25px"},onClick:we})}):null,h.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Give a star to Matterbridge",children:e.jsx(Q,{style:{color:"#FFD700",margin:"0",padding:"0"},onClick:ye,children:e.jsx(mr,{})})}):null,h.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Sponsor Matterbridge",children:e.jsx(Q,{style:{color:"#b6409c",margin:"0",padding:"0"},onClick:R,children:e.jsx(Vt,{})})}):null,e.jsx(T,{title:"Matterbridge help",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:pe,children:e.jsx(gr,{})})}),e.jsx(T,{title:"Matterbridge changelog",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:Ce,children:e.jsx(Et,{})})}),h.matterbridgeInformation&&!h.matterbridgeInformation.readOnly&&e.jsx(T,{title:"Update matterbridge to latest version",children:e.jsx(Q,{style:{color:O?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:X,children:e.jsx(We,{})})}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&h.matterbridgeInformation.shellySysUpdate&&e.jsx(T,{title:"Shelly system update",children:e.jsx(Q,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:E,children:e.jsx(We,{})})}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&h.matterbridgeInformation.shellyMainUpdate&&e.jsx(T,{title:"Shelly software update",children:e.jsx(Q,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:W,children:e.jsx(We,{})})}),e.jsx(T,{title:"Restart matterbridge",children:e.jsx(Q,{style:{color:x||p?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:L,children:e.jsx(dt,{})})}),h.matterbridgeInformation.restartMode===""?e.jsx(T,{title:"Shut down matterbridge",children:e.jsx(Q,{style:{color:x||p?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:_,children:e.jsx(Re,{})})}):null,e.jsx(T,{title:"Download, backup and more",children:e.jsx(Q,{onClick:ne,children:e.jsx(hr,{style:{color:"var(--main-icon-color)"}})})}),e.jsxs(ze,{id:"command-menu",anchorEl:v,keepMounted:!0,open:!!v,onClose:()=>H(""),children:[h.matterbridgeInformation&&!h.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>H("update"),children:[e.jsx(z,{children:e.jsx(We,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Install latest stable",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&!h.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>H("updatedev"),children:[e.jsx(z,{children:e.jsx(We,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Install latest dev",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&!h.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>H("updatecheck"),children:[e.jsx(z,{children:e.jsx(We,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Check for updates",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&h.matterbridgeInformation.shellySysUpdate&&e.jsxs(I,{onClick:()=>H("shelly-sys-update"),children:[e.jsx(z,{children:e.jsx(We,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shelly system update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&h.matterbridgeInformation.shellyMainUpdate&&e.jsxs(I,{onClick:()=>H("shelly-main-update"),children:[e.jsx(z,{children:e.jsx(We,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shelly software update",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>H("restart"),children:[e.jsx(z,{children:e.jsx(dt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Restart",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation.restartMode===""?e.jsxs(I,{onClick:()=>H("shutdown"),children:[e.jsx(z,{children:e.jsx(Re,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shutdown",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}):null,h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{u("Reboot","Are you sure you want to reboot the Shelly board?","reboot",H,oe)},children:[e.jsx(z,{children:e.jsx(dt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reboot...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsx(Ze,{}),e.jsxs(I,{onClick:je,children:[e.jsx(z,{children:e.jsx(et,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"View",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(ze,{id:"sub-menu-view",anchorEl:G,keepMounted:!0,open:!!G,onClose:xe,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{H("view-mblog"),xe()},children:[e.jsx(z,{children:e.jsx(et,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("view-mjlog"),xe()},children:[e.jsx(z,{children:e.jsx(et,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{H("view-shellylog"),xe()},children:[e.jsx(z,{children:e.jsx(et,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(Ze,{}),e.jsxs(I,{onClick:me,children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Download",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(ze,{id:"sub-menu-download",anchorEl:a,keepMounted:!0,open:!!a,onClose:J,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{H("download-mbstorage"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("download-pluginstorage"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge plugins storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("download-pluginconfig"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge plugins config",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("download-mblog"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("download-mjstorage"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("download-mjlog"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{H("shelly-create-system-log"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Create Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{H("shelly-download-system-log"),J()},children:[e.jsx(z,{children:e.jsx(Se,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Download Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(Ze,{}),e.jsxs(I,{onClick:ue,children:[e.jsx(z,{children:e.jsx(ht,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(ze,{id:"sub-menu-backup",anchorEl:F,keepMounted:!0,open:!!F,onClose:ee,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{H("create-backup"),ee()},children:[e.jsx(z,{children:e.jsx(ht,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Create backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{H("download-backup"),ee()},children:[e.jsx(z,{children:e.jsx(ht,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Download backup",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]}),e.jsx(Ze,{}),e.jsxs(I,{onClick:le,children:[e.jsx(z,{children:e.jsx(fr,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(ze,{id:"sub-menu-reset",anchorEl:d,keepMounted:!0,open:!!d,onClose:fe,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(I,{onClick:()=>{fe(),u("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",H,oe)},children:[e.jsx(z,{children:e.jsx(Re,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset all devices...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(I,{onClick:()=>{fe(),u("Reset commissioning and shutdown","Are you sure you want to reset the commissioning? You will have to manually remove Matterbridge from the controller.","reset",H,oe)},children:[e.jsx(z,{children:e.jsx(Re,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset commissioning...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),!h.matterbridgeInformation.readOnly&&e.jsxs(I,{onClick:()=>{fe(),u("Factory reset and shutdown","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","factoryreset",H,oe)},children:[e.jsx(z,{children:e.jsx(Re,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{fe(),u("Network reset","Are you sure you want to factory reset the network parameters?","softreset",H,oe)},children:[e.jsx(z,{children:e.jsx(Re,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset network...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),h.matterbridgeInformation&&h.matterbridgeInformation.shellyBoard&&e.jsxs(I,{onClick:()=>{fe(),u("Factory reset","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","hardreset",H,oe)},children:[e.jsx(z,{children:e.jsx(Re,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]})]})]})]})}const Vo=r.memo(Oo),Eo=()=>"ontouchstart"in window||typeof window.DocumentTouch<"u"&&document instanceof window.DocumentTouch?(n&&console.log("WebSocketLogs detectTouchscreen = true"),!0):(n&&console.log("WebSocketLogs detectTouchscreen = false"),!1);function Ao(){const{messages:i,autoScroll:u}=r.useContext(Ut),[c,o]=r.useState(!1),l=r.useRef(null),y=r.useMemo(()=>Eo(),[]),g=p=>o(!0),t=p=>o(!1);r.useEffect(()=>{n&&console.log(`WebSocketLogs autoScroll: ${u} isHovering: ${c}`),u&&!c&&!y&&l.current?.scrollIntoView({behavior:"smooth"})},[i,c,u,y]);const x=p=>{switch(p.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"#5c0e91"}},N=p=>{switch(p.toLowerCase()){case"warn":return"black";default:return"white"}};return e.jsx("div",{style:{margin:"0px",padding:"0px"},children:e.jsxs("ul",{style:{margin:"0px",padding:"0px"},onMouseEnter:g,onMouseLeave:t,children:[i.map((p,j)=>e.jsxs("li",{style:{wordWrap:"break-word",maxHeight:"200px",overflow:"hidden"},children:[e.jsx("span",{style:{marginRight:"5px",padding:"1px 5px",backgroundColor:x(p.level),color:N(p.level),fontSize:"12px",borderRadius:"3px",textAlign:"center"},children:p.level}),p.time&&e.jsx("span",{style:{marginRight:"3px",color:"#505050"},children:"["+p.time+"]"}),p.name&&e.jsx("span",{style:{marginRight:"3px",color:"#09516d"},children:"["+p.name+"]"}),e.jsx("span",{style:{color:"var(--main-log-color)"},children:p.message})]},j)),e.jsx("div",{ref:l})]})})}const Bt=r.memo(Ao);function $e(){const{retry:i}=r.useContext(ge),u=()=>{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(Y,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:i<100?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"256px",width:"256px",margin:"10px",marginBottom:"20px"}}),e.jsx(xr,{style:{color:"var(--primary-color)"}}),e.jsx("div",{style:{marginTop:"20px",color:"var(--primary-color)"},children:e.jsxs("span",{children:["Reconnecting to Matterbridge ","(attempt "+i+")","..."]})})]}):e.jsxs("div",{style:{marginTop:"20px",color:"var(--primary-color)",textAlign:"center"},children:[e.jsx("img",{src:"matterbridge.svg",alt:"Matterbridge Logo",style:{height:"256px",width:"256px",margin:"10px",marginBottom:"20px"}}),e.jsx("span",{children:"Unable to connect to Matterbridge after multiple attempts."}),e.jsx("br",{}),e.jsx("span",{children:"Please check your network connection."}),e.jsx("br",{}),e.jsx(ae,{variant:"contained",color:"primary",onClick:u,style:{marginTop:"20px"},children:"Refresh the Page"})]})})})}function _o({value:i,maxChars:u}){let c=i;if(i.length>u&&u>3){const o=u-3,l=i.substring(0,Math.ceil(o/2)),y=i.substring(i.length-Math.floor(o/2),i.length);c=`${l} … ${y}`}return i!==c?e.jsx(T,{title:i,placement:"top",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[0,12]}}]}},children:e.jsx("span",{children:c})}):e.jsx("span",{children:c})}function qo({systemInfo:i,compact:u}){const{sendMessage:c,addListener:o,removeListener:l,getUniqueId:y}=r.useContext(ge),[g,t]=r.useState(i),x=r.useRef(y());if(n&&console.log("SystemInfoTable:",g,"compact:",u),i&&u&&g.totalMemory&&g.freeMemory){const N=g.totalMemory,p=g.freeMemory;g.freeMemory=`${p} / ${N}`,g.totalMemory=""}if(i&&u&&g.heapTotal&&g.heapUsed){const N=g.heapTotal,p=g.heapUsed;g.heapUsed=`${p} / ${N}`,g.heapTotal=""}if(i&&u&&g.osRelease&&g.osType){const N=g.osType,p=g.osRelease;g.osType=`${N} (${p})`,g.osRelease=""}if(i&&u&&g.osArch&&g.osPlatform){const N=g.osPlatform,p=g.osArch;g.osPlatform=`${N} (${p})`,g.osArch=""}return r.useEffect(()=>{const N=p=>{p.src==="Matterbridge"&&p.dst==="Frontend"&&(p.method==="memory_update"&&p.response&&p.response.totalMemory&&p.response.freeMemory&&p.response.heapTotal&&p.response.heapUsed&&p.response.rss&&(n&&console.log("SystemInfoTable received memory_update",p),(g.totalMemory!==p.response.totalMemory||g.freeMemory!==p.response.freeMemory||g.heapTotal!==p.response.heapTotal||g.heapUsed!==p.response.heapUsed||g.rss!==p.response.rss)&&t(j=>({...j,totalMemory:p.response.totalMemory,freeMemory:p.response.freeMemory,heapTotal:p.response.heapTotal,heapUsed:p.response.heapUsed,rss:p.response.rss}))),p.method==="cpu_update"&&p.response&&p.response.cpuUsage&&(n&&console.log("SystemInfoTable received cpu_update",p),g.cpuUsage!==(p.response.cpuUsage?p.response.cpuUsage.toFixed(2)+" %":"")&&t(j=>({...j,cpuUsage:p.response.cpuUsage.toFixed(2)+" %"}))),p.method==="uptime_update"&&p.response&&p.response.systemUptime&&p.response.processUptime&&(n&&console.log("SystemInfoTable received uptime_update",p),(g.systemUptime!==p.response.systemUptime||g.processUptime!==p.response.processUptime)&&t(j=>({...j,systemUptime:p.response.systemUptime,processUptime:p.response.processUptime}))))};return n&&console.log("SystemInfoTable useEffect WebSocketMessage mounting"),o(N,x.current),n&&console.log("SystemInfoTable useEffect WebSocketMessage mounted"),()=>{n&&console.log("SystemInfoTable useEffect WebSocketMessage unmounting"),l(N),n&&console.log("SystemInfoTable useEffect WebSocketMessage unmounted")}},[o,g.cpuUsage,g.freeMemory,g.heapTotal,g.heapUsed,g.processUptime,g.rss,g.systemUptime,g.totalMemory,l,c]),g?(n&&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(g).filter(([N,p])=>p!==void 0&&p!=="").map(([N,p],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:N}),e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx(_o,{value:typeof p!="string"?p.toString():p,maxChars:25})})]},N))})})})]})):null}const zo=r.memo(qo),$t={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"}},Uo=i=>{if(!i)return"";const u=i.toString().replace(/[^0-9]/g,"");if(u.length<5)return u;const c=u.slice(0,4),o=u.slice(4,7),l=u.slice(7,11);return[c,o,l].filter(Boolean).join("-")};function Bo({id:i}){const{online:u,sendMessage:c,addListener:o,removeListener:l,getUniqueId:y}=r.useContext(ge),[g,t]=r.useState(null),[x,N]=r.useState(null),p=r.useRef(null),j=r.useRef(y()),{showConfirmCancelDialog:O}=r.useContext(Be);r.useEffect(()=>{n&&console.log(`QRDiv received storeId update "${i}"`),i&&(n&&console.log(`QRDiv sending data request for storeId "${i}"`),t(i),c({id:j.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:i,server:!0}}))},[i]),r.useEffect(()=>{const b=v=>{v.src==="Matterbridge"&&v.dst==="Frontend"&&v.method==="refresh_required"&&v.response.changed==="matter"&&v.response.matter&&(n&&console.log(`QRDiv received refresh_required: changed=${v.response.changed} for storeId "${v.response.matter.id}":`,v.response.matter),g===v.response.matter.id&&(n&&console.log(`QRDiv received refresh_required/matter: setting matter data for storeId "${v.response.matter.id}":`,v.response.matter),p.current&&clearTimeout(p.current),v.response.matter.advertising&&v.response.matter.advertiseTime&&v.response.matter.advertiseTime+9e5<=Date.now()&&(v.response.matter.advertising=!1),N(v.response.matter),v.response.matter.advertising&&(n&&console.log(`QRDiv setting matter advertise timeout for storeId "${v.response.matter.id}":`,v.response.matter.advertiseTime+9e5-Date.now()),p.current=setTimeout(()=>{p.current&&clearTimeout(p.current),n&&console.log(`QRDiv clearing advertising state for storeId "${g}" after 15 minutes`),N(w=>w&&{...w,advertising:!1})},v.response.matter.advertiseTime+9e5-Date.now()))))};return o(b,j.current),n&&console.log("QRDiv webSocket effect mounted"),()=>{l(b),p.current&&clearTimeout(p.current),p.current=null,n&&console.log("QRDiv webSocket effect unmounted")}},[g]);const $=()=>{n&&console.log(`QRDiv sent matter startCommission for node "${x?.id}"`),x&&c({id:j.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,startCommission:!0}})},P=()=>{n&&console.log(`QRDiv sent matter stopCommission for node "${x?.id}"`),x&&c({id:j.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,stopCommission:!0}})},U=()=>{n&&console.log(`QRDiv sent matter advertise for node "${x?.id}"`),x&&c({id:j.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,advertise:!0}})},h=b=>{n&&console.log(`QRDiv sent matter removeFabric for node "${x?.id}" and fabricIndex ${b}`),x&&c({id:j.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,removeFabric:b}})},V=async()=>{if(!x||!x.manualPairingCode)return;const b=x.manualPairingCode.toString();try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(b);else{const v=document.createElement("textarea");v.value=b,v.style.position="fixed",v.style.opacity="0",document.body.appendChild(v),v.focus(),v.select(),document.execCommand("copy"),document.body.removeChild(v)}n&&console.log("Manual pairing code copied to clipboard")}catch(v){console.error("Failed to copy manual pairing code",v)}};return!x||!u?(n&&console.log("QRDiv rendering undefined state"),null):x.online?x.advertising&&x.qrPairingCode&&x.manualPairingCode?(n&&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(Q,{"aria-label":"send advertising",size:"small",onClick:U,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(T,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(re,{path:Wt,size:"22px"})})}),e.jsx(Q,{"aria-label":"stop pairing",size:"small",onClick:P,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(T,{title:"Turn off pairing",arrow:!0,children:e.jsx(re,{path:ro,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:g}),e.jsx(to,{value:x.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: ",Uo(x.manualPairingCode)]}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(T,{title:"Copy manual pairing code",arrow:!0,children:e.jsx(Q,{"aria-label":"copy manual pairing code",size:"small",onClick:V,sx:$t,children:e.jsx(re,{path:oo,size:.85})})})})]})]})):x.commissioned&&x.fabricInformations&&x.sessionInformations?(n&&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(Q,{"aria-label":"send advertising",size:"small",onClick:U,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(T,{title:"Send again the mDNS advertisement",arrow:!0,children:e.jsx(re,{path:Wt,size:"22px"})})}),e.jsx(Q,{"aria-label":"start pairing",size:"small",onClick:$,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx(T,{title:"Turn on pairing",arrow:!0,children:e.jsx(re,{path:Lt,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:g}),x.fabricInformations.map((b,v)=>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: ",b.fabricIndex]}),e.jsx(T,{title:"Remove the fabric. You will also need to remove it from the controller.",arrow:!0,children:e.jsx(Q,{"aria-label":"remove the fabric",size:"small",onClick:()=>O("Remove fabric","Are you sure you want to remove this fabric? You will also need to remove it from the controller.","RemoveFabric",()=>h(b.fabricIndex),()=>{}),sx:{...$t,padding:"2px"},children:e.jsx(re,{path:no,size:1})})})]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Vendor: ",b.rootVendorId," ",b.rootVendorName]}),b.label!==""&&e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Label: ",b.label]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Sessions: ",x.sessionInformations?x.sessionInformations.filter(w=>w.fabric?.fabricIndex===b.fabricIndex&&w.isPeerActive===!0).length:"0"," ","subscriptions: ",x.sessionInformations?x.sessionInformations.filter(w=>w.fabric?.fabricIndex===b.fabricIndex&&w.isPeerActive===!0&&w.numberOfActiveSubscriptions>0).length:"0"]})]},v))]}),e.jsx("div",{className:"MbfWindowFooter",children:e.jsxs("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--div-text-color)"},children:["Serial number: ",x.serialNumber]})})]})):!x.commissioned&&!x.advertising?(n&&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:g}),e.jsx(ae,{onClick:$,endIcon:e.jsx(re,{path:Lt,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: ",x.serialNumber]})})]})):(n&&console.log("QRDiv rendering unknown state"),null):(n&&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:g}),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: ",x.serialNumber]})})]}))}const Qo=r.memo(Bo);function Ko(){const{logMessage:i,sendMessage:u,getUniqueId:c}=r.useContext(ge),[o,l]=r.useState("matterbridge-"),[y,g]=r.useState(!1),[t,x]=r.useState(null),N=r.useRef(c()),p=v=>{v.preventDefault(),g(!0)},j=()=>{g(!1)},O=v=>{v.preventDefault(),g(!1);const w=v.dataTransfer.files[0];if(w){i("Plugins",`Installing package ${w.name}. Please wait...`);const F=new FormData;F.append("file",w),F.append("filename",w.name),fetch("./api/uploadpackage",{method:"POST",body:F}).then(C=>C.text()).then(C=>{i("Plugins",`Server response: ${C}`)}).catch(C=>{console.error("Error uploading plugin file:",C),i("Plugins",`Error installing package ${C}`)})}},$=v=>{const w=v.target.files&&v.target.files[0];if(w){i("Plugins",`Uploading package ${w.name}`);const F=new FormData;F.append("file",w),F.append("filename",w.name),fetch("./api/uploadpackage",{method:"POST",body:F}).then(C=>C.text()).then(C=>{i("Plugins",`Server response: ${C}`)}).catch(C=>{console.error("Error uploading plugin file:",C),i("Plugins",`Error uploading package ${C}`)})}},P=()=>{u({id:N.current,sender:"InstallPlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:o,restart:!1}})},U=()=>{document.getElementById("file-upload")?.click()},h=()=>{u({id:N.current,sender:"InstallPlugins",method:"/api/addplugin",src:"Frontend",dst:"Matterbridge",params:{pluginNameOrPath:o}})},V=v=>{x(v.currentTarget)},b=v=>{v!==""&&l(v),x(null)};return n&&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:p,onDragLeave:j,onDrop:O,children:[e.jsx(de,{value:o,onChange:v=>{l(v.target.value)},size:"small",id:"plugin-name",label:"Plugin name or plugin path",variant:"outlined",fullWidth:!0}),e.jsx(Q,{onClick:V,children:e.jsx(br,{})}),e.jsxs(ze,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:!!t,onClose:()=>b(""),children:[e.jsx(I,{onClick:()=>b("matterbridge-zigbee2mqtt"),children:"matterbridge-zigbee2mqtt"}),e.jsx(I,{onClick:()=>b("matterbridge-somfy-tahoma"),children:"matterbridge-somfy-tahoma"}),e.jsx(I,{onClick:()=>b("matterbridge-shelly"),children:"matterbridge-shelly"}),e.jsx(I,{onClick:()=>b("matterbridge-hass"),children:"matterbridge-hass"}),e.jsx(I,{onClick:()=>b("matterbridge-webhooks"),children:"matterbridge-webhooks"}),e.jsx(I,{onClick:()=>b("matterbridge-bthome"),children:"matterbridge-bthome"}),e.jsx(I,{onClick:()=>b("matterbridge-test"),children:"matterbridge-test"}),e.jsx(I,{onClick:()=>b("matterbridge-example-accessory-platform"),children:"matterbridge-example-accessory-platform"}),e.jsx(I,{onClick:()=>b("matterbridge-example-dynamic-platform"),children:"matterbridge-example-dynamic-platform"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-door"),children:"matterbridge-eve-door"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-motion"),children:"matterbridge-eve-motion"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-energy"),children:"matterbridge-eve-energy"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-weather"),children:"matterbridge-eve-weather"}),e.jsx(I,{onClick:()=>b("matterbridge-eve-room"),children:"matterbridge-eve-room"})]}),e.jsx(T,{title:"Install or update a plugin from npm",children:e.jsx(ae,{onClick:P,endIcon:e.jsx(Se,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Install"})}),e.jsx(T,{title:"Upload and install a plugin from a tarball",children:e.jsx(ae,{onClick:U,endIcon:e.jsx(vr,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Upload"})}),e.jsx(T,{title:"Add an installed plugin",children:e.jsx(ae,{onClick:h,endIcon:e.jsx(ct,{}),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:$})]})}const Jo=r.memo(Ko);function Ee({status:i,enabledText:u="Enabled",disabledText:c=void 0,tooltipText:o=void 0,onClick:l}){if(i===void 0)return null;{const y=e.jsx("div",{className:i?"status-enabled":"status-disabled",style:{cursor:"default"},onClick:l,children:i?u:c??u});return o!==void 0?e.jsx(T,{title:o,children:y}):y}}function Rt(i){return i.id!==0&&i.src==="Matterbridge"&&i.dst==="Frontend"}const Ae={fontSize:"16px",fontWeight:"bold",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},_e={fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)",backgroundColor:"var(--div-bg-color)"},Go={fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)",backgroundColor:"var(--div-bg-color)"},Yo={fontSize:"16px",fontWeight:"bold",backgroundColor:"var(--div-bg-color)"},ke={padding:"0px",margin:"0px"},Xo="5px 10px 5px 10px",st={},he={},at={},lt={};let qe=[],xt=[];const Zo=({open:i,onClose:u,plugin:c})=>{const{sendMessage:o,addListener:l,removeListener:y,getUniqueId:g}=r.useContext(ge),t=r.useRef(g()),[x,N]=r.useState(c.configJson),[p,j]=r.useState(null),[O,$]=r.useState({"ui:submitButtonOptions":{submitText:"Confirm"},"ui:globalOptions":{orderable:!0}}),[P,U]=r.useState("");let h={};r.useEffect(()=>{const D=S=>{S.src==="Matterbridge"&&S.dst==="Frontend"&&(Rt(S)&&S.id===t.current&&S.method==="/api/select/devices"&&S.response&&(n&&console.log(`ConfigPluginDialog (id: ${S.id}) received ${S.response.length} /api/select/devices:`,S.response),qe=S.response),Rt(S)&&S.id===t.current&&S.method==="/api/select/entities"&&S.response&&(n&&console.log(`ConfigPluginDialog (id: ${S.id}) received ${S.response.length} /api/select/entities:`,S.response),xt=S.response))};return l(D,t.current),n&&console.log("ConfigPluginDialog added WebSocket listener id:",t.current),x&&p&&p.properties&&(Object.keys(p.properties).forEach(S=>{Object.keys(p.properties[S]).forEach(L=>{L.startsWith("ui:")&&(O[S]={},O[S][L]=p.properties[S][L],delete p.properties[S][L])})}),$(O)),c.name&&c.configJson&&c.schemaJson&&(N(c.configJson),j(c.schemaJson),o({id:t.current,sender:"ConfigPlugin",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name}}),o({id:t.current,sender:"ConfigPlugin",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name}}),n&&console.log('HomePlugins sent "/api/select/devices" and "/api/select/entities" for plugin:',c.name)),()=>{y(D),n&&console.log("ConfigPluginDialog removed WebSocket listener")}},[l,x,c,y,p,o,O]);const V=(D,S)=>{h=D.formData},b=D=>{n&&console.log("ConfigPluginDialog handleSaveChanges:",D.formData),N(D.formData),c.configJson=D.formData,c.restartRequired=!0,o({id:t.current,sender:"ConfigPlugin",method:"/api/savepluginconfig",src:"Frontend",dst:"Matterbridge",params:{pluginName:D.formData.name,formData:D.formData}}),u()};function v(D){const{id:S,label:L,onKeyChange:_,onDropPropertyClick:Z,disabled:K,schema:f,children:ne,registry:H,readonly:oe,required:ue}=D,{templates:ee}=H,{RemoveButton:je}=ee.ButtonTemplates;if(!(To in f))return e.jsx(Y,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:ne});const me=({target:J})=>_(J&&J.value);return e.jsxs(Y,{sx:{display:"flex",flexDirection:"row",flexGrow:1,padding:0,margin:0,border:"none"},children:[e.jsx(de,{id:`${S}-key`,name:`${S}-key`,required:ue,disabled:K||oe,defaultValue:L,onBlur:oe?void 0:me,type:"text",variant:"outlined",sx:{width:"250px",minWidth:"250px",maxWidth:"250px",marginRight:"20px"}}),e.jsx(Y,{sx:{flex:1},children:ne}),e.jsx(je,{disabled:K||oe,onClick:Z(L),registry:H})]})}function w(D){const{children:S,description:L,displayLabel:_,errors:Z,help:K,hidden:f,registry:ne,uiSchema:H}=D,oe=Lo(H),ue=Fo("WrapIfAdditionalTemplate",ne,oe);return f?e.jsx("div",{style:{display:"none"},children:S}):e.jsx(Y,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:e.jsxs(ue,{...D,children:[_===!0&&L,S,Z,K]})})}function F(D){const{description:S}=D;return S?e.jsx(se,{sx:_e,children:S}):null}function C(D){const{required:S,title:L}=D;return L?e.jsx(Y,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsxs(se,{sx:Ae,children:["Title ",L," ",S&&e.jsx("mark",{children:"***"})]})}):null}function G(D){const{help:S}=D;return S?e.jsx(Y,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsx(se,{sx:Go,children:S})}):null}function A(D){const{errors:S}=D;return S?e.jsxs(Y,{sx:{padding:"10px",margin:"10px",border:"1px solid grey"},children:[e.jsx(se,{color:"error",sx:Yo,children:"Please fix the following errors:"}),e.jsx(Je,{children:S.map((L,_)=>e.jsxs(yr,{children:[e.jsx(z,{children:e.jsx(jr,{color:"error"})}),e.jsx(te,{primary:L.stack})]},_))})]}):null}function a(D){const{errors:S}=D;return S?e.jsx(Y,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:S.map((L,_)=>e.jsxs(se,{color:"error",variant:"body2",sx:{marginLeft:1},children:["This field ",L]},_))}):null}function s(D){const{id:S,name:L,_schema:_,_uiSchema:Z,value:K,options:f,label:ne,type:H,placeholder:oe,required:ue,disabled:ee,readonly:je,autofocus:xe,onChange:me,onChangeOverride:J,onBlur:le,onFocus:fe,_rawErrors:Qe,_hideError:B,_registry:k,_formContext:ce}=D,Ke=({target:{value:ve}})=>me(ve===""?f.emptyValue:ve),Pe=({target:ve})=>le(S,ve&&ve.value),Ye=({target:ve})=>fe(S,ve&&ve.value);return e.jsx(Y,{sx:{padding:"0px",margin:"0px"},children:e.jsx(de,{id:S,name:S,label:oe&&oe!==""?ne:void 0,variant:"outlined",placeholder:oe&&oe!==""?oe:ne,required:ue,disabled:ee||je,autoFocus:xe,value:K||K===0?K:"",type:H,autoComplete:H==="password"?"current-password":L,onChange:J||Ke,onBlur:Pe,onFocus:Ye,fullWidth:!0})})}function d(D){return console.log("ArrayFieldTitleTemplate:",D),null}function m(D){return console.log("ArrayFieldDescriptionTemplate:",D),null}function R(D){return console.log("ArrayFieldItemTemplate:",D),null}function pe(D){const{canAdd:S,onAddClick:L,schema:_,title:Z}=D,[K,f]=r.useState(!1),[ne,H]=r.useState(!1),[oe,ue]=r.useState(!1),[ee,je]=r.useState(""),xe=k=>{je(k.target.value)},me=()=>{n&&console.log("ArrayFieldTemplate: handleDialogDeviceToggle filter:",ee,"selectDevices:",qe),f(!K)},J=()=>{n&&console.log("ArrayFieldTemplate: handleDialogEntityToggle filter:",ee,"selectEntities:",xt),H(!ne)},le=()=>{n&&console.log("ArrayFieldTemplate: handleDialogDeviceEntityToggle filter:",ee,"selectDevices:",qe),ue(!oe)},fe=k=>{f(!1),_.selectFrom==="serial"?_.items.default=k.serial:_.selectFrom==="name"&&(_.items.default=k.name),L()},Qe=k=>{H(!1),_.selectEntityFrom==="name"?_.items.default=k.name:_.selectEntityFrom==="description"&&(_.items.default=k.description),L()},B=k=>{ue(!1),_.selectDeviceEntityFrom==="name"?_.items.default=k.name:_.selectDeviceEntityFrom==="description"&&(_.items.default=k.description),L()};return e.jsxs(Y,{sx:{margin:"0px",padding:"5px 10px 5px 10px",border:"1px solid grey"},children:[Z&&e.jsxs(Y,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[Z&&e.jsx(se,{sx:Ae,children:Z}),S&&e.jsxs(Y,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[_.selectFrom&&e.jsx(T,{title:"Add a device from the list",children:e.jsx(Q,{onClick:me,size:"small",color:"primary",sx:ke,children:e.jsx(tt,{})})}),_.selectEntityFrom&&e.jsx(T,{title:"Add an entity from the list",children:e.jsx(Q,{onClick:J,size:"small",color:"primary",sx:ke,children:e.jsx(tt,{})})}),_.selectDeviceEntityFrom&&e.jsx(T,{title:"Add a device entity from the list",children:e.jsx(Q,{onClick:le,size:"small",color:"primary",sx:ke,children:e.jsx(tt,{})})}),e.jsx(T,{title:"Add a new item",children:e.jsx(Q,{onClick:L,size:"small",color:"primary",sx:ke,children:e.jsx(ct,{})})})]})]}),_.description&&e.jsx(se,{sx:_e,children:_.description}),D.items.map(k=>e.jsxs(Y,{sx:{margin:"2px 0px",padding:"0px",display:"flex",alignItems:"center"},children:[e.jsx(Y,{sx:{flexGrow:1,marginRight:"10px"},children:k.children}),e.jsx(Q,{disabled:!k.hasMoveUp,onClick:k.onReorderClick(k.index,k.index-1),size:"small",color:"primary",sx:ke,children:e.jsx(Mt,{})}),e.jsx(Q,{disabled:!k.hasMoveDown,onClick:k.onReorderClick(k.index,k.index+1),size:"small",color:"primary",sx:ke,children:e.jsx(St,{})}),e.jsx(Q,{onClick:k.onDropIndexClick(k.index),size:"small",color:"primary",sx:ke,children:e.jsx(ut,{})})]},k.index)),e.jsxs(Ie,{open:K,onClose:me,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(De,{children:"Select a device"}),e.jsxs(Ne,{children:[e.jsxs(Y,{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(de,{fullWidth:!0,variant:"outlined",value:ee,onChange:xe,placeholder:"Enter serial or name"})]}),e.jsx(Je,{dense:!0,children:qe.filter(k=>k.serial.toLowerCase().includes(ee.toLowerCase())||k.name.toLowerCase().includes(ee.toLowerCase())).map((k,ce)=>e.jsxs(rt,{onClick:()=>fe(k),sx:st,children:[k.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:he})}),k.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:he})}),k.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:he})}),e.jsx(te,{primary:k.name,secondary:k.serial,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ce))})]}),e.jsx(Oe,{children:e.jsx(ae,{onClick:me,children:"Close"})})]}),e.jsxs(Ie,{open:ne,onClose:J,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(De,{children:"Select an entity"}),e.jsxs(Ne,{children:[e.jsxs(Y,{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(de,{fullWidth:!0,variant:"outlined",value:ee,onChange:xe,placeholder:"Enter name or description"})]}),e.jsx(Je,{dense:!0,children:xt.filter(k=>k.name.toLowerCase().includes(ee.toLowerCase())||k.description.toLowerCase().includes(ee.toLowerCase())).map((k,ce)=>e.jsxs(rt,{onClick:()=>Qe(k),sx:st,children:[k.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:he})}),k.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:he})}),k.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:he})}),k.icon==="component"&&e.jsx(z,{children:e.jsx(kt,{style:he})}),k.icon==="matter"&&e.jsx(z,{children:e.jsx(It,{style:he})}),e.jsx(te,{primary:k.name,secondary:k.description,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ce))})]}),e.jsx(Oe,{children:e.jsx(ae,{onClick:J,children:"Close"})})]}),e.jsxs(Ie,{open:oe,onClose:le,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsxs(De,{children:["Select an entity for ",Z]}),e.jsx(Ne,{children:e.jsx(Je,{dense:!0,children:qe.filter(k=>k.serial===Z||k.name===Z).map(k=>k.entities?.map((ce,Ke)=>e.jsxs(rt,{onClick:()=>B(ce),sx:st,children:[ce.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:he})}),ce.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:he})}),ce.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:he})}),ce.icon==="component"&&e.jsx(z,{children:e.jsx(kt,{style:he})}),ce.icon==="matter"&&e.jsx(z,{children:e.jsx(It,{style:he})}),e.jsx(te,{primary:ce.name,secondary:ce.description,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},Ke)))})}),e.jsx(Oe,{children:e.jsx(ae,{onClick:le,children:"Close"})})]})]})}function Ce(D){const{onAddClick:S,schema:L,properties:_,title:Z,description:K}=D,[f,ne]=r.useState(!1),[H,oe]=r.useState(""),ue=J=>{oe(J.target.value)},ee=()=>{ne(!f)},je=J=>{n&&console.log(`ObjectFieldTemplate: handleSelectValue value "${J.serial}" for schema "${L.selectFrom}"`),ne(!1);let le="";L.selectFrom==="serial"?le=J.serial:L.selectFrom==="name"&&(le=J.name),U(le),n&&console.log(`ObjectFieldTemplate: handleSelectValue newkey "${le}"`),S(L)()},xe=()=>{S(L)()},me=!L.additionalProperties;return n&&console.log(`ObjectFieldTemplate: isRoot ${me} newkey "${P}"`),!me&&P!==""&&(n&&console.log("ObjectFieldTemplate: newkey",P,"properties",_),_.forEach(J=>{if(J.name==="newKey"&&J.content.key==="newKey"&&J.content.props.name==="newKey"&&J.content.props.onKeyChange&&P!==""){n&&console.log("ObjectFieldTemplate: newkey onKeyChange",P);const le=P;U(""),J.content.props.onKeyChange(le)}})),e.jsxs(Y,{sx:{margin:"0px",padding:me?"10px":"5px 10px 0px 10px",border:me?"none":"1px solid grey"},children:[L.title&&me&&e.jsx(Y,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(se,{sx:Ae,children:L.title})}),Z&&!me&&e.jsxs(Y,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[e.jsx(se,{sx:Ae,children:Z}),e.jsxs(Y,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[L.selectFrom&&e.jsx(T,{title:"Add a device from the list",children:e.jsx(Q,{onClick:ee,size:"small",color:"primary",sx:ke,children:e.jsx(tt,{})})}),e.jsx(T,{title:"Add a new item",children:e.jsx(Q,{onClick:xe,size:"small",color:"primary",sx:ke,children:e.jsx(ct,{})})})]})]}),L.description&&e.jsx(Y,{sx:{padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(se,{sx:_e,children:L.description})}),_.map(({content:J,name:le,hidden:fe})=>!fe&&e.jsxs(Y,{sx:{margin:"0px",marginBottom:"10px",padding:["object","array","boolean"].includes(L.properties[le].type)?"0px":Xo,border:["object","array","boolean"].includes(L.properties[le].type)?"none":"1px solid grey"},children:[!["object","array","boolean"].includes(L.properties[le].type)&&e.jsx(se,{sx:Ae,children:le}),e.jsx(Y,{sx:{flexGrow:1,padding:"0px",margin:"0px"},children:J})]},le)),e.jsxs(Ie,{open:f,onClose:ee,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(De,{children:"Select a device"}),e.jsxs(Ne,{children:[e.jsxs(Y,{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(de,{fullWidth:!0,variant:"outlined",value:H,onChange:ue,placeholder:"Enter serial or name"})]}),e.jsx(Je,{dense:!0,children:qe.filter(J=>J.serial.toLowerCase().includes(H.toLowerCase())||J.name.toLowerCase().includes(H.toLowerCase())).map((J,le)=>e.jsxs(rt,{onClick:()=>je(J),sx:st,children:[J.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:he})}),J.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:he})}),J.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:he})}),e.jsx(te,{primary:J.name,secondary:J.serial,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},le))})]}),e.jsx(Oe,{children:e.jsx(ae,{onClick:ee,children:"Close"})})]})]})}function we(D){const{uiSchema:S}=D,{submitText:L,norender:_}=Wo(S);return _?null:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",margin:"10px",padding:"0px",gap:"20px"},children:[e.jsx(ae,{type:"submit",variant:"contained",color:"primary",children:L}),e.jsx(ae,{variant:"contained",color:"primary",onClick:u,children:"Cancel"})]})}function ye(D){const{className:S,disabled:L,onClick:_,registry:Z,style:K,uiSchema:f,...ne}=D;return e.jsx(T,{title:"Remove the item",children:e.jsx(Q,{disabled:L,size:"small",color:"primary",onClick:_,children:e.jsx(ut,{})})})}function X(D){const{className:S,disabled:L,onClick:_,registry:Z,uiSchema:K,...f}=D;return e.jsx(T,{title:"Add an item",children:e.jsx(Q,{size:"small",color:"primary",onClick:_,children:e.jsx(ct,{})})})}function ie(D){const{disabled:S,onClick:L,registry:_,style:Z,uiSchema:K,...f}=D;return e.jsx(T,{title:"Move up the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:L,children:e.jsx(Mt,{})})})}function M(D){const{disabled:S,onClick:L,registry:_,style:Z,uiSchema:K,...f}=D;return e.jsx(T,{title:"Move down the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:L,children:e.jsx(St,{})})})}function E(D){const{id:S,name:L,value:_,schema:Z,readonly:K,onChange:f}=D,[ne,H]=r.useState(),oe=ee=>{n&&console.log(`CheckboxWidget ${L} onChangeField:`,ee),H(ee&&ee!==""?ee:void 0)},ue=()=>{n&&console.log(`CheckboxWidget onClick plugin="${c.name}" action="${L}" value="${ne}"`),o({id:t.current,sender:"ConfigPlugin",method:"/api/action",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name,action:L,value:ne,formData:h,id:S}}),Z.buttonClose===!0?u():Z.buttonSave===!0&&b({formData:x})};return Z.buttonText&&Z.description?e.jsxs(Y,{sx:{margin:"0px",padding:"10px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(se,{sx:_e,children:Z.description}),e.jsx(ae,{variant:"contained",color:"primary",onClick:()=>ue(),children:Z.buttonText})]}):Z.buttonField&&Z.description?e.jsxs(Y,{sx:{margin:"0px",padding:"10px",gap:"20px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(se,{sx:_e,children:Z.description}),e.jsx(de,{id:L+"-input",name:L,label:Z.textLabel,placeholder:Z.textPlaceholder,onChange:ee=>oe(ee.target.value),sx:{width:"250px",minWidth:"250px",maxWidth:"250px"}}),e.jsx(ae,{id:L+"-button",variant:"contained",color:"primary",disabled:ne===void 0,onClick:()=>ue(),children:Z.buttonField})]}):e.jsxs(Y,{sx:{margin:"0px",padding:"5px 10px",border:"1px solid grey"},children:[L&&e.jsxs(Y,{sx:{margin:"0px",padding:"0px",gap:"10px",display:"flex",justifyContent:"flex-start",alignItems:"center"},children:[e.jsx(se,{sx:Ae,children:L}),e.jsx(Te,{checked:_,readOnly:K,onChange:()=>f(!_),sx:{padding:"0px",margin:"0px"}})]}),Z.description&&e.jsx(se,{sx:_e,children:Z.description})]})}function W({schema:D,id:S,name:L,options:_,label:Z,hideLabel:K,required:f,disabled:ne,placeholder:H,readonly:oe,value:ue,multiple:ee,autofocus:je,onChange:xe,onBlur:me,onFocus:J,errorSchema:le,rawErrors:fe=[],registry:Qe,uiSchema:B,hideError:k,formContext:ce,...Ke}){const{enumOptions:Pe,enumDisabled:Ye,emptyValue:ve}=_;ee=typeof ee>"u"?!1:!!ee;const yt=ee?[]:"",jt=typeof ue>"u"||ee&&ue.length<1||!ee&&ue===yt,Kt=({target:{value:Me}})=>xe(ft(Me,Pe,ve)),Jt=({target:Me})=>me(S,ft(Me&&Me.value,Pe,ve)),Gt=({target:Me})=>J(S,ft(Me&&Me.value,Pe,ve)),Ct=No(ue,Pe,ee),{InputLabelProps:Yt,SelectProps:Xt,autocomplete:Zt,...er}=Ke,tr=!ee&&D.default===void 0;return e.jsxs(de,{id:S,name:S,value:!jt&&typeof Ct<"u"?Ct:yt,required:f,disabled:ne||oe,autoFocus:je,autoComplete:Zt,placeholder:H,error:fe.length>0,onChange:Kt,onBlur:Jt,onFocus:Gt,...er,select:!0,InputLabelProps:{...Yt,shrink:!jt},SelectProps:{...Xt,multiple:ee},"aria-describedby":Po(S),children:[tr&&e.jsx(I,{value:"",children:H}),Array.isArray(Pe)&&Pe.map(({value:Me,label:rr},wt)=>{const or=Array.isArray(Ye)&&Ye.indexOf(Me)!==-1;return e.jsx(I,{value:String(wt),disabled:or,children:rr},wt)})]})}return n&&console.log("ConfigPluginDialog rendering..."),!i||!p||!x?null:e.jsxs(Ie,{open:i,onClose:u,slotProps:{paper:{sx:{maxWidth:"800px"}}},children:[e.jsx(De,{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(Ne,{style:{padding:"0px",margin:"0px",width:"800px",height:"600px",overflow:"auto"},children:e.jsx(Io,{schema:p,formData:x,uiSchema:O,validator:Do,templates:{FieldTemplate:w,BaseInputTemplate:s,TitleFieldTemplate:C,DescriptionFieldTemplate:F,FieldHelpTemplate:G,FieldErrorTemplate:a,ErrorListTemplate:A,WrapIfAdditionalTemplate:v,ArrayFieldTitleTemplate:d,ArrayFieldDescriptionTemplate:m,ArrayFieldItemTemplate:R,ArrayFieldTemplate:pe,ObjectFieldTemplate:Ce,ButtonTemplates:{SubmitButton:we,RemoveButton:ye,AddButton:X,MoveUpButton:ie,MoveDownButton:M}},widgets:{CheckboxWidget:E,SelectWidget:W},onChange:V,onSubmit:b})})]})};function Qt(i){if(n&&console.log(`getQRColor (id: ${i?.id}) received matter:`,i??"undefined"),i===void 0||!i.online||!i.qrPairingCode&&!i.manualPairingCode&&!i.fabricInformations&&!i.sessionInformations)return"red";if(i.commissioned===!1&&i.qrPairingCode&&i.manualPairingCode)return"var(--primary-color)";let u=0,c=0;for(const o of i.sessionInformations??[])o.fabric&&o.isPeerActive===!0&&u++,o.numberOfActiveSubscriptions>0&&(c+=o.numberOfActiveSubscriptions);return i.commissioned===!0&&i.fabricInformations&&i.sessionInformations&&(u===0||c===0)?"var(--secondary-color)":"var(--div-text-color)"}function en(i,u,c){const o=i?.[c],l=u?.[c];return o==null&&l==null?0:o==null?-1:l==null?1:typeof o=="boolean"&&typeof l=="boolean"?o===l?0:o?1:-1:typeof o=="number"&&typeof l=="number"?o-l:String(o).localeCompare(String(l))}function tn({name:i,title:u,columns:c,rows:o,getRowKey:l,footerLeft:y,footerRight:g,onRowClick:t}){const x=r.useRef(new WeakMap),N=r.useRef(1),p=a=>{if(typeof l=="string"&&a&&a[l]!=null)return a[l];if(typeof l=="function"){const m=l(a);if(m!=null)return m}const s=c?.[0]?.id;if(s&&a&&a[s]!=null)return a[s];console.warn(`MbfTable(${i}): using fallback stable row key; consider providing getRowKey prop for better React performance`);let d=x.current.get(a);return d||(d=`rk_${N.current++}`,x.current.set(a,d)),d},[j,O]=r.useState(localStorage.getItem(`${i}_table_order_by`)||null),[$,P]=r.useState(localStorage.getItem(`${i}_table_order`)||null),[U,h]=r.useState(!1),[V,b]=r.useState(()=>{try{const a=localStorage.getItem(`${i}_column_visibility`);if(a)return JSON.parse(a)}catch{}return{}}),v=r.useMemo(()=>{const a={};for(const s of c)s.hidden||(a[s.id]=s.required?!0:V[s.id]!==!1);return a},[c,V]),w=r.useMemo(()=>{if(!j||!$)return o;const a=c.find(d=>d.id===j);if(!a||a.noSort)return o;const s=o.map((d,m)=>({el:d,index:m}));return s.sort((d,m)=>{let R;return typeof a.comparator=="function"?R=a.comparator(d.el,m.el):R=en(d.el,m.el,j),R!==0?$==="asc"?R:-R:d.index-m.index}),s.map(d=>d.el)},[o,j,$,c]),F=a=>{if(j!==a||!j){O(a),P("asc"),localStorage.setItem(`${i}_table_order_by`,a),localStorage.setItem(`${i}_table_order`,"asc");return}if($==="asc"){P("desc"),localStorage.setItem(`${i}_table_order`,"desc");return}O(null),P(null),localStorage.removeItem(`${i}_table_order_by`),localStorage.removeItem(`${i}_table_order`)},C=()=>{h(!U)},G=a=>{b(s=>{const d=c.find(pe=>pe.id===a);if(d&&d.required)return s;const m=v[a]!==!1,R={...s};m?R[a]=!1:delete R[a];try{localStorage.setItem(`${i}_column_visibility`,JSON.stringify(R))}catch{}return R})},A=()=>{b({});try{localStorage.removeItem(`${i}_column_visibility`)}catch{}h(!1)};return n&&console.log(`Rendering table ${i}${j&&$?` ordered by ${j}:${$}`:""}`),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(Ie,{open:U,onClose:(a,s)=>{s==="backdropClick"||s==="escapeKeyDown"||C()},disableEscapeKeyDown:!0,disableRestoreFocus:!0,children:[e.jsx(De,{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 ${i} columns`})]})}),e.jsx(Ne,{children:e.jsx(Cr,{children:c.filter(a=>!a.hidden).map(a=>e.jsx(Fe,{control:e.jsx(Te,{disabled:!!a.required,checked:a.required?!0:v[a.id]!==!1,onChange:()=>G(a.id)}),label:a.label},a.id))})}),e.jsxs(Oe,{children:[e.jsx(ae,{onClick:A,children:"Reset"}),e.jsx(ae,{variant:"contained",onClick:a=>{if(a?.currentTarget&&typeof a.currentTarget.blur=="function")try{a.currentTarget.blur()}catch{}const s=document.activeElement;if(s&&s instanceof HTMLElement&&typeof s.blur=="function")try{s.blur()}catch{}C()},children:"Close"})]})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between",borderBottom:"none"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:i}),u&&e.jsx("p",{className:"MbfWindowHeaderText",children:u}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(Q,{onClick:a=>{if(a?.currentTarget?.blur)try{a.currentTarget.blur()}catch{}C()},"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx(T,{title:`Configure ${i} columns`,children:e.jsx(re,{path:io,size:"20px",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":`${i} 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(a=>{if(a.hidden||!a.required&&v[a.id]===!1)return null;const s=!a.noSort,d=s&&j===a.id&&!!$;return e.jsxs("th",{onClick:s?()=>F(a.id):void 0,style:{margin:"0",padding:"5px 10px",position:"sticky",top:0,minWidth:a.minWidth,maxWidth:a.maxWidth,textAlign:a.align||"left",cursor:s?"pointer":"default",border:"none",color:"var(--header-text-color)",backgroundColor:"var(--header-bg-color)",whiteSpace:a.maxWidth?"nowrap":void 0,overflow:a.maxWidth?"hidden":void 0,textOverflow:a.maxWidth?"ellipsis":void 0},"aria-sort":s?d?$==="asc"?"ascending":"descending":"none":void 0,children:[a.label,d&&e.jsxs("span",{style:{marginLeft:6},children:[$==="asc"&&e.jsx(re,{path:so,size:"15px"}),$==="desc"&&e.jsx(re,{path:ao,size:"15px"})]})]},a.id)})})}),e.jsx("tbody",{children:w.map((a,s)=>{const d=p(a);return e.jsx("tr",{className:s%2===0?"table-content-even":"table-content-odd",onClick:t?m=>t(a,d,m):void 0,style:{height:"30px",minHeight:"30px",border:"none",borderCollapse:"collapse",cursor:t?"pointer":void 0},children:c.map(m=>{if(m.hidden||!m.required&&v[m.id]===!1)return null;const R=a[m.id];return e.jsx("td",{style:{border:"none",borderCollapse:"collapse",textAlign:m.align||"left",padding:"5px 10px",margin:"0",maxWidth:m.maxWidth,whiteSpace:m.maxWidth?"nowrap":void 0,overflow:m.maxWidth?"hidden":void 0,textOverflow:m.maxWidth?"ellipsis":void 0},children:typeof m.render=="function"?m.render(R,d,a,m):typeof R=="boolean"?e.jsx(Te,{checked:R,disabled:!0,size:"small",sx:{m:0,p:0,color:"var(--table-text-color)","&.Mui-disabled":{color:"var(--table-text-color)",opacity:.7}}}):m.format&&typeof R=="number"?m.format(R):R!=null?String(R):null},m.id)})},d)})})]})}),(y||g)&&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:y}),e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:g})]})]})}function rn(i){return r.memo(i)}const gt=rn(tn);function on({storeId:i,setStoreId:u}){const{online:c,sendMessage:o,addListener:l,removeListener:y,getUniqueId:g}=r.useContext(ge),{showConfirmCancelDialog:t}=r.useContext(Be),x=r.useRef(g()),[N,p]=r.useState(null),[j,O]=r.useState(null),[$,P]=r.useState([]),U=[{label:"Name",id:"name",required:!0,render:(M,E,W,D)=>e.jsx(T,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>a(W),children:W.name})})},{label:"Description",id:"description",render:(M,E,W,D)=>e.jsx(T,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>a(W),children:W.description})})},{label:"Version",id:"version",render:(M,E,W,D)=>e.jsxs(e.Fragment,{children:[W.latestVersion!==void 0&&W.latestVersion!==W.version&&j&&!j.readOnly&&e.jsx(T,{title:"New plugin stable version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>w(W),children:["Update to v.",W.latestVersion]})}),W.version.includes("-dev-")&&W.devVersion!==void 0&&W.devVersion!==W.version&&j&&!j.readOnly&&e.jsx(T,{title:"New plugin dev version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>F(W),children:["Update to new dev v.",W.devVersion.split("-dev-")[0]]})}),e.jsx(T,{title:"Plugin version",children:e.jsx("span",{children:W.version})})]})},{label:"Author",id:"author",render:(M,E,W,D)=>e.jsx(e.Fragment,{children:W.author?W.author.replace("https://github.com/",""):"Unknown"})},{label:"Type",id:"type",render:(M,E,W,D)=>e.jsx(e.Fragment,{children:W.type?W.type.replace("Platform",""):"Unknown"})},{label:"Devices",id:"registeredDevices"},{label:"Actions",id:"actions",required:!0,noSort:!0,render:(M,E,W,D)=>e.jsxs("div",{style:{margin:"0px",padding:"0px",gap:"4px",display:"flex",flexDirection:"row"},children:[j&&j.bridgeMode==="childbridge"&&!W.error&&W.enabled&&e.jsx(T,{title:"Shows the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:Qt(W.matter)},onClick:()=>{W.matter?.id&&u(W.matter?.id)},size:"small",children:e.jsx(At,{})})}),j&&j.bridgeMode==="childbridge"&&!W.error&&W.enabled&&e.jsx(T,{title:"Restart the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0",padding:"0",width:"19px",height:"19px"},onClick:()=>G(W),size:"small",children:e.jsx(dt,{})})}),e.jsx(T,{title:"Plugin config",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{disabled:W.restartRequired===!0,style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>ye(W),size:"small",children:e.jsx(vt,{})})}),j&&!j.readOnly&&e.jsx(T,{title:"Remove the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{V("Remove plugin","Are you sure? This will also remove all devices and configuration from the controller.","remove",W)},size:"small",children:e.jsx(ut,{})})}),W.enabled?e.jsx(T,{title:"Disable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>{V("Disable plugin","Are you sure? This will also remove all devices and configuration from the controller.","disable",W)},size:"small",children:e.jsx(wr,{})})}):e.jsx(e.Fragment,{}),W.enabled?e.jsx(e.Fragment,{}):e.jsx(T,{title:"Enable the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>A(W),size:"small",children:e.jsx(Sr,{})})}),e.jsx(T,{title:"Open the plugin help",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>d(W),size:"small",children:e.jsx(Mr,{})})}),e.jsx(T,{title:"Open the plugin version history",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>m(W),size:"small",children:e.jsx(kr,{})})}),j&&!j.readOnly&&e.jsx(T,{title:"Sponsor the plugin",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{style:{margin:"0",padding:"0",width:"19px",height:"19px",color:"#b6409c"},onClick:()=>s(W),size:"small",children:e.jsx(Vt,{})})})]})},{label:"Status",id:"status",required:!0,noSort:!0,render:(M,E,W,D)=>e.jsx("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",margin:"0",padding:"0",gap:"5px",width:"auto",maxWidth:"max-content"},children:W.error?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:!1,enabledText:"Error",disabledText:"Error",tooltipText:"The plugin is in error state. Check the log!"})}):e.jsx(e.Fragment,{children:W.enabled===!1?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:W.enabled,enabledText:"Enabled",disabledText:"Disabled",tooltipText:"Whether the plugin is enable or disabled"})}):e.jsx(e.Fragment,{children:W.loaded&&W.started&&W.configured?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:W.loaded,enabledText:"Running",tooltipText:"Whether the plugin is running"})}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{status:W.loaded,enabledText:"Loaded",tooltipText:"Whether the plugin has been loaded"}),e.jsx(Ee,{status:W.started,enabledText:"Started",tooltipText:"Whether the plugin started"}),e.jsx(Ee,{status:W.configured,enabledText:"Configured",tooltipText:"Whether the plugin has been configured"})]})})})})}];r.useEffect(()=>{const M=E=>{E.src==="Matterbridge"&&E.dst==="Frontend"&&(E.method==="refresh_required"&&E.response.changed==="plugins"&&(n&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and sending /api/plugins request`),o({id:x.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),E.method==="refresh_required"&&E.response.changed==="matter"&&(n&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and setting matter id ${E.response.matter?.id}`),P(W=>{const D=W.findIndex(L=>L.matter?.id===E.response.matter?.id);if(D<0)return n&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and matter id ${E.response.matter?.id} not found`),W;n&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} set matter id ${E.response.matter?.id}`);const S=[...W];return S[D]={...S[D],matter:E.response.matter},S})),E.method==="refresh_required"&&E.response.changed==="settings"&&(n&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and sending /api/settings request`),o({id:x.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),E.id===x.current&&E.method==="/api/settings"&&(n&&console.log(`HomePlugins (id: ${E.id}) received settings:`,E.response),p(E.response.systemInformation),O(E.response.matterbridgeInformation)),E.id===x.current&&E.method==="/api/plugins"&&(n&&console.log(`HomePlugins (id: ${E.id}) received ${E.response.length} plugins:`,E.response),P(E.response)))};return l(M,x.current),n&&console.log("HomePlugins added WebSocket listener id:",x.current),()=>{y(M),n&&console.log("HomePlugins removed WebSocket listener")}},[l,y,o]),r.useEffect(()=>{c&&(n&&console.log("HomePlugins sending api requests"),o({id:x.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),o({id:x.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,o]);const h=r.useRef(null),V=(M,E,W,D)=>{n&&console.log(`handleActionWithConfirmCancel ${W} ${D.name}`),h.current=D,t(M,E,W,b,v)},b=M=>{n&&console.log(`handleConfirm action confirmed ${M} ${h.current?.name}`),M==="remove"&&h.current?C(h.current):M==="disable"&&h.current&&A(h.current),h.current=null},v=M=>{n&&console.log(`handleCancel action canceled ${M} ${h.current?.name}`),h.current=null},w=M=>{n&&console.log("handleUpdatePlugin plugin:",M.name),o({id:x.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:M.name,restart:!1}})},F=M=>{n&&console.log("handleUpdateDevPlugin plugin:",M.name),o({id:x.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:M.name+"@dev",restart:!1}})},C=M=>{n&&console.log("handleRemovePlugin plugin:",M.name),o({id:x.current,sender:"HomePlugins",method:"/api/removeplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:M.name}})},G=M=>{n&&console.log("handleRestartPlugin plugin:",M.name),o({id:x.current,sender:"HomePlugins",method:"/api/restartplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:M.name}})},A=M=>{n&&console.log("handleEnableDisablePlugin plugin:",M.name,"enabled:",M.enabled),M.enabled===!0?(M.enabled=!1,o({id:x.current,sender:"HomePlugins",method:"/api/disableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:M.name}})):(M.enabled=!0,o({id:x.current,sender:"HomePlugins",method:"/api/enableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:M.name}}))},a=M=>{n&&console.log(`handleHomepagePlugin plugin: ${M.name} homepage: ${M.homepage}`),M.homepage&&window.open(M.homepage,"_blank")},s=M=>{n&&console.log("handleSponsorPlugin plugin:",M.name,"funding:",M.funding),M.funding&&window.open(M.funding,"_blank")},d=M=>{n&&console.log("handleHelpPlugin plugin:",M.name,"help:",M.help),M.help&&window.open(M.help,"_blank")},m=M=>{n&&console.log("handleChangelogPlugin plugin:",M.name,"changelog:",M.changelog),M.changelog&&window.open(M.changelog,"_blank")},[R,pe]=r.useState(),[Ce,we]=r.useState(!1),ye=M=>{n&&console.log("handleConfigPlugin plugin:",M.name),o({id:x.current,sender:"HomePlugins",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:M.name}}),o({id:x.current,sender:"HomePlugins",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:M.name}}),pe(M),X()},X=()=>{we(!0)},ie=()=>{we(!1)};return n&&console.log("HomePlugins rendering..."),c?e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"0 0 auto",overflow:"hidden"},children:[R&&e.jsx(Zo,{open:Ce,onClose:ie,plugin:R}),e.jsx(gt,{name:"Plugins",columns:U,rows:$,footerRight:"",footerLeft:""})]}):e.jsx($e,{})}const nn=r.memo(on),sn=i=>`${i.pluginName}::${i.serial}`;function an({storeId:i,setStoreId:u}){const{online:c,sendMessage:o,addListener:l,removeListener:y,getUniqueId:g}=r.useContext(ge),[t,x]=r.useState(!1),[N,p]=r.useState(!0),[j,O]=r.useState(null),[$,P]=r.useState([]),[U,h]=r.useState([]),[V,b]=r.useState([]),[v,w]=r.useState([]),F=r.useRef(g()),C=[{label:"Plugin",id:"pluginName"},{label:"Name",id:"name",required:!0},{label:"Serial",id:"serial"},{label:"Availability",id:"availability",render:(a,s,d,m)=>d.reachable===!0?"Online":d.reachable===!1?e.jsx("span",{style:{color:"red"},children:"Offline"}):"",comparator:(a,s)=>{const d=a.reachable===!0?1:a.reachable===!1?0:-1,m=s.reachable===!0?1:s.reachable===!1?0:-1;return d-m}},{label:"Power",id:"powerSource",render:(a,s,d,m)=>d.powerSource==="ac"||d.powerSource==="dc"?e.jsx(_t,{fontSize:"small",sx:{color:"var(--primary-color)"}}):d.powerSource==="ok"?e.jsx(pt,{fontSize:"small",sx:{color:"green"}}):d.powerSource==="warning"?e.jsx(pt,{fontSize:"small",sx:{color:"yellow"}}):d.powerSource==="critical"?e.jsx(pt,{fontSize:"small",sx:{color:"red"}}):e.jsx("span",{})},{label:"Url",id:"configUrl"},{label:"Actions",id:"selected",required:!0,render:(a,s,d,m)=>e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[d.matter!==void 0?e.jsx(T,{title:"Show the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{onClick:()=>u(i===d.matter?.id?j?.matterbridgeInformation.bridgeMode==="bridge"?"Matterbridge":null:d.matter?.id||null),"aria-label":"Show the QRCode",sx:{margin:0,padding:0,color:Qt(d.matter)},children:e.jsx(At,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),d.configUrl?e.jsx(T,{title:"Open the configuration page",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{onClick:()=>window.open(d.configUrl,"_blank"),"aria-label":"Open config url",sx:{margin:0,padding:0},children:e.jsx(vt,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),d.selected!==void 0?e.jsx(T,{title:"Select/unselect the device",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Te,{checked:d.selected,onChange:R=>A(R,d),sx:{margin:"0",marginLeft:"8px",padding:"0"},size:"small"})}):e.jsx("div",{style:{width:"20px",height:"20px"}})]})}],G=r.useCallback(a=>{a.selected=void 0;const s=$.find(R=>R.name===a.pluginName);if(!s)return console.error(`HomeDevices isSelected: plugin ${a.pluginName} not found for device ${a.name} `),a.selected;const d=s.schemaJson?.properties?.whiteList?.selectFrom;let m=s.configJson.postfix;return m===""&&(m=void 0),s.hasWhiteList===!0&&s.hasBlackList===!0&&d&&(a.selected=!0,d==="serial"&&s.configJson.whiteList&&s.configJson.whiteList.length>0&&s.configJson.whiteList.includes(m?a.serial.replace("-"+m,""):a.serial)&&(a.selected=!0),d==="serial"&&s.configJson.whiteList&&s.configJson.whiteList.length>0&&!s.configJson.whiteList.includes(m?a.serial.replace("-"+m,""):a.serial)&&(a.selected=!1),d==="serial"&&s.configJson.blackList&&s.configJson.blackList.length>0&&s.configJson.blackList.includes(m?a.serial.replace("-"+m,""):a.serial)&&(a.selected=!1),d==="name"&&s.configJson.whiteList&&s.configJson.whiteList.length>0&&s.configJson.whiteList.includes(a.name)&&(a.selected=!0),d==="name"&&s.configJson.whiteList&&s.configJson.whiteList.length>0&&!s.configJson.whiteList.includes(a.name)&&(a.selected=!1),d==="name"&&s.configJson.blackList&&s.configJson.blackList.length>0&&s.configJson.blackList.includes(a.name)&&(a.selected=!1)),a.selected},[$]);r.useEffect(()=>{const a=s=>{if(s.method==="refresh_required"&&s.response.changed!=="matter"&&(n&&console.log(`HomeDevices received refresh_required: changed=${s.response.changed} and sending /api/plugins request`),o({id:F.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),s.method==="refresh_required"&&s.response.changed==="matter"&&(n&&console.log(`HomeDevices received refresh_required: changed=${s.response.changed} and setting matter id ${s.response.matter?.id}`),w(d=>{const m=d.findIndex(pe=>pe.name.replaceAll(" ","")===s.response.matter?.id);if(m<0)return n&&console.debug(`HomeDevices: matter id ${s.response.matter?.id} not found`),d;const R=[...d];return R[m]={...R[m],matter:s.response.matter},n&&console.log(`HomeDevices received refresh_required: changed=${s.response.changed} and set matter id ${s.response.matter?.id}`),R})),s.method==="restart_required"&&(n&&console.log("HomeDevices received restart_required"),x(!0)),s.method==="restart_not_required"&&(n&&console.log("HomeDevices received restart_not_required"),x(!1)),s.method==="state_update"&&s.response.plugin&&s.response.serialNumber&&s.response.cluster.includes("BasicInformationServer")&&s.response.attribute==="reachable"&&(console.log(`HomeDevices updating device reachability for plugin ${s.response.plugin} serial ${s.response.serialNumber} value ${s.response.value}`),h(d=>d.map(m=>m.pluginName===s.response.plugin&&m.serial===s.response.serialNumber?{...m,reachable:s.response.value}:m))),s.id===F.current&&s.method==="/api/settings"&&(n&&console.log(`HomeDevices (id: ${s.id}) received settings:`,s.response),O(s.response),x(s.response.matterbridgeInformation.restartRequired||s.response.matterbridgeInformation.fixedRestartRequired)),s.id===F.current&&s.method==="/api/plugins"&&(n&&console.log(`HomeDevices (id: ${s.id}) received ${s.response?.length} plugins:`,s.response),s.response)){let d=!0;for(const m of s.response)m.enabled===!0&&(m.loaded!==!0||m.started!==!0||m.error===!0)&&(d=!1);if(!d)return;n&&console.log("HomeDevices reset plugins, devices and selectDevices"),p(!1),P(s.response),h([]),b([]),o({id:F.current,sender:"HomeDevices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}),n&&console.log("HomeDevices sent /api/devices");for(const m of s.response)m.enabled===!0&&m.loaded===!0&&m.started===!0&&m.error!==!0&&(o({id:F.current,sender:"HomeDevices",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:m.name}}),n&&console.log(`HomeDevices sent /api/select/devices for plugin: ${m.name}`))}if(s.id===F.current&&s.method==="/api/devices"&&(n&&console.log(`HomeDevices (id: ${s.id}) received ${s.response?.length} devices:`,s.response),s.response)){for(const d of s.response)d.selected=G(d);h(s.response)}s.id===F.current&&s.method==="/api/select/devices"&&(n&&console.log(`HomeDevices (id: ${s.id}) received ${s.response?.length} selectDevices for plugin ${s.response&&s.response.length>0?s.response[0].pluginName:"without select devices"}:`,s.response),s.response&&s.response.length>0&&b(d=>{const m=d.filter(pe=>pe.pluginName!==s.response[0].pluginName),R=s.response.map(pe=>({...pe,selected:G(pe)}));return[...m,...R]}))};return l(a,F.current),n&&console.log(`HomeDevices added WebSocket listener id ${F.current}`),()=>{y(a),n&&console.log("HomeDevices removed WebSocket listener")}},[$,l,y,o,G]),r.useEffect(()=>{if(U.length===0&&V.length===0){w([]);return}n&&console.log(`HomeDevices mixing devices (${U.length}) and selectDevices (${V.length})`);const a=[];for(const s of U)a.push(s);for(const s of V)U.find(d=>d.pluginName===s.pluginName&&d.serial.includes(s.serial))||a.push(s);a.length>0&&(w(a),console.log(`HomeDevices mixed ${a.length} devices and selectDevices`))},[$,U,V,w]),r.useEffect(()=>{c&&(n&&console.log("HomeDevices sending /api/settings and /api/plugins requests"),o({id:F.current,sender:"HomeDevices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),o({id:F.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,o]);const A=(a,s)=>{console.log(`handleCheckboxChange: checkbox changed to ${a.target.checked} for device ${s.name} serial ${s.serial}`),h(d=>{const m=d.findIndex(pe=>pe.pluginName===s.pluginName&&pe.serial===s.serial);if(m<0)return console.error(`handleCheckboxChange: device not found ${s.name} serial ${s.serial}`),d;const R=[...d];return R[m]={...R[m],selected:a.target.checked},R}),a.target.checked?o({id:F.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"selectdevice",plugin:s.pluginName,serial:s.serial,name:s.name}}):o({id:F.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"unselectdevice",plugin:s.pluginName,serial:s.serial,name:s.name}})};return n&&console.log("HomeDevices rendering..."),c?e.jsx("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",overflow:"hidden"},children:e.jsx(gt,{name:"Devices",getRowKey:sn,rows:v,columns:C,footerLeft:N?"Waiting for the plugins to fully load...":`Registered devices: ${U.length.toString()}/${v.length.toString()}`,footerRight:t?"Restart required":""})}):e.jsx($e,{})}const ln=r.memo(an);function dn(){const[i,u]=r.useState(null),[c,o]=r.useState(null),[l,y]=r.useState([]),[g]=r.useState(localStorage.getItem("homePagePlugins")!=="false"),[t,x]=r.useState(localStorage.getItem("homePageMode")??"devices"),[N,p]=r.useState(""),[j,O]=r.useState(!1),[$,P]=r.useState(!1),[U,h]=r.useState(null),{addListener:V,removeListener:b,online:v,sendMessage:w,logFilterLevel:F,logFilterSearch:C,autoScroll:G,getUniqueId:A}=r.useContext(ge),a=r.useRef(A());return r.useEffect(()=>{const s=d=>{d.src==="Matterbridge"&&d.dst==="Frontend"&&(d.method==="refresh_required"&&d.response.changed==="settings"&&(n&&console.log(`Home received refresh_required: changed=${d.response.changed} and sending /api/settings request`),h(null),y([]),w({id:a.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),w({id:a.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),d.method==="/api/settings"&&d.id===a.current&&(n&&console.log("Home received settings:",d.response),u(d.response.systemInformation),o(d.response.matterbridgeInformation),d.response.matterbridgeInformation.bridgeMode==="bridge"&&(U||h("Matterbridge")),d.response.matterbridgeInformation.bridgeMode==="childbridge"&&l.length>0&&U===null&&!U&&l.length>0&&l[0].matter?.id&&h(l[0].matter.id),d.response.matterbridgeInformation.matterbridgeVersion&&p(`https://github.com/Luligu/matterbridge/blob/${d.response.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?"dev":"main"}/CHANGELOG.md`),localStorage.getItem("frontendVersion")===null&&d.response.matterbridgeInformation.frontendVersion?localStorage.setItem("frontendVersion",d.response.matterbridgeInformation.frontendVersion):d.response.matterbridgeInformation.frontendVersion!==localStorage.getItem("frontendVersion")&&d.response.matterbridgeInformation.frontendVersion&&(localStorage.setItem("frontendVersion",d.response.matterbridgeInformation.frontendVersion),P(!0)),localStorage.getItem("matterbridgeVersion")===null?localStorage.setItem("matterbridgeVersion",d.response.matterbridgeInformation.matterbridgeVersion):d.response.matterbridgeInformation.matterbridgeVersion!==localStorage.getItem("matterbridgeVersion")&&(localStorage.setItem("matterbridgeVersion",d.response.matterbridgeInformation.matterbridgeVersion),O(!0)),d.response.matterbridgeInformation.shellyBoard&&(localStorage.getItem("homePageMode")||(localStorage.setItem("homePageMode","devices"),x("devices")))),d.method==="/api/plugins"&&d.id===a.current&&(n&&console.log(`Home received plugins (${c?.bridgeMode}):`,d.response),y(d.response),c?.bridgeMode==="childbridge"&&d.response.length>0&&!U&&d.response.length>0&&d.response[0].matter?.id&&h(d.response[0].matter.id)))};return V(s,a.current),n&&console.log(`Home added WebSocket listener id ${a.current}`),()=>{b(s),n&&console.log("Home removed WebSocket listener")}},[V,b,w,c,l,U]),r.useEffect(()=>{v&&(n&&console.log("Home received online"),w({id:a.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),w({id:a.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[v,w]),n&&console.log("Home rendering..."),!v||!i||!c?e.jsx($e,{}):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(Qo,{id:U}),e.jsx(zo,{systemInfo:i,compact:!0})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",gap:"20px"},children:[$&&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(ae,{onClick:()=>window.location.reload(),endIcon:e.jsx(Ir,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Refresh"})})]})]}),j&&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(ae,{onClick:()=>window.open(N,"_blank"),endIcon:e.jsx(Et,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Changelog"}),e.jsx(ae,{onClick:()=>window.location.reload(),endIcon:e.jsx(Dr,{}),style:{marginLeft:"10px",color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Close"})]})]})]}),g&&!c.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(Jo,{})]}),g&&e.jsx(nn,{storeId:U,setStoreId:h}),t==="devices"&&e.jsx(ln,{storeId:U,setStoreId:h}),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 "',F,'" and search "',C,'" Scroll: ',G?"auto":"manual"]})})]}),e.jsx("div",{style:{flex:"1 1 auto",margin:"0px",padding:"10px",overflow:"auto"},children:e.jsx(Bt,{})})]})]})]})}const cn=r.memo(dn),Ht={display:"flex",gap:"2px",justifyContent:"space-evenly",width:"100%",height:"40px"},pn={margin:"0",padding:"0",fontSize:"36px",fontWeight:"medium",color:"var(--primary-color)"},un={margin:"0",padding:"0",fontSize:"20px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},Ot={margin:"0",padding:"0",paddingBottom:"2px",fontSize:"16px",fontWeight:"medium",color:"var(--div-text-color)",textAlign:"center"},mn={display:"flex",gap:"2px",justifyContent:"center",width:"100%",height:"18px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},gn={margin:"0",padding:"0",fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)"},hn={display:"flex",justifyContent:"center",width:"100%",height:"52px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},fn={margin:"0",padding:"0",fontSize:"14px",fontWeight:"bold",color:"var(--div-text-color)"},xn={display:"flex",gap:"4px",justifyContent:"center",width:"100%",height:"15px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},bt={margin:"0",padding:"0px 4px",borderRadius:"5px",textAlign:"center",fontSize:"12px",fontWeight:"normal",color:"var(--secondary-color)"},bn=[256,257,268,269],vn=[266,267],yn=[259,260,261,271,272],jn=[256,257,268,269,266,267,259,260,261];function q({icon:i,iconColor:u,cluster:c,value:o,unit:l,prefix:y}){return n&&console.log(`Render cluster "${c.clusterName}.${c.attributeName}" value(${typeof o}-${isNaN(o)}) "${o}" unit "${l}"`),y=y??!1,e.jsxs(Y,{sx:Ht,children:[i&&r.cloneElement(i,{key:`${c.clusterId}-${c.attributeId}-icon`,sx:{...pn,color:u??"var(--primary-color)"}}),e.jsxs(Y,{sx:{...Ht,gap:"4px",alignContent:"center",alignItems:"end",justifyContent:"center"},children:[l&&y===!0&&e.jsx(se,{sx:Ot,children:l},`${c.clusterId}-${c.attributeId}-unit`),e.jsx(se,{sx:un,children:o==null||typeof o=="number"&&isNaN(o)||o==="NaN"?"---":o},`${c.clusterId}-${c.attributeId}-value`),l&&y===!1&&e.jsx(se,{sx:Ot,children:l},`${c.clusterId}-${c.attributeId}-unit`)]},`${c.clusterId}-${c.attributeId}-valueunitbox`)]},`${c.clusterId}-${c.attributeId}-box`)}function Cn({device:i,endpoint:u,id:c,deviceType:o,clusters:l}){const y=["Unknown","Good","Fair","Moderate","Poor","VeryPoor","Ext.Poor"];let g="";return n&&console.log(`Device "${i.name}" endpoint "${u}" id "${c}" deviceType "0x${o.toString(16).padStart(4,"0")}" clusters (${l?.length}):`,l),o===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batVoltage").map(t=>g=`${t.attributeLocalValue} mV`),jn.includes(o)&&l.filter(t=>t.clusterName==="LevelControl"&&t.attributeName==="currentLevel").map(t=>g=`Level ${t.attributeValue}`),o===514&&l.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>g=`Position ${t.attributeLocalValue/100}%`),o===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedHeatingSetpoint").map(t=>g=`Heat ${t.attributeLocalValue/100}°C `),o===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedCoolingSetpoint").map(t=>g=g+`Cool ${t.attributeLocalValue/100}°C`),o===118&&l.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>g=`${t.attributeLocalValue===0?"No CO detected":"CO alarm!"}`),o===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="voltage").map(t=>g=`${t.attributeLocalValue/1e3} V, `),o===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activeCurrent").map(t=>g=g+`${t.attributeLocalValue/1e3} A, `),o===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activePower").map(t=>g=g+`${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:[o===19&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:t.attributeLocalValue===!0?e.jsx(Ge,{}):e.jsx(Nr,{}),iconColor:t.attributeLocalValue===!0?"green":"red",cluster:t,value:t.attributeLocalValue===!0?"Online":"Offline"})),o===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batPercentRemaining").map(t=>e.jsx(q,{icon:e.jsx(pt,{}),cluster:t,value:t.attributeLocalValue/2,unit:"%"})),o===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="wiredCurrentType").map(t=>e.jsx(q,{icon:e.jsx(_t,{}),cluster:t,value:t.attributeLocalValue===0?"AC":"DC"})),o===1293&&l.filter(t=>t.clusterName==="DeviceEnergyManagement"&&t.attributeName==="esaState").map(t=>e.jsx(q,{icon:e.jsx(re,{path:lo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Offline":"Online"})),bn.includes(o)&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(q,{icon:e.jsx(Pr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),vn.includes(o)&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(q,{icon:e.jsx(re,{path:co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),yn.includes(o)&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(q,{icon:e.jsx(re,{path:po,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),o===115&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(q,{icon:e.jsx(re,{path:uo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),o===124&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(q,{icon:e.jsx(re,{path:mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),o===117&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(q,{icon:e.jsx(re,{path:go,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),o===123&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(Dt,{}),cluster:t,value:"Oven"})),o===112&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(Wr,{}),cluster:t,value:"Fridge"})),o===113&&l.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(q,{icon:e.jsx(re,{path:ho,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),o===121&&l.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(q,{icon:e.jsx(Dt,{}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),o===122&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="fanMode").map(t=>e.jsx(q,{icon:e.jsx(re,{path:fo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),o===120&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(re,{path:Ft,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Cooktop"})),o===119&&l.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(q,{icon:e.jsx(re,{path:Ft,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),o===116&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(re,{path:xo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Robot"})),o===514&&l.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>e.jsx(q,{icon:e.jsx(Lr,{}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),o===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(q,{icon:e.jsx(re,{path:bo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),o===10&&l.filter(t=>t.clusterName==="DoorLock"&&t.attributeName==="lockState").map(t=>e.jsx(q,{icon:t.attributeValue==="1"?e.jsx(Fr,{}):e.jsx(Tr,{}),cluster:t,value:t.attributeValue==="1"?"Locked":"Unlocked"})),o===43&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(q,{icon:e.jsx($r,{}),cluster:t,value:t.attributeValue,unit:"%"})),o===15&&l.filter(t=>t.clusterName==="Switch"&&t.attributeName==="currentPosition").map(t=>e.jsx(q,{icon:e.jsx(re,{path:vo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeValue,unit:"pos",prefix:!0})),o===39&&l.filter(t=>t.clusterName==="ModeSelect"&&t.attributeName==="currentMode").map(t=>e.jsx(q,{icon:e.jsx(Rr,{}),cluster:t,value:t.attributeValue,unit:"mode",prefix:!0})),o===771&&l.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(q,{icon:e.jsx(Hr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),o===45&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(q,{icon:e.jsx(Nt,{}),cluster:t,value:t.attributeValue,unit:"%"})),o===114&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(q,{icon:e.jsx(Nt,{}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),o===67&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(q,{icon:e.jsx(Or,{}),cluster:t,value:t.attributeLocalValue===!0?"Leak":"No leak"})),o===65&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(q,{icon:e.jsx(Vr,{}),cluster:t,value:t.attributeLocalValue===!0?"Freeze":"No freeze"})),o===68&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(q,{icon:e.jsx(Er,{}),cluster:t,value:t.attributeLocalValue===!0?"Rain":"No rain"})),o===1292&&l.filter(t=>t.clusterName==="EnergyEvse"&&t.attributeName==="state").map(t=>e.jsx(q,{icon:e.jsx(re,{path:yo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Free":"In use"})),o===1295&&l.filter(t=>t.clusterName==="WaterHeaterManagement"&&t.attributeName==="tankPercentage").map(t=>e.jsx(q,{icon:e.jsx(re,{path:jo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Tank "+(t.attributeLocalValue??0)+"%"})),o===777&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(q,{icon:e.jsx(re,{path:Co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"HeatPump"})),o===23&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(q,{icon:e.jsx(re,{path:wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Solar"})),o===24&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="featureMap").map(t=>e.jsx(q,{icon:e.jsx(re,{path:So,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Inverter"})),o===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(q,{icon:e.jsx(re,{path:Tt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No smoke":"Smoke!"})),o===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(q,{icon:e.jsx(re,{path:Tt,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No Co":"Co!"})),o===66&&l.filter(t=>t.clusterName==="ValveConfigurationAndControl"&&t.attributeName==="currentState").map(t=>e.jsx(q,{icon:e.jsx(Ar,{}),cluster:t,value:t.attributeLocalValue===0?"Closed":"Opened"})),o===44&&l.filter(t=>t.clusterName==="AirQuality"&&t.attributeName==="airQuality").map(t=>e.jsx(q,{icon:e.jsx(re,{path:Mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:y[t.attributeLocalValue??0]})),o===770&&l.filter(t=>t.clusterName==="TemperatureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(q,{icon:e.jsx(_r,{}),cluster:t,value:t.attributeLocalValue/100,unit:"°C"})),o===775&&l.filter(t=>t.clusterName==="RelativeHumidityMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(q,{icon:e.jsx(re,{path:ko,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),o===774&&l.filter(t=>t.clusterName==="FlowMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(q,{icon:e.jsx(qr,{}),cluster:t,value:t.attributeLocalValue,unit:"l/h"})),o===773&&l.filter(t=>t.clusterName==="PressureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(q,{icon:e.jsx(zr,{}),cluster:t,value:t.attributeLocalValue,unit:"hPa"})),o===21&&l.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(q,{icon:t.attributeValue==="true"?e.jsx(Ur,{}):e.jsx(Br,{}),cluster:t,value:t.attributeValue==="true"?"Closed":"Opened"})),o===263&&l.filter(t=>t.clusterName==="OccupancySensing"&&t.attributeName==="occupancy").map(t=>e.jsx(q,{icon:t.attributeValue==="{ occupied: true }"?e.jsx(Qr,{}):e.jsx(Kr,{}),cluster:t,value:t.attributeValue==="{ occupied: true }"?"Occupied":"Unocc."})),o===262&&l.filter(t=>t.clusterName==="IlluminanceMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(q,{icon:e.jsx(Jr,{}),cluster:t,value:Math.round(Math.pow(10,t.attributeLocalValue/1e4)),unit:"lx"})),o===1296&&l.filter(t=>t.clusterName==="ElectricalEnergyMeasurement"&&t.attributeName==="cumulativeEnergyImported").map(t=>e.jsx(q,{icon:e.jsx(Gr,{}),cluster:t,value:Math.round(t.attributeLocalValue?.energy/1e6),unit:"kwh"})),e.jsx(Y,{sx:mn,children:e.jsx(se,{sx:gn,children:g})}),e.jsx(Y,{sx:hn,children:e.jsx(se,{sx:fn,children:i.name})}),e.jsxs(Y,{sx:xn,children:[n&&e.jsx(se,{sx:bt,children:u}),e.jsx(se,{sx:bt,children:c}),n&&e.jsxs(se,{sx:bt,children:["0x",o.toString(16).padStart(4,"0")]})]})]})}function wn({filter:i}){const{online:u,sendMessage:c,addListener:o,removeListener:l,getUniqueId:y}=r.useContext(ge),[g,t]=r.useState(null),[x,N]=r.useState([]),[p,j]=r.useState([]),[O,$]=r.useState(p),[P,U]=r.useState({}),[h,V]=r.useState({}),[b,v]=r.useState({}),w=r.useRef(y()),F=r.useRef(O),C=r.useCallback(A=>{console.log("DevicesIcons received state_update:",A.response);const a=F.current.find(d=>d.pluginName===A.response.plugin&&d.uniqueId===A.response.uniqueId);if(!a)return;console.log(`DevicesIcons found device "${a.name}" serial "${a.serial}"`);const s=b[a.serial].find(d=>d.clusterName+"Server"===A.response.cluster&&d.attributeName===A.response.attribute);console.log(`DevicesIcons found device "${a.name}" serial "${a.serial}" with cluster:`,s),s&&(s.attributeValue=String(A.response.value),s.attributeLocalValue=A.response.value,v({...b}),console.log(`DevicesIcons updated attribute ${s.clusterName}:${s.attributeName} for device "${a.name}" serial "${a.serial}" to "${s.attributeValue}"`))},[b]);r.useEffect(()=>{const A=a=>{if(a.method==="refresh_required")n&&console.log(`DevicesIcons received refresh_required: changed=${a.response.changed} and sending api requests`),c({id:w.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:w.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:w.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}});else if(a.method==="state_update"&&a.response)C(a);else if(a.method==="/api/settings"&&a.response)n&&console.log("DevicesIcons received settings:",a.response),t(a.response);else if(a.method==="/api/plugins"&&a.response)n&&console.log("DevicesIcons received plugins:",a.response),N(a.response);else if(a.method==="/api/devices"&&a.response){n&&console.log(`DevicesIcons received ${a.response.length} devices:`,a.response),j(a.response);for(const s of a.response)n&&console.log("DevicesIcons sending /api/clusters"),c({id:w.current,sender:"DevicesIcons",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:s.pluginName,endpoint:s.endpoint||0}})}else if(a.method==="/api/clusters"&&a.response){if(n&&console.log(`DevicesIcons received for device "${a.response.deviceName}" serial "${a.response.serialNumber}" deviceType ${a.response.deviceTypes.join(" ")} clusters (${a.response.clusters.length}):`,a.response),a.response.clusters.length===0)return;const s=a.response.serialNumber;P[s]=[],h[s]=a.response.deviceTypes,b[s]=[];for(const d of a.response.clusters)P[s].find(m=>m.endpoint===d.endpoint)||P[s].push({endpoint:d.endpoint,id:d.id,deviceTypes:d.deviceTypes}),!["FixedLabel","Descriptor","Identify","Groups","PowerTopology"].includes(d.clusterName)&&b[s].push(d);U({...P}),V({...h}),v({...b}),n&&console.log(`DevicesIcons endpoints for "${s}":`,P[s]),n&&console.log(`DevicesIcons deviceTypes for "${s}":`,h[s]),n&&console.log(`DevicesIcons clusters for "${s}":`,b[s])}};return o(A,w.current),n&&console.log("DevicesIcons useEffect webSocket mounted"),()=>{l(A),n&&console.log("DevicesIcons useEffect webSocket unmounted")}},[]),r.useEffect(()=>(n&&console.log("DevicesIcons useEffect online mounting"),u&&(n&&console.log("DevicesIcons useEffect online sending api requests"),c({id:w.current,sender:"DevicesIcons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:w.current,sender:"DevicesIcons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:w.current,sender:"DevicesIcons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),n&&console.log("DevicesIcons useEffect online mounted"),()=>{n&&console.log("DevicesIcons useEffect online unmounted")}),[u,c]),r.useEffect(()=>{if(i===""){$(p),F.current=p;return}const A=p.filter(a=>a.name.toLowerCase().includes(i)||a.serial.toLowerCase().includes(i));$(A),F.current=A},[p,i]);const G=r.memo(Cn);return n&&console.log("DevicesIcons rendering..."),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"auto"},children:O.map(A=>P[A.serial]&&P[A.serial].map(a=>a.deviceTypes.map(s=>e.jsx(G,{device:A,endpoint:a.endpoint,id:a.id,deviceType:s,clusters:b[A.serial].filter(d=>d.endpoint===a.endpoint)},`${A.pluginName}-${A.uniqueId}-${a.id}-${s.toString()}`))))})}const Sn=r.memo(wn),Mn=[{label:"Plugin name",id:"pluginName",required:!0},{label:"Device type",id:"type"},{label:"Endpoint",id:"endpoint",align:"right"},{label:"Name",id:"name",required:!0},{label:"Serial number",id:"serial"},{label:"Unique ID",id:"uniqueId"},{label:"Url",id:"configUrl"},{label:"Config",id:"configButton",noSort:!0,render:(i,u,c,o)=>c.configUrl?e.jsx(Q,{onClick:()=>window.open(c.configUrl,"_blank"),"aria-label":"Open Config",sx:{margin:0,padding:0},children:e.jsx(vt,{fontSize:"small"})}):null},{label:"Cluster",id:"cluster"}],kn=[{label:"Endpoint",id:"endpoint",required:!0},{label:"Id",id:"id"},{label:"Device Types",id:"deviceTypes",render:(i,u,c,o)=>Array.isArray(i)?e.jsx(e.Fragment,{children:i.map(l=>`0x${l.toString(16).padStart(4,"0")}`).join(", ")}):e.jsx(e.Fragment,{children:i})},{label:"Cluster Name",id:"clusterName",required:!0},{label:"Cluster ID",id:"clusterId"},{label:"Attribute Name",id:"attributeName",required:!0},{label:"Attribute ID",id:"attributeId"},{label:"Attribute Value",id:"attributeValue",required:!0,render:(i,u,c,o)=>e.jsx(T,{title:String(i),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:String(i)})})}],In=i=>`${i.pluginName}::${i.uniqueId}`,Dn=i=>`${i.endpoint}::${i.clusterName}::${i.attributeName}`;function Nn({filter:i}){const{online:u,sendMessage:c,addListener:o,removeListener:l,getUniqueId:y}=r.useContext(ge),[g,t]=r.useState([]),[x,N]=r.useState(g),[p,j]=r.useState([]),[O,$]=r.useState(0),[P,U]=r.useState(null),[h,V]=r.useState(null),[b,v]=r.useState(null),[w,F]=r.useState(null),C=r.useRef(y()),G=r.useRef(x),A=r.useCallback(s=>{console.log("DevicesTable received state_update:",s.response);const d=G.current.find(m=>m.pluginName===s.response.plugin&&m.uniqueId===s.response.uniqueId);if(d&&(console.log(`DevicesTable found device "${d.name}" serial "${d.serial}"`),P&&h)){const m=p.find(R=>R.clusterName+"Server"===s.response.cluster&&R.attributeName===s.response.attribute);if(console.log(`DevicesTable found device "${d.name}" serial "${d.serial}" with cluster:`,m),!m)return;m.attributeValue=String(s.response.value),m.attributeLocalValue=s.response.value,j([...p]),console.log(`DevicesTable updated attribute ${m.clusterName}:${m.attributeName} for device "${d.name}" serial "${d.serial}" to "${m.attributeValue}"`)}},[p,h,P]);r.useEffect(()=>{const s=d=>{if(n&&console.log("DevicesTable received WebSocket Message:",d),d.method==="refresh_required"&&d.response.changed==="devices")n&&console.log(`DevicesTable received refresh_required: changed=${d.response.changed} and sending /api/devices request`),c({id:C.current,sender:"DevicesTable",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}});else if(d.method==="state_update"&&d.response)A(d);else if(d.method==="/api/devices")n&&console.log(`DevicesTable received ${d.response.length} devices:`,d.response),t(d.response);else if(d.method==="/api/clusters"){n&&console.log(`DevicesTable received ${d.response.clusters.length} clusters for plugin ${d.response.plugin}:`,d.response),j(d.response.clusters);const m={};for(const R of d.response.clusters)n&&console.log("Cluster:",R.endpoint),m[R.endpoint]?m[R.endpoint]++:m[R.endpoint]=1;$(Object.keys(m).length)}};return o(s,C.current),n&&console.log("DevicesTable added WebSocket listener"),()=>{l(s),n&&console.log("DevicesTable removed WebSocket listener")}},[c,o,l,A]),r.useEffect(()=>{u&&(n&&console.log("DevicesTable sending api requests with id ",C.current),c({id:C.current,sender:"DevicesTable",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:C.current,sender:"DevicesTable",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:C.current,sender:"DevicesTable",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}))},[u,c]),r.useEffect(()=>{P&&h&&(n&&console.log("DevicesTable sending /api/clusters"),c({id:C.current,sender:"DevicesTable",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:P,endpoint:Number(h)}}))},[P,h,c]),r.useEffect(()=>{if(i===""){N(g),G.current=g;return}const s=g.filter(d=>d.name.toLowerCase().includes(i)||d.serial.toLowerCase().includes(i));N(s),G.current=s},[g,i]);const a=s=>{if(s.uniqueId===w){F(null),U(null),V(null),v(null);return}F(s.uniqueId),U(s.pluginName),V(s.endpoint?s.endpoint.toString():null),v(s.name)};return n&&console.log("DevicesTable rendering..."),u?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowDiv",style:{margin:"0",padding:"0",gap:"0",maxHeight:`${P&&h?"50%":"100%"}`,width:"100%",flex:"1 1 auto",overflow:"hidden"},children:e.jsx(gt,{name:"Registered devices",getRowKey:In,onRowClick:a,rows:x,columns:Mn,footerLeft:`Total devices: ${x.length.toString()}`})}),P&&h&&e.jsx("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(gt,{name:"Clusters",title:b||"",getRowKey:Dn,rows:p,columns:kn,footerLeft:`Total child endpoints: ${O-1}`})})]}):e.jsx($e,{})}const Pn=r.memo(Nn);function Wn(){const{online:i}=r.useContext(ge),[u,c]=r.useState(""),[o,l]=r.useState("icon");r.useEffect(()=>{const t=localStorage.getItem("devicesFilter");t&&c(t)},[]),r.useEffect(()=>{const t=localStorage.getItem("devicesViewMode");t&&l(t)},[]);const y=t=>{c(t.target.value.toLowerCase()),localStorage.setItem("devicesFilter",t.target.value.toLowerCase())},g=t=>{l(t),localStorage.setItem("devicesViewMode",t)};return n&&console.log("Devices rendering..."),i?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(Y,{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(de,{variant:"outlined",value:u,onChange:y,placeholder:"Enter the device name or serial number",sx:{width:"320px"},InputProps:{style:{backgroundColor:"var(--main-bg-color)"}}})]}),e.jsxs(Y,{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(Q,{onClick:()=>g("table"),"aria-label":"Table View",disabled:o==="table",children:e.jsx(T,{title:"Table View",children:e.jsx(Yr,{style:{color:o==="table"?"var(--main-icon-color)":"var(--primary-color)"}})})}),e.jsx(Q,{onClick:()=>g("icon"),"aria-label":"Icon View",disabled:o==="icon",children:e.jsx(T,{title:"Icon View (beta)",children:e.jsx(Xr,{style:{color:o==="icon"?"var(--main-icon-color)":"var(--primary-color)"}})})})]})]}),o==="table"&&e.jsx(Pn,{filter:u}),o==="icon"&&e.jsx(Sn,{filter:u})]}):e.jsx($e,{})}const Ln=r.memo(Wn);function Fn(){const[i,u]=r.useState(localStorage.getItem("logFilterLevel")??"info"),[c,o]=r.useState(localStorage.getItem("logFilterSearch")??"*"),[l,y]=r.useState(localStorage.getItem("logAutoScroll")!=="false"),{setMessages:g,setLogFilters:t,online:x,setAutoScroll:N}=r.useContext(ge),p=P=>{u(P.target.value),t(P.target.value,c),localStorage.setItem("logFilterLevel",P.target.value),n&&console.log("handleChangeLevel called with value:",P.target.value)},j=P=>{o(P.target.value),t(i,P.target.value),localStorage.setItem("logFilterSearch",P.target.value),n&&console.log("handleChangeSearch called with value:",P.target.value)},O=P=>{y(P.target.checked),N(P.target.checked),localStorage.setItem("logAutoScroll",P.target.value?"true":"false"),n&&console.log("handleAutoScrollChange called with value:",P.target.checked)},$=()=>{n&&console.log("handleClearLogsClick called"),g([])};return n&&console.log("Logs rendering..."),x?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(Pt,{id:"select-level",style:{color:"var(--div-text-color)"},children:"Filter log by level:"}),e.jsxs(Ue,{style:{height:"30px",backgroundColor:"var(--main-bg-color)"},labelId:"select-level",id:"debug-level",value:i,onChange:p,children:[e.jsx(I,{value:"debug",children:"Debug"}),e.jsx(I,{value:"info",children:"Info"}),e.jsx(I,{value:"notice",children:"Notice"}),e.jsx(I,{value:"warn",children:"Warn"}),e.jsx(I,{value:"error",children:"Error"}),e.jsx(I,{value:"fatal",children:"Fatal"})]}),e.jsx(Pt,{id:"search",style:{color:"var(--div-text-color)"},children:"Filter log by text:"}),e.jsx(de,{style:{width:"300px"},size:"small",id:"logsearch",variant:"outlined",value:c,onChange:j,InputProps:{style:{height:"30px",padding:"0 0px",backgroundColor:"var(--main-bg-color)"}}}),e.jsx(Fe,{control:e.jsx(Te,{checked:l,onChange:O}),label:"Auto scroll",style:{color:"var(--div-text-color)"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:e.jsx(T,{title:"Clear the logs",children:e.jsx(ae,{onClick:$,endIcon:e.jsx(ut,{}),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(Bt,{})})]}):e.jsx($e,{})}const Tn=r.memo(Fn),$n=({open:i,ip:u,onClose:c,onSave:o})=>{const l=u?u.split(".").slice(0,3).join(".")+".1":"",[y,g]=r.useState("dhcp"),[t,x]=r.useState({ip:u??"",subnet:"255.255.255.0",gateway:l,dns:l}),N=O=>$=>{x({...t,[O]:$.target.value})},p=()=>{c()},j=()=>{o({type:y,...t}),c()};return e.jsxs(Ie,{open:i,onClose:(O,$)=>{$==="backdropClick"||$==="escapeKeyDown"||c()},maxWidth:"sm",style:{maxWidth:"550px",margin:"auto"},children:[e.jsx(De,{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(Ne,{dividers:!0,children:[e.jsxs(qt,{component:"fieldset",fullWidth:!0,children:[e.jsx(be,{component:"legend",children:"Select IP Configuration"}),e.jsxs(zt,{row:!0,value:y,onChange:O=>g(O.target.value),children:[e.jsx(Fe,{value:"dhcp",control:e.jsx(mt,{}),label:"DHCP"}),e.jsx(Fe,{value:"static",control:e.jsx(mt,{}),label:"Static"})]})]}),y==="static"&&e.jsxs(Le,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Le,{size:6,children:e.jsx(de,{label:"IP Address",fullWidth:!0,value:t.ip,onChange:N("ip")})}),e.jsx(Le,{size:6,children:e.jsx(de,{label:"Subnet Mask",fullWidth:!0,value:t.subnet,onChange:N("subnet")})}),e.jsx(Le,{size:6,children:e.jsx(de,{label:"Gateway",fullWidth:!0,value:t.gateway,onChange:N("gateway")})}),e.jsx(Le,{size:6,children:e.jsx(de,{label:"DNS Server",fullWidth:!0,value:t.dns,onChange:N("dns")})})]})]}),e.jsxs(Oe,{children:[e.jsx(ae,{onClick:p,children:"Cancel"}),e.jsx(ae,{variant:"contained",onClick:j,children:"Save"})]})]})},Rn=({open:i,onClose:u,onSave:c})=>{const[o,l]=r.useState(""),[y,g]=r.useState(""),t=$=>{l($.target.value)},x=$=>{g($.target.value)},N=o.length>0&&o===y,p=()=>{u()},j=()=>{N&&(c(o),u())},O=()=>{c(""),u()};return e.jsxs(Ie,{open:i,onClose:($,P)=>{P==="backdropClick"||P==="escapeKeyDown"||u()},maxWidth:"sm",style:{maxWidth:"500px",margin:"auto"},disableEscapeKeyDown:!0,children:[e.jsx(De,{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(Ne,{dividers:!0,children:e.jsx(qt,{component:"fieldset",fullWidth:!0,sx:{margin:0,padding:0,gap:"20px"},children:e.jsxs(Le,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Le,{size:12,children:e.jsx(de,{type:"password",autoComplete:"new-password",label:"New Password",size:"small",variant:"outlined",fullWidth:!0,value:o,onChange:t})}),e.jsx(Le,{size:12,children:e.jsx(de,{type:"password",autoComplete:"new-password",label:"Confirm Password",size:"small",variant:"outlined",fullWidth:!0,value:y,onChange:x,error:y!==""&&o!==y,helperText:y!==""&&o!==y?"Passwords do not match":""})})]})})}),e.jsxs(Oe,{children:[e.jsx(ae,{onClick:p,children:"Cancel"}),e.jsx(ae,{variant:"contained",onClick:j,disabled:!N,children:"Change"}),e.jsx(ae,{variant:"contained",onClick:O,children:"Reset"})]})]})};function Hn(){const{online:i,addListener:u,removeListener:c,sendMessage:o,getUniqueId:l}=r.useContext(ge),[y,g]=r.useState(null),[t,x]=r.useState(null),N=r.useRef(l());return r.useEffect(()=>{const p=j=>{j.src==="Matterbridge"&&j.dst==="Frontend"&&(j.method==="refresh_required"&&j.response.changed==="settings"&&(n&&console.log(`Settings received refresh_required: changed=${j.response.changed} and sending /api/settings request`),o({id:N.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),j.method==="/api/settings"&&(n&&console.log("Settings received /api/settings:",j.response),g(j.response.matterbridgeInformation),x(j.response.systemInformation)))};return u(p,N.current),n&&console.log("Settings added WebSocket listener"),()=>{c(p),n&&console.log("Settings removed WebSocket listener")}},[u,c,o]),r.useEffect(()=>{i&&(n&&console.log("Settings received online"),o({id:N.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[i,o]),y?(n&&console.log("Settings rendering..."),i?e.jsx("div",{className:"MbfPageDiv",children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"20px",width:"100%"},children:[e.jsx(On,{matterbridgeInfo:y,systemInfo:t}),e.jsx(Vn,{matterbridgeInfo:y}),e.jsx(En,{matterbridgeInfo:y})]})}):e.jsx($e,{})):null}function On({matterbridgeInfo:i,systemInfo:u}){const{sendMessage:c,getUniqueId:o}=r.useContext(ge),[l,y]=r.useState("bridge"),[g,t]=r.useState("Info"),[x,N]=r.useState(!1),[p,j]=r.useState("dark"),[O,$]=r.useState(localStorage.getItem("homePagePlugins")!=="false"),[P,U]=r.useState(localStorage.getItem("homePageMode")??"devices"),[h,V]=r.useState(localStorage.getItem("virtualMode")??"outlet"),b=r.useRef(o()),[v,w]=r.useState(!1),F=()=>w(!1),C=X=>{n&&console.log("handleSaveNetConfig called with config:",X),c({id:b.current,sender:"Settings",method:"/api/shellynetconfig",src:"Frontend",dst:"Matterbridge",params:X})},[G,A]=r.useState(!1),a=()=>A(!1),s=X=>{n&&console.log("handleSaveChangePassword called with password:",X),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setpassword",value:X}})};r.useEffect(()=>{i&&(y(i.bridgeMode==="bridge"?"bridge":"childbridge"),t(i.loggerLevel.charAt(0).toUpperCase()+i.loggerLevel.slice(1)),N(i.fileLogger),V(i.virtualMode))},[i]),r.useEffect(()=>{const X=localStorage.getItem("frontendTheme");X&&j(X)},[]);const d=X=>{n&&console.log("handleChangeBridgeMode called with value:",X.target.value),y(X.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setbridgemode",value:X.target.value}})},m=X=>{n&&console.log("handleChangeMbLoggerLevel called with value:",X.target.value),t(X.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmbloglevel",value:X.target.value}})},R=X=>{n&&console.log("handleLogOnFileMbChange called with value:",X.target.checked),N(X.target.checked),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmblogfile",value:X.target.checked}})},pe=X=>{const ie=X.target.value;n&&console.log("handleChangeTheme called with value:",ie),j(ie),localStorage.setItem("frontendTheme",ie),document.body.setAttribute("frontend-theme",ie)},Ce=X=>{const ie=X.target.checked;n&&console.log("handleChangeHomePagePlugins called with value:",ie),$(ie),localStorage.setItem("homePagePlugins",ie?"true":"false")},we=X=>{const ie=X.target.value;n&&console.log("handleChangeHomePageMode called with value:",ie),U(ie),localStorage.setItem("homePageMode",ie)},ye=X=>{const ie=X.target.value;n&&console.log("handleChangeVirtualMode called with value:",ie),V(ie),localStorage.setItem("virtualMode",ie),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setvirtualmode",value:ie}})};return!i||!u?null: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($n,{open:v,ip:u.ipv4Address,onClose:F,onSave:C}),e.jsx(Rn,{open:G,onClose:a,onSave:s}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(Y,{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(be,{style:{padding:"0px",margin:"0px"},id:"matterbridgeInfo-mode",children:"Matterbridge mode:"}),e.jsxs(zt,{row:!0,name:"mode-buttons-group",value:l,onChange:d,children:[e.jsx(Fe,{value:"bridge",control:e.jsx(mt,{}),label:"Bridge",disabled:i.readOnly===!0}),e.jsx(Fe,{value:"childbridge",control:e.jsx(mt,{}),label:"Childbridge",disabled:i.readOnly===!0})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},id:"mblogger-level-label",children:"Logger level:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"mblogger-level-label",id:"mblogger-level",value:g,onChange:m,children:[e.jsx(I,{value:"Debug",children:"Debug"}),e.jsx(I,{value:"Info",children:"Info"}),e.jsx(I,{value:"Notice",children:"Notice"}),e.jsx(I,{value:"Warn",children:"Warn"}),e.jsx(I,{value:"Error",children:"Error"}),e.jsx(I,{value:"Fatal",children:"Fatal"})]}),e.jsx(Fe,{style:{padding:"0px",margin:"0px"},control:e.jsx(Te,{checked:x,onChange:R,name:"logOnFileMb"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},id:"frontend-theme-label",children:"Frontend theme:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"frontend-theme-label",id:"frontend-theme",value:p,onChange:pe,children:[e.jsx(I,{value:"classic",children:"Classic"}),e.jsx(I,{value:"light",children:"Light"}),e.jsx(I,{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},id:"frontend-home-plugin-label",children:"Home page plugins:"}),e.jsx(Te,{checked:O,onChange:Ce,name:"showPlugins"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},id:"frontend-home-label",children:"Home page bottom panel:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"frontend-home-label",id:"frontend-home",value:P,onChange:we,children:[e.jsx(I,{value:"logs",children:"Logs"}),e.jsx(I,{value:"devices",children:"Devices"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"10px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},id:"frontend-virtual-label",children:"Virtual devices:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"frontend-virtual-label",id:"frontend-virtual",value:h,onChange:ye,children:[e.jsx(I,{value:"disabled",children:"Disabled"}),e.jsx(I,{value:"outlet",children:"Outlet"}),e.jsx(I,{value:"light",children:"Light"}),e.jsx(I,{value:"switch",children:"Switch"}),e.jsx(I,{value:"mounted_switch",children:"Mounted Switch"})]})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ae,{variant:"contained",color:"primary",onClick:()=>A(!0),children:"Change password"})}),i.shellyBoard&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(ae,{variant:"contained",color:"primary",onClick:()=>w(!0),children:"Configure IP"})})]})})]})}function Vn({matterbridgeInfo:i}){const{sendMessage:u,getUniqueId:c}=r.useContext(ge),[o,l]=r.useState("Info"),[y,g]=r.useState(!1),[t,x]=r.useState(""),[N,p]=r.useState(""),[j,O]=r.useState(""),[$,P]=r.useState(""),[U,h]=r.useState(""),[V,b]=r.useState(""),v=r.useRef(c());r.useEffect(()=>{i&&(l(["Debug","Info","Notice","Warn","Error","Fatal"][i.matterLoggerLevel]),g(i.matterFileLogger),x(i.matterMdnsInterface||""),p(i.matterIpv4Address||""),O(i.matterIpv6Address||""),P(i.matterPort?i.matterPort.toString():""),h(i.matterDiscriminator?i.matterDiscriminator.toString():""),b(i.matterPasscode?i.matterPasscode.toString():""))},[i]);const w=m=>{n&&console.log("handleChangeMjLoggerLevel called with value:",m.target.value),l(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjloglevel",value:m.target.value}})},F=m=>{n&&console.log("handleLogOnFileMjChange called with value:",m.target.checked),g(m.target.checked),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjlogfile",value:m.target.checked}})},C=m=>{n&&console.log("handleChangeMdnsInterface called with value:",m.target.value),x(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmdnsinterface",value:m.target.value}})},G=m=>{n&&console.log("handleChangeIpv4Address called with value:",m.target.value),p(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv4address",value:m.target.value}})},A=m=>{n&&console.log("handleChangeIpv6Address called with value:",m.target.value),O(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv6address",value:m.target.value}})},a=m=>{n&&console.log("handleChangeMatterPort called with value:",m.target.value),P(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterport",value:m.target.value}})},s=m=>{n&&console.log("handleChangeMatterDiscriminator called with value:",m.target.value),h(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterdiscriminator",value:m.target.value}})},d=m=>{n&&console.log("handleChangemMatterPasscode called with value:",m.target.value),b(m.target.value),u({id:v.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterpasscode",value:m.target.value}})};return i?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(Y,{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(be,{style:{padding:"0px",margin:"0px"},id:"mjdebug-info",children:"Logger level:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"select-mjlevel",id:"mjdebug-level",value:o,onChange:w,children:[e.jsx(I,{value:"Debug",children:"Debug"}),e.jsx(I,{value:"Info",children:"Info"}),e.jsx(I,{value:"Notice",children:"Notice"}),e.jsx(I,{value:"Warn",children:"Warn"}),e.jsx(I,{value:"Error",children:"Error"}),e.jsx(I,{value:"Fatal",children:"Fatal"})]}),e.jsx(Fe,{style:{padding:"0px",margin:"0px"},control:e.jsx(Te,{checked:y,onChange:F,name:"logOnFileMj"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},children:"Mdns interface:"}),e.jsx(de,{value:t,onChange:C,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},children:"Ipv4 address:"}),e.jsx(de,{value:N,onChange:G,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},children:"Ipv6 address:"}),e.jsx(de,{value:j,onChange:A,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},children:"Commissioning port:"}),e.jsx(de,{value:$,onChange:a,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},children:"Commissioning discriminator:"}),e.jsx(de,{value:U,onChange:s,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(be,{style:{padding:"0px",margin:"0px"},children:"Commissioning passcode:"}),e.jsx(de,{value:V,onChange:d,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]})]})})]}):null}function En({matterbridgeInfo:i}){return i?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(Y,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[" ",e.jsx(He,{value:i.matterbridgeVersion,label:"Current Version"}),e.jsx(He,{value:i.matterbridgeLatestVersion,label:"Latest Version"}),e.jsx(He,{value:i.homeDirectory,label:"Home Directory"}),e.jsx(He,{value:i.rootDirectory,label:"Root Directory"}),e.jsx(He,{value:i.matterbridgeDirectory,label:"Matterbridge Storage Directory"}),e.jsx(He,{value:i.matterbridgePluginDirectory,label:"Matterbridge Plugin Directory"}),e.jsx(He,{value:i.globalModulesDirectory,label:"Global Module Directory"})]})})]}):null}function He({value:i,label:u}){return e.jsx(de,{focused:!0,value:i,size:"small",label:u,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)"}}}})}const An=r.memo(Hn);function _n(){const{online:i,sendMessage:u,addListener:c,removeListener:o,getUniqueId:l}=r.useContext(ge),{showSnackbarMessage:y}=r.useContext(Be),[g,t]=r.useState(null),[x,N]=r.useState([]),[p,j]=r.useState([]),[O,$]=r.useState(null),[P,U]=r.useState({cpuUsage:0}),[h,V]=r.useState({totalMemory:"",freeMemory:"",heapTotal:"",heapUsed:"",external:"",arrayBuffers:"",rss:""}),[b,v]=r.useState({systemUptime:"",processUptime:""}),w=r.useRef(l());return console.log("Test uniqueId:",w),r.useEffect(()=>{console.log("Test useEffect WebSocketMessage mounting");const F=C=>{if(C.method==="restart_required")console.log("Test received restart_required"),y("Restart required",0);else if(C.method==="refresh_required")console.log(`Test received refresh_required: changed=${C.response.changed} and sending api requests`),y("Refresh required",0),u({id:w.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:w.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:w.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}});else if(C.method==="memory_update")console.log("Test received memory_update",C),V(C.response);else if(C.method==="cpu_update")console.log("Test received cpu_update",C),U(C.response);else if(C.method==="uptime_update")console.log("Test received uptime_update",C),v(C.response);else if(C.method==="/api/settings"&&C.response)console.log("Test received /api/settings:",C.response),y("Test received /api/settings",0),t(C.response);else if(C.method==="/api/plugins"&&C.response)console.log(`Test received ${C.response.length} plugins:`,C.response),y("Test received /api/plugins",0),N(C.response);else if(C.method==="/api/devices"&&C.response){console.log(`Test received ${C.response.length} devices:`,C.response),y("Test received /api/devices",0),j(C.response);for(const G of C.response)console.log("Test sending /api/clusters for device:",G.pluginName,G.name,G.endpoint),u({id:w.current,method:"/api/clusters",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{plugin:G.pluginName,endpoint:G.endpoint||0}})}else C.method==="/api/clusters"&&C.response&&(console.log(`Test received ${C.response.clusters.length} clusters for device ${C.response.deviceName} endpoint ${C.response.endpoint}:`,C),y(`Test received /api/clusters for ${C.response.plugin}::${C.response.deviceName}`,0),$(C.response))};return c(F,w.current),console.log("Test useEffect WebSocketMessage mounted"),()=>{console.log("Test useEffect WebSocketMessage unmounting"),o(F),console.log("Test useEffect WebSocketMessage unmounted")}},[c,o,u,y]),r.useEffect(()=>(console.log("Test useEffect online mounting"),i&&(console.log("Test useEffect online received online"),u({id:w.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:w.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),u({id:w.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}})),console.log("Test useEffect online mounted"),()=>{console.log("Test useEffect online unmounted")}),[i,u,y]),console.log("Test rendering..."),i?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($e,{})}const qn=r.memo(_n);function zn(i,u){n&&console.log("getCssVariable:",i,"defaultValue",u);const c=getComputedStyle(document.body).getPropertyValue(i).trim();return c||console.error("getCssVariable: undefined",c),c||u}function Un(i){return Zr({palette:{primary:{main:i},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 n=!1;const Bn=()=>{n=!n};function Qn({setLoggedIn:i}){const[u,c]=r.useState(""),[o,l]=r.useState(""),y={display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",backgroundColor:"var(--main-bg-color)"},g={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)"},t={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)"},x=async p=>{try{const j=await fetch("./api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:p})});if(j.ok){const{valid:O}=await j.json();O?i(!0):p!==""&&l("Incorrect password!")}else console.error("Failed to log in:",j.statusText)}catch(j){console.error("Failed to log in:",j)}},N=p=>{p.preventDefault(),x(u)};return x(""),e.jsx("div",{style:y,children:e.jsxs("form",{onSubmit:N,style:g,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:u,onChange:p=>c(p.target.value),style:t,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:o&&e.jsx("p",{style:{color:"red"},children:o})})]})})}function Kn(){const[i,u]=r.useState(!1);n&&console.log("Setting frontend theme");const c=localStorage.getItem("frontendTheme");n&&console.log("Saved theme:",c),c?document.body.setAttribute("frontend-theme",c):document.body.setAttribute("frontend-theme","dark");const o=zn("--primary-color","#1976d2");n&&console.log("Primary color from CSS:",o);const l=Un(o),y=window.location.pathname.includes("/matterbridge/")?"/matterbridge":window.location.href.includes("/api/hassio_ingress/")?window.location.pathname:"/";return n&&(console.log("Loading App..."),console.log("- production mode"),console.log(`- with href = "${window.location.href}"`),console.log(`- pathname = "${window.location.pathname}"`),console.log(`- baseName = "${y}"`)),i?e.jsx(eo,{theme:l,children:e.jsx(cr,{dense:!0,maxSnack:10,preventDuplicate:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Ro,{children:e.jsx(Ho,{children:e.jsx(nr,{basename:y,children:e.jsxs("div",{className:"MbfScreen",children:[e.jsx(Vo,{}),e.jsxs(ir,{children:[e.jsx(Ve,{path:"/",element:e.jsx(cn,{})}),e.jsx(Ve,{path:"/devices",element:e.jsx(Ln,{})}),e.jsx(Ve,{path:"/log",element:e.jsx(Tn,{})}),e.jsx(Ve,{path:"/settings",element:e.jsx(An,{})}),e.jsx(Ve,{path:"/test",element:e.jsx(qn,{})}),e.jsx(Ve,{path:"*",element:e.jsx(sr,{to:"/"})})]})]})})})})})}):e.jsx(Qn,{setLoggedIn:u})}ar.createRoot(document.getElementById("root")).render(e.jsx(lr.StrictMode,{children:e.jsx(Kn,{})}));
|