matterbridge 3.2.9-dev-20250924-c639a33 → 3.2.9-dev-20250926-85736bb

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/dist/frontend.js CHANGED
@@ -21,6 +21,7 @@ export class Frontend extends EventEmitter {
21
21
  matterbridge;
22
22
  log;
23
23
  port = 8283;
24
+ listening = false;
24
25
  expressApp;
25
26
  httpServer;
26
27
  httpsServer;
@@ -63,6 +64,7 @@ export class Frontend extends EventEmitter {
63
64
  if (hasParameter('ingress')) {
64
65
  this.httpServer.listen(this.port, '0.0.0.0', () => {
65
66
  this.log.info(`The frontend http server is listening on ${UNDERLINE}http://0.0.0.0:${this.port}${UNDERLINEOFF}${rs}`);
67
+ this.listening = true;
66
68
  this.emit('server_listening', 'http', this.port, '0.0.0.0');
67
69
  });
68
70
  }
@@ -72,6 +74,7 @@ export class Frontend extends EventEmitter {
72
74
  this.log.info(`The frontend http server is listening on ${UNDERLINE}http://${this.matterbridge.systemInformation.ipv4Address}:${this.port}${UNDERLINEOFF}${rs}`);
73
75
  if (this.matterbridge.systemInformation.ipv6Address !== '')
74
76
  this.log.info(`The frontend http server is listening on ${UNDERLINE}http://[${this.matterbridge.systemInformation.ipv6Address}]:${this.port}${UNDERLINEOFF}${rs}`);
77
+ this.listening = true;
75
78
  this.emit('server_listening', 'http', this.port);
76
79
  });
77
80
  }
@@ -164,6 +167,7 @@ export class Frontend extends EventEmitter {
164
167
  if (hasParameter('ingress')) {
165
168
  this.httpsServer.listen(this.port, '0.0.0.0', () => {
166
169
  this.log.info(`The frontend https server is listening on ${UNDERLINE}https://0.0.0.0:${this.port}${UNDERLINEOFF}${rs}`);
170
+ this.listening = true;
167
171
  this.emit('server_listening', 'https', this.port, '0.0.0.0');
168
172
  });
169
173
  }
@@ -173,6 +177,7 @@ export class Frontend extends EventEmitter {
173
177
  this.log.info(`The frontend https server is listening on ${UNDERLINE}https://${this.matterbridge.systemInformation.ipv4Address}:${this.port}${UNDERLINEOFF}${rs}`);
174
178
  if (this.matterbridge.systemInformation.ipv6Address !== '')
175
179
  this.log.info(`The frontend https server is listening on ${UNDERLINE}https://[${this.matterbridge.systemInformation.ipv6Address}]:${this.port}${UNDERLINEOFF}${rs}`);
180
+ this.listening = true;
176
181
  this.emit('server_listening', 'https', this.port);
177
182
  });
178
183
  }
@@ -581,6 +586,7 @@ export class Frontend extends EventEmitter {
581
586
  this.log.debug('Closing http server...');
582
587
  this.httpServer.close();
583
588
  this.log.debug('Http server closed successfully');
589
+ this.listening = false;
584
590
  this.emit('server_stopped');
585
591
  this.httpServer.removeAllListeners();
586
592
  this.httpServer = undefined;
@@ -590,6 +596,7 @@ export class Frontend extends EventEmitter {
590
596
  this.log.debug('Closing https server...');
591
597
  this.httpsServer.close();
592
598
  this.log.debug('Https server closed successfully');
599
+ this.listening = false;
593
600
  this.emit('server_stopped');
594
601
  this.httpsServer.removeAllListeners();
595
602
  this.httpsServer = undefined;
@@ -654,6 +654,8 @@ export class Matterbridge extends EventEmitter {
654
654
  this.shutdown = true;
655
655
  return;
656
656
  }
657
+ if (getIntParameter('frontend') !== 0 || getIntParameter('frontend') === undefined)
658
+ await this.frontend.start(getIntParameter('frontend'));
657
659
  try {
658
660
  await this.startMatterStorage();
659
661
  if (this.aggregatorSerialNumber && this.aggregatorUniqueId && this.matterStorageService) {
@@ -699,8 +701,6 @@ export class Matterbridge extends EventEmitter {
699
701
  this.shutdown = true;
700
702
  return;
701
703
  }
702
- if (getIntParameter('frontend') !== 0 || getIntParameter('frontend') === undefined)
703
- await this.frontend.start(getIntParameter('frontend'));
704
704
  clearTimeout(this.checkUpdateTimeout);
705
705
  this.checkUpdateTimeout = setTimeout(async () => {
706
706
  const { checkUpdates } = await import('./update.js');
@@ -737,7 +737,7 @@ export class Matterbridge extends EventEmitter {
737
737
  return;
738
738
  }
739
739
  }
740
- async startPlugins() {
740
+ async startPlugins(wait = false, start = true) {
741
741
  for (const plugin of this.plugins) {
742
742
  plugin.configJson = await this.plugins.loadConfig(plugin);
743
743
  plugin.schemaJson = await this.plugins.loadSchema(plugin);
@@ -757,7 +757,10 @@ export class Matterbridge extends EventEmitter {
757
757
  plugin.started = false;
758
758
  plugin.configured = false;
759
759
  plugin.registeredDevices = undefined;
760
- this.plugins.load(plugin, true, 'Matterbridge is starting');
760
+ if (wait)
761
+ await this.plugins.load(plugin, start, 'Matterbridge is starting');
762
+ else
763
+ this.plugins.load(plugin, start, 'Matterbridge is starting');
761
764
  }
762
765
  this.frontend.wssSendRefreshRequired('plugins');
763
766
  }
@@ -1252,7 +1255,14 @@ export class Matterbridge extends EventEmitter {
1252
1255
  async startChildbridge(delay = 1000) {
1253
1256
  if (!this.matterStorageManager)
1254
1257
  throw new Error('No storage manager initialized');
1255
- await this.startPlugins();
1258
+ this.log.debug('Loading all plugins in childbridge mode...');
1259
+ await this.startPlugins(true, false);
1260
+ this.log.debug('Creating server nodes for DynamicPlatform plugins and starting all plugins in childbridge mode...');
1261
+ for (const plugin of this.plugins.array().filter((p) => p.enabled && !p.error)) {
1262
+ if (plugin.type === 'DynamicPlatform')
1263
+ await this.createDynamicPlugin(plugin);
1264
+ this.plugins.start(plugin, 'Matterbridge is starting');
1265
+ }
1256
1266
  this.log.debug('Starting start matter interval in childbridge mode...');
1257
1267
  let failCount = 0;
1258
1268
  this.startMatterInterval = setInterval(async () => {
@@ -1280,9 +1290,6 @@ export class Matterbridge extends EventEmitter {
1280
1290
  plugin.error = true;
1281
1291
  }
1282
1292
  }
1283
- if (plugin.type === 'DynamicPlatform' && !plugin.locked) {
1284
- await this.createDynamicPlugin(plugin);
1285
- }
1286
1293
  }
1287
1294
  if (!allStarted)
1288
1295
  return;
@@ -1,5 +1,5 @@
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 Se,a as Me,b as ke,B as oe,c as Fe,d as X,A as pr,I as Q,C as ur,T as $,S as gr,F as Vt,H as mr,e as Et,f as We,R as dt,P as He,M as hr,g as ze,h as D,L as q,i as te,j as Ze,V as et,k as we,l as ht,m as fr,n as xr,o as pe,p as br,q as vr,r as ct,s as ie,t as Te,K as St,u as Mt,v as ut,w as tt,x as Je,y as rt,W as Ge,z as ot,E as nt,G as kt,J as It,N as yr,O as jr,Q as Cr,U as $e,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 $r,ac as Tr,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 ye,az as zt,aA as gt,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 go,n as mo,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 $t,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 $o}from"./vendor_rjsf.js";import"./vendor_lodash.js";import"./vendor_emotion.js";(function(){const m=document.createElement("link").relList;if(m&&m.supports&&m.supports("modulepreload"))return;for(const d of document.querySelectorAll('link[rel="modulepreload"]'))n(d);new MutationObserver(d=>{for(const v of d)if(v.type==="childList")for(const h of v.addedNodes)h.tagName==="LINK"&&h.rel==="modulepreload"&&n(h)}).observe(document,{childList:!0,subtree:!0});function c(d){const v={};return d.integrity&&(v.integrity=d.integrity),d.referrerPolicy&&(v.referrerPolicy=d.referrerPolicy),d.crossOrigin==="use-credentials"?v.credentials="include":d.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function n(d){if(d.ep)return;d.ep=!0;const v=c(d);fetch(d.href,v)}})();function To({open:s,title:m,message:c,onConfirm:n,onCancel:d}){const v=t=>{i&&console.log("Confirmed"),t.preventDefault(),n()},h=t=>{i&&console.log("Canceled"),t.preventDefault(),d()};return e.jsxs(Se,{open:s,children:[e.jsx(Me,{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:m})]})}),e.jsxs(ke,{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(oe,{onClick:v,variant:"contained",color:"primary",size:"small",children:"Confirm"}),e.jsx(oe,{onClick:h,variant:"contained",color:"primary",size:"small",children:"Cancel"})]})]})]})}const Ro=({open:s,output:m,packageName:c,onInstall:n,onClose:d})=>{const v=r.useRef(null);return r.useEffect(()=>{i&&console.log(`InstallProgressDialog output effect mounted, scrolling to bottom: ${v.current}`),setTimeout(()=>{i&&console.log("Scrolling to bottom:",v.current),v.current?.scrollIntoView({behavior:"smooth"})},0)},[m]),e.jsxs(Se,{open:s,onClose:(h,t)=>{t==="backdropClick"||t==="escapeKeyDown"||d()},slotProps:{paper:{sx:{width:"800px",maxWidth:"50vw",height:"600px",maxHeight:"50vh",overflow:"hidden"}}},children:[e.jsx(Me,{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.jsxs("h4",{style:{margin:0},children:["Install",n?"":"ing"," package ",c]})]})}),e.jsxs(ke,{dividers:!0,style:{overflow:"hidden",display:"flex",flexDirection:"column",height:400,paddingBottom:0},children:[e.jsx("label",{style:{display:"block",marginBottom:"10px",fontSize:"16px",color:"var(--primary-color)"},children:"Install log"}),e.jsxs("ul",{style:{width:"100%",height:"100%",fontFamily:"monospace",fontSize:"14px",padding:8,margin:0,marginBottom:"10px",color:"var(--div-text-color)",background:"var(--div-bg-color)",overflow:"auto",listStyle:"none",boxSizing:"border-box",borderRadius:4,border:"1px solid var(--primary-color)",whiteSpace:"pre-wrap",display:"block"},children:[m.split(`
2
- `).map((h,t)=>e.jsx("li",{style:{padding:0,margin:0},children:h},t)),e.jsx("li",{ref:v,style:{padding:0,margin:0}})]})]}),e.jsxs(Fe,{children:[n&&e.jsx(oe,{variant:"contained",onClick:n,children:"Install"}),e.jsx(oe,{onClick:d,children:"Close"})]})]})},it=[],Be=r.createContext(null);function Ho({children:s}){const{enqueueSnackbar:m,closeSnackbar:c}=dr(),n=r.useCallback(p=>{i&&console.log(`UiProvider closeSnackbarMessage: message ${p}`);const w=it.findIndex(se=>se.message===p);w!==-1&&(c(it[w].key),it.splice(w,1),i&&console.log(`UiProvider closeSnackbarMessage: message ${p} removed from persistMessages`))},[c]),d=r.useCallback((p,w,se)=>{i&&console.log(`UiProvider showSnackbarMessage: message ${p} timeout ${w}`);const ge=m(p,{variant:"default",autoHideDuration:w==null||w>0?(w??5)*1e3:null,persist:w===0,content:fe=>e.jsx(X,{sx:{margin:"0",padding:"0",width:"300px",marginRight:"30px"},children:e.jsx(pr,{severity:se??"info",variant:"filled",sx:{color:"#fff",fontWeight:"normal",width:"100%",cursor:"pointer",padding:"0px 10px"},onClick:()=>c(fe),action:e.jsx(Q,{size:"small",onClick:()=>c(fe),sx:{color:"#fff"},children:e.jsx(ur,{fontSize:"small"})}),children:p},fe)},fe)});w===0&&(i&&console.log(`UiProvider showSnackbarMessage: message ${p} timeout ${w} - persist key ${ge}`),it.push({message:p,key:ge}))},[m,c]),[v,h]=r.useState(!1),[t,x]=r.useState(""),[P,g]=r.useState(""),[C,V]=r.useState(""),T=r.useRef(null),W=r.useRef(null),A=()=>{i&&console.log(`UiProvider handle confirm action ${C}`),h(!1),T.current&&T.current(C)},f=()=>{i&&console.log(`UiProvider handle cancel action ${C}`),h(!1),W.current&&W.current(C)},G=r.useCallback((p,w,se,ge,fe)=>{i&&console.log(`UiProvider showConfirmCancelDialog for command ${se}`),x(p),g(w),V(se),T.current=ge,W.current=fe,h(!0)},[]),[b,y]=r.useState(!1),[k,H]=r.useState(""),[R,z]=r.useState(""),j=r.useCallback(p=>{b||(console.log(`UiProvider show install progress for package ${p}`),H(p),z(`Starting installation of ${p}...
3
- `),y(!0))},[b]),a=r.useCallback(p=>{console.log(`UiProvider addInstallProgress: output ${p}`),z(w=>w+p+`
4
- `)},[]),o=()=>{console.log("UiProvider handle install close action"),y(!1),H(""),z("")},l=r.useMemo(()=>({showSnackbarMessage:d,closeSnackbarMessage:n,closeSnackbar:c,showConfirmCancelDialog:G,showInstallProgress:j,addInstallProgress:a}),[d,n,c,G,j,a]);return e.jsxs(Be.Provider,{value:l,children:[e.jsx(To,{open:v,title:t,message:P,onConfirm:A,onCancel:f}),e.jsx(Ro,{open:b,packageName:k,output:R,onClose:o}),s]})}const Ut=r.createContext(null),he=r.createContext(null);function Oo({children:s}){const[m,c]=r.useState(localStorage.getItem("logFilterLevel")??"info"),[n,d]=r.useState(localStorage.getItem("logFilterSearch")??"*"),[v,h]=r.useState([]),[t,x]=r.useState(1e3),[P,g]=r.useState(!0),[C,V]=r.useState(!1),{showSnackbarMessage:T,closeSnackbarMessage:W,closeSnackbar:A,showInstallProgress:f,addInstallProgress:G}=r.useContext(Be),b=r.useRef([]),y=r.useRef(null),k=r.useRef(1),H=r.useRef(Math.floor(Math.random()*999e3)+1e3),R=r.useRef(null),z=r.useRef(null),j=r.useRef(null),a=r.useRef(m),o=r.useRef(n),l=r.useRef(0),p=r.useRef(null),w=r.useMemo(()=>window.location.href.replace(/^http/,"ws"),[]),se=r.useMemo(()=>window.location.href.includes("api/hassio_ingress"),[]),ge=100,fe=60,Ie=50,Z=300,ne=10;r.useEffect(()=>(i&&console.log("WebSocket messages started counter interval"),p.current=setInterval(()=>{l.current>0&&(i&&console.log(`WebSocket messages received in the last ${ne} seconds: ${l.current*(60/ne)} messages/minute`),l.current=0)},ne*1e3),()=>{i&&console.log("WebSocket messages stopped counter interval"),p.current&&clearInterval(p.current),p.current=null}),[]),r.useEffect(()=>{a.current=m},[m]),r.useEffect(()=>{o.current=n},[n]);const L=r.useCallback(()=>Math.floor(Math.random()*999e3)+1e3,[]),E=r.useCallback(U=>{if(y.current&&y.current.readyState===WebSocket.OPEN)try{i&&console.log(`WebSocket sending message with id ${U.id}:`,U),U.id===void 0&&(U.id=H.current);const u=JSON.stringify(U);y.current.send(u),i&&console.log("WebSocket sent message:",U)}catch(u){i&&console.error(`WebSocket error sending message: ${u}`)}else i&&console.error("WebSocket message not sent, WebSocket not connected:",U)},[]),S=r.useCallback((U,u)=>{h(ee=>[...ee,{level:U,time:"",name:"",message:u}])},[]),N=r.useCallback((U,u)=>{c(U),d(u),S("WebSocket",`Filtering by log level "${U}" and log search "${u}"`)},[S]),M=r.useCallback((U,u)=>{i&&console.log(`WebSocket addListener id ${u}:`,U),(u==null||isNaN(u)||u===0)&&console.error("WebSocket addListener called without id, listener not added:",U),b.current=[...b.current,{listener:U,id:u}],i&&console.log("WebSocket addListener total listeners:",b.current.length)},[]),F=r.useCallback(U=>{i&&console.log("WebSocket removeListener:",U),b.current=b.current.filter(u=>u.listener!==U),i&&console.log("WebSocket removeListener total listeners:",b.current.length)},[]),O=r.useCallback(()=>{w===""||w===null||w===void 0||(S("WebSocket",`Connecting to WebSocket: ${w}`),y.current=new WebSocket(w),y.current.onmessage=U=>{C||V(!0),l.current+=1;try{const u=JSON.parse(U.data);if(u.id===void 0||u.src===void 0||u.dst===void 0){i&&console.error("WebSocket undefined message id/src/dst:",u);return}if(u.src!=="Matterbridge"||u.dst!=="Frontend"){i&&console.error("WebSocket invalid message src/dst:",u);return}if(u.error){i&&console.error("WebSocket error message response:",u);return}if(u.id===H.current&&u.method==="pong"&&u.response==="pong"){i&&console.log(`WebSocket pong response message id ${u.id}:`,u),z.current&&clearTimeout(z.current),z.current=null;return}else if(u.method==="snackbar"&&u.response&&u.response.message){i&&console.log(`WebSocket message id ${u.id} method ${u.method}:`,u),T(u.response.message,u.response.timeout,u.response.severity);return}else if(u.method==="close_snackbar"&&u.response&&u.response.message){i&&console.log(`WebSocket message id ${u.id} method ${u.method}:`,u),W(u.response.message);return}else if(u.method==="log"){if(!u.response||!u.response.level||!u.response.time||!u.response.name||!u.response.message||(u.response.level==="spawn"&&(u.response.name==="Matterbridge:spawn-init"?f(u.response.message):u.response.name==="Matterbridge:spawn-exit"||G(u.response.message+`
5
- `)),["debug","info","notice","warn","error","fatal"].includes(u.response.level)&&(a.current==="info"&&u.response.level==="debug"||a.current==="notice"&&(u.response.level==="debug"||u.response.level==="info")||a.current==="warn"&&(u.response.level==="debug"||u.response.level==="info"||u.response.level==="notice")||a.current==="error"&&(u.response.level==="debug"||u.response.level==="info"||u.response.level==="notice"||u.response.level==="warn")||a.current==="fatal"&&(u.response.level==="debug"||u.response.level==="info"||u.response.level==="notice"||u.response.level==="warn"||u.response.level==="error")))||o.current!=="*"&&o.current!==""&&!u.response.message.toLowerCase().includes(o.current.toLowerCase())&&!u.response.name.toLowerCase().includes(o.current.toLowerCase())||u.response.name==="Commissioning"&&u.response.message.includes("is uncommissioned"))return;h(ae=>{const J=[...ae,{level:u.response.level,time:u.response.time,name:u.response.name,message:u.response.message}];return J.length>t*2?J.slice(t):J})}else{if(i&&console.log(`WebSocket received message id ${u.id} method ${u.method}:`,u),u.id===0)b.current.forEach(ee=>ee.listener(u));else{const ee=b.current.find(ae=>ae.id===u.id);ee?ee.listener(u):i&&console.debug(`WebSocket no listener found for message id ${u.id}:`,u)}return}}catch(u){console.error(`WebSocketUse error parsing message: ${u}`)}},y.current.onopen=()=>{i&&console.log(`WebSocket: Connected to WebSocket: ${w}`),S("WebSocket",`Connected to WebSocket: ${w}`),V(!0),A(),k.current=1,j.current=setTimeout(()=>{R.current=setInterval(()=>{E({id:H.current,method:"ping",src:"Frontend",dst:"Matterbridge",params:{}}),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{i&&console.error(`WebSocketUse: No pong response received from WebSocket: ${w}`),S("WebSocket",`No pong response received from WebSocket: ${w}`),V(!1)},1e3*Ie)},1e3*fe)},1e3*Z)},y.current.onclose=()=>{i&&console.error(`WebSocket: Disconnected from WebSocket ${se?"with Ingress":""}: ${w}`),S("WebSocket",`Disconnected from WebSocket: ${w}`),V(!1),A(),j.current&&clearTimeout(j.current),z.current&&clearTimeout(z.current),R.current&&clearInterval(R.current),S("WebSocket",`Reconnecting (attempt ${k.current} of ${ge}) to WebSocket${se?" (Ingress)":""}: ${w}`),se?setTimeout(Y,5e3):k.current===1?Y():k.current<ge?setTimeout(Y,1e3*k.current):S("WebSocket",`Reconnect attempts exceeded limit of ${ge} retries, refresh the page to reconnect to: ${w}`),k.current=k.current+1},y.current.onerror=U=>{i&&console.error(`WebSocket: WebSocket error connecting to ${w}:`,U),S("WebSocket",`WebSocket error connecting to ${w}`)})},[w]),Y=r.useCallback(()=>{i&&console.log(`WebSocket attemptReconnect ${k.current}/${ge} to:`,w),O()},[O]);r.useEffect(()=>(O(),()=>{y.current&&y.current.readyState===WebSocket.OPEN&&y.current.close()}),[O]);const le=r.useMemo(()=>({messages:v,maxMessages:t,autoScroll:P,setMessages:h,setLogFilters:N,setMaxMessages:x,setAutoScroll:g}),[v,h,N]),de=r.useMemo(()=>({maxMessages:t,autoScroll:P,logFilterLevel:m,logFilterSearch:n,setMessages:h,setLogFilters:N,setMaxMessages:x,setAutoScroll:g,online:C,retry:k.current,getUniqueId:L,addListener:M,removeListener:F,sendMessage:E,logMessage:S}),[t,P,h,N,x,g,C,k.current,M,F,E,S]);return e.jsx(Ut.Provider,{value:le,children:e.jsx(he.Provider,{value:de,children:s})})}function Vo(){const{showSnackbarMessage:s,showConfirmCancelDialog:m}=r.useContext(Be),{online:c,sendMessage:n,logMessage:d,addListener:v,removeListener:h,getUniqueId:t}=r.useContext(he),[x,P]=r.useState(!1),[g,C]=r.useState(!1),[V,T]=r.useState(!1),[W,A]=r.useState(!1),[f,G]=r.useState(null),b=r.useRef(t()),[y,k]=r.useState(null),[H,R]=r.useState(null),[z,j]=r.useState(null),[a,o]=r.useState(null),[l,p]=r.useState(null),w=()=>{window.open("https://www.buymeacoffee.com/luligugithub","_blank")},se=()=>{window.open("https://github.com/Luligu/matterbridge/blob/main/README.md","_blank")},ge=()=>{f?.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")},fe=()=>{window.open("https://discord.gg/QX58CDe6hd","_blank")},Ie=()=>{window.open("https://github.com/Luligu/matterbridge","_blank")},Z=()=>{n({id:b.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge",restart:!0}})},ne=()=>{n({id:b.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge@dev",restart:!0}})},L=()=>{n({id:b.current,sender:"Header",method:"/api/checkupdates",src:"Frontend",dst:"Matterbridge",params:{}})},E=()=>{i&&console.log("Header: handleShellySystemUpdateClick"),d("Matterbridge","Installing system updates..."),n({id:b.current,sender:"Header",method:"/api/shellysysupdate",src:"Frontend",dst:"Matterbridge",params:{}})},S=()=>{i&&console.log("Header: handleShellyMainUpdateClick"),d("Matterbridge","Installing software updates..."),n({id:b.current,sender:"Header",method:"/api/shellymainupdate",src:"Frontend",dst:"Matterbridge",params:{}})},N=()=>{i&&console.log("Header: handleShellyCreateSystemLog"),n({id:b.current,sender:"Header",method:"/api/shellycreatesystemlog",src:"Frontend",dst:"Matterbridge",params:{}})},M=()=>{i&&console.log("Header: handleShellyDownloadSystemLog"),d("Matterbridge","Downloading Shelly system log..."),s("Downloading Shelly system log...",5),window.location.href="./api/shellydownloadsystemlog"},F=()=>{f?.matterbridgeInformation.restartMode===""?n({id:b.current,sender:"Header",method:"/api/restart",src:"Frontend",dst:"Matterbridge",params:{}}):n({id:b.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},O=()=>{n({id:b.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},Y=()=>{n({id:b.current,sender:"Header",method:"/api/reboot",src:"Frontend",dst:"Matterbridge",params:{}})},le=()=>{n({id:b.current,sender:"Header",method:"/api/softreset",src:"Frontend",dst:"Matterbridge",params:{}})},de=()=>{n({id:b.current,sender:"Header",method:"/api/hardreset",src:"Frontend",dst:"Matterbridge",params:{}})},U=B=>{k(B.currentTarget)},u=B=>{i&&console.log("Header: handleMenuClose",B),k(null),B==="download-mblog"?(d("Matterbridge","Downloading matterbridge log..."),s("Downloading matterbridge log...",5),window.location.href="./api/download-mblog"):B==="download-mjlog"?(d("Matterbridge","Downloading matter log..."),s("Downloading matter log...",5),window.location.href="./api/download-mjlog"):B==="view-mblog"?(d("Matterbridge","Loading matterbridge log..."),s("Loading matterbridge log...",5),window.location.href="./api/view-mblog"):B==="view-mjlog"?(d("Matterbridge","Loading matter log..."),s("Loading matter log...",5),window.location.href="./api/view-mjlog"):B==="view-shellylog"?(d("Matterbridge","Loading shelly system log..."),s("Loading shelly system log...",5),window.location.href="./api/shellyviewsystemlog"):B==="download-mbstorage"?(d("Matterbridge","Downloading matterbridge storage..."),s("Downloading matterbridge storage...",5),window.location.href="./api/download-mbstorage"):B==="download-pluginstorage"?(d("Matterbridge","Downloading matterbridge plugins storage..."),s("Downloading matterbridge plugins storage...",5),window.location.href="./api/download-pluginstorage"):B==="download-pluginconfig"?(d("Matterbridge","Downloading matterbridge plugins config..."),s("Downloading matterbridge plugins config...",5),window.location.href="./api/download-pluginconfig"):B==="download-mjstorage"?(d("Matterbridge","Downloading matter storage..."),s("Downloading matter storage...",5),window.location.href="./api/download-mjstorage"):B==="download-backup"?(d("Matterbridge","Downloading backup..."),s("Downloading backup...",10),window.location.href="./api/download-backup"):B==="update"?Z():B==="updatedev"?ne():B==="updatecheck"?L():B==="shelly-sys-update"?E():B==="shelly-main-update"?S():B==="shelly-create-system-log"?N():B==="shelly-download-system-log"?M():B==="softreset"?le():B==="hardreset"?de():B==="restart"?F():B==="shutdown"?O():B==="reboot"?Y():B==="create-backup"?n({id:b.current,sender:"Header",method:"/api/create-backup",src:"Frontend",dst:"Matterbridge",params:{}}):B==="unregister"?n({id:b.current,sender:"Header",method:"/api/unregister",src:"Frontend",dst:"Matterbridge",params:{}}):B==="reset"?n({id:b.current,sender:"Header",method:"/api/reset",src:"Frontend",dst:"Matterbridge",params:{}}):B==="factoryreset"&&n({id:b.current,sender:"Header",method:"/api/factoryreset",src:"Frontend",dst:"Matterbridge",params:{}})},ee=B=>{i&&console.log("Header: handleMenuCloseCancel:",B),k(null)},ae=B=>{R(B.currentTarget)},J=()=>{R(null)},Ce=B=>{j(B.currentTarget)},ve=()=>{j(null)},me=B=>{o(B.currentTarget)},K=()=>{o(null)},ce=B=>{p(B.currentTarget)},be=()=>{p(null)},Qe=()=>{Qn(),i&&console.log("Matterbridge logo clicked: debug is now",i)};return r.useEffect(()=>{const B=I=>{i&&console.log("Header received WebSocket Message:",I),I.method==="/api/settings"&&I.id===b.current?(i&&console.log("Header received settings:",I.response),G(I.response),P(I.response.matterbridgeInformation.restartRequired||I.response.matterbridgeInformation.fixedRestartRequired),C(I.response.matterbridgeInformation.fixedRestartRequired),T(I.response.matterbridgeInformation.updateRequired)):I.method==="refresh_required"&&I.response.changed==="settings"?(i&&console.log(`Header received refresh_required: changed=${I.response.changed} and sending /api/settings request`),n({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})):I.method==="restart_required"?(i&&console.log(`Header received restart_required with fixed: ${I.response.fixed}`),P(!0),I.response.fixed===!0&&C(!0)):I.method==="restart_not_required"?(i&&console.log("Header received restart_not_required"),P(!1)):I.method==="update_required"?(i&&console.log("Header received update_required"),I.response.devVersion===!0?A(!0):T(!0),n({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})):I.method==="shelly_sys_update"?(i&&console.log("Header received WS_ID_SHELLY_SYS_UPDATE:"),G(ue=>ue?{matterbridgeInformation:{...ue.matterbridgeInformation,shellySysUpdate:I.response.available},systemInformation:ue.systemInformation}:null)):I.method==="shelly_main_update"&&(i&&console.log("Header received WS_ID_SHELLY_MAIN_UPDATE:"),G(ue=>ue?{matterbridgeInformation:{...ue.matterbridgeInformation,shellyMainUpdate:I.response.available},systemInformation:ue.systemInformation}:null))};return v(B,b.current),i&&console.log(`Header added WebSocket listener id ${b.current}`),()=>{h(B),i&&console.log("Header removed WebSocket listener")}},[v,h,n,s]),r.useEffect(()=>{c&&(i&&console.log("Header sending /api/settings requests"),n({id:b.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,n]),i&&console.log("Header rendering..."),!c||!f?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:[!f.matterbridgeInformation.readOnly&&V&&e.jsx($,{title:"New Matterbridge version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:Z,children:["Update to v.",f.matterbridgeInformation.matterbridgeLatestVersion]})}),!f.matterbridgeInformation.readOnly&&W&&e.jsx($,{title:"New Matterbridge dev version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:ne,children:["Update to new dev v.",f.matterbridgeInformation.matterbridgeDevVersion.split("-dev-")[0]]})}),!f.matterbridgeInformation.readOnly&&e.jsx($,{title:"Matterbridge version, click to see the changelog",children:e.jsxs("span",{className:"status-information",onClick:ge,children:["v.",f.matterbridgeInformation.matterbridgeVersion]})}),f.matterbridgeInformation.shellyBoard&&e.jsx("img",{src:"Shelly.svg",alt:"Shelly Icon",style:{height:"30px",padding:"0px",margin:"0px",marginRight:"30px"}}),f.matterbridgeInformation.bridgeMode!==""&&f.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Bridge mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:f.matterbridgeInformation.bridgeMode})}):null,f.matterbridgeInformation.restartMode!==""&&f.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Restart mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:f.matterbridgeInformation.restartMode})}):null,f.matterbridgeInformation.profile&&f.matterbridgeInformation.profile!==""&&f.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Current profile",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:f.matterbridgeInformation.profile})}):null]}),e.jsxs("div",{className:"sub-header",style:{gap:"5px"},children:[f.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Matterbridge discord group",children:e.jsx("img",{src:"discord.svg",alt:"Discord Logo",style:{cursor:"pointer",height:"25px"},onClick:fe})}):null,f.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Give a star to Matterbridge",children:e.jsx(Q,{style:{color:"#FFD700",margin:"0",padding:"0"},onClick:Ie,children:e.jsx(gr,{})})}):null,f.matterbridgeInformation.readOnly===!1?e.jsx($,{title:"Sponsor Matterbridge",children:e.jsx(Q,{style:{color:"#b6409c",margin:"0",padding:"0"},onClick:w,children:e.jsx(Vt,{})})}):null,e.jsx($,{title:"Matterbridge help",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:se,children:e.jsx(mr,{})})}),e.jsx($,{title:"Matterbridge changelog",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:ge,children:e.jsx(Et,{})})}),f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsx($,{title:"Update matterbridge to latest version",children:e.jsx(Q,{style:{color:V?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:Z,children:e.jsx(We,{})})}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.matterbridgeInformation.shellySysUpdate&&e.jsx($,{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,{})})}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.matterbridgeInformation.shellyMainUpdate&&e.jsx($,{title:"Shelly software update",children:e.jsx(Q,{style:{color:"var(--primary-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:S,children:e.jsx(We,{})})}),e.jsx($,{title:"Restart matterbridge",children:e.jsx(Q,{style:{color:x||g?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:F,children:e.jsx(dt,{})})}),f.matterbridgeInformation.restartMode===""?e.jsx($,{title:"Shut down matterbridge",children:e.jsx(Q,{style:{color:x||g?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0px"},onClick:O,children:e.jsx(He,{})})}):null,e.jsx($,{title:"Download, backup and more",children:e.jsx(Q,{onClick:U,children:e.jsx(hr,{style:{color:"var(--main-icon-color)"}})})}),e.jsxs(ze,{id:"command-menu",anchorEl:y,keepMounted:!0,open:!!y,onClose:()=>u(""),children:[f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>u("update"),children:[e.jsx(q,{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)"}}})]}),f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>u("updatedev"),children:[e.jsx(q,{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)"}}})]}),f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>u("updatecheck"),children:[e.jsx(q,{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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.matterbridgeInformation.shellySysUpdate&&e.jsxs(D,{onClick:()=>u("shelly-sys-update"),children:[e.jsx(q,{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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.matterbridgeInformation.shellyMainUpdate&&e.jsxs(D,{onClick:()=>u("shelly-main-update"),children:[e.jsx(q,{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(D,{onClick:()=>u("restart"),children:[e.jsx(q,{children:e.jsx(dt,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Restart",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation.restartMode===""?e.jsxs(D,{onClick:()=>u("shutdown"),children:[e.jsx(q,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shutdown",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}):null,f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{m("Reboot","Are you sure you want to reboot the Shelly board?","reboot",u,ee)},children:[e.jsx(q,{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(D,{onClick:Ce,children:[e.jsx(q,{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:z,keepMounted:!0,open:!!z,onClose:ve,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{u("view-mblog"),ve()},children:[e.jsx(q,{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(D,{onClick:()=>{u("view-mjlog"),ve()},children:[e.jsx(q,{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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{u("view-shellylog"),ve()},children:[e.jsx(q,{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(D,{onClick:me,children:[e.jsx(q,{children:e.jsx(we,{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:K,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{u("download-mbstorage"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{u("download-pluginstorage"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge plugins storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{u("download-pluginconfig"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge plugins config",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{u("download-mblog"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matterbridge log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{u("download-mjstorage"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter storage",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{u("download-mjlog"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Matter log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{u("shelly-create-system-log"),K()},children:[e.jsx(q,{children:e.jsx(we,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Create Shelly system log",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{u("shelly-download-system-log"),K()},children:[e.jsx(q,{children:e.jsx(we,{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(D,{onClick:ae,children:[e.jsx(q,{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:H,keepMounted:!0,open:!!H,onClose:J,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{u("create-backup"),J()},children:[e.jsx(q,{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(D,{onClick:()=>{u("download-backup"),J()},children:[e.jsx(q,{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(D,{onClick:ce,children:[e.jsx(q,{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:l,keepMounted:!0,open:!!l,onClose:be,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{be(),m("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",u,ee)},children:[e.jsx(q,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset all devices...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{be(),m("Reset commissioning and shutdown","Are you sure you want to reset the commissioning? You will have to manually remove Matterbridge from the controller.","reset",u,ee)},children:[e.jsx(q,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset commissioning...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>{be(),m("Factory reset and shutdown","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","factoryreset",u,ee)},children:[e.jsx(q,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{be(),m("Network reset","Are you sure you want to factory reset the network parameters?","softreset",u,ee)},children:[e.jsx(q,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset network...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{be(),m("Factory reset","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","hardreset",u,ee)},children:[e.jsx(q,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]})]})]})]})}const Eo=r.memo(Vo),Ao=()=>"ontouchstart"in window||typeof window.DocumentTouch<"u"&&document instanceof window.DocumentTouch?(i&&console.log("WebSocketLogs detectTouchscreen = true"),!0):(i&&console.log("WebSocketLogs detectTouchscreen = false"),!1);function _o(){const{messages:s,autoScroll:m}=r.useContext(Ut),[c,n]=r.useState(!1),d=r.useRef(null),v=r.useMemo(()=>Ao(),[]),h=g=>n(!0),t=g=>n(!1);r.useEffect(()=>{i&&console.log(`WebSocketLogs autoScroll: ${m} isHovering: ${c}`),m&&!c&&!v&&d.current?.scrollIntoView({behavior:"smooth"})},[s,c,m,v]);const x=g=>{switch(g.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"}},P=g=>{switch(g.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:h,onMouseLeave:t,children:[s.map((g,C)=>e.jsxs("li",{style:{wordWrap:"break-word",maxHeight:"200px",overflow:"hidden"},children:[e.jsx("span",{style:{marginRight:"5px",padding:"1px 5px",backgroundColor:x(g.level),color:P(g.level),fontSize:"12px",borderRadius:"3px",textAlign:"center"},children:g.level}),g.time&&e.jsx("span",{style:{marginRight:"3px",color:"#505050"},children:"["+g.time+"]"}),g.name&&e.jsx("span",{style:{marginRight:"3px",color:"#09516d"},children:"["+g.name+"]"}),e.jsx("span",{style:{color:"var(--main-log-color)"},children:g.message})]},C)),e.jsx("div",{ref:d})]})})}const Bt=r.memo(_o);function Re(){const{retry:s}=r.useContext(he),m=()=>{window.location.reload()};return e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",fontSize:"20px",flexDirection:"column",color:"var(--main-text-color)",height:"100vh",backgroundColor:"var(--main-bg-color)"},children:e.jsx(X,{sx:{display:"flex",alignItems:"center",flexDirection:"column"},children:s<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 "+s+")","..."]})})]}):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(oe,{variant:"contained",color:"primary",onClick:m,style:{marginTop:"20px"},children:"Refresh the Page"})]})})})}function qo({value:s,maxChars:m}){let c=s;if(s.length>m&&m>3){const n=m-3,d=s.substring(0,Math.ceil(n/2)),v=s.substring(s.length-Math.floor(n/2),s.length);c=`${d} … ${v}`}return s!==c?e.jsx($,{title:s,placement:"top",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[0,12]}}]}},children:e.jsx("span",{children:c})}):e.jsx("span",{children:c})}function zo({systemInfo:s,compact:m}){const{sendMessage:c,addListener:n,removeListener:d,getUniqueId:v}=r.useContext(he),[h,t]=r.useState(s),x=r.useRef(v());if(i&&console.log("SystemInfoTable:",h,"compact:",m),s&&m&&h.totalMemory&&h.freeMemory){const P=h.totalMemory,g=h.freeMemory;h.freeMemory=`${g} / ${P}`,h.totalMemory=""}if(s&&m&&h.heapTotal&&h.heapUsed){const P=h.heapTotal,g=h.heapUsed;h.heapUsed=`${g} / ${P}`,h.heapTotal=""}if(s&&m&&h.osRelease&&h.osType){const P=h.osType,g=h.osRelease;h.osType=`${P} (${g})`,h.osRelease=""}if(s&&m&&h.osArch&&h.osPlatform){const P=h.osPlatform,g=h.osArch;h.osPlatform=`${P} (${g})`,h.osArch=""}return r.useEffect(()=>{const P=g=>{g.src==="Matterbridge"&&g.dst==="Frontend"&&(g.method==="memory_update"&&g.response&&g.response.totalMemory&&g.response.freeMemory&&g.response.heapTotal&&g.response.heapUsed&&g.response.rss&&(i&&console.log("SystemInfoTable received memory_update",g),(h.totalMemory!==g.response.totalMemory||h.freeMemory!==g.response.freeMemory||h.heapTotal!==g.response.heapTotal||h.heapUsed!==g.response.heapUsed||h.rss!==g.response.rss)&&t(C=>({...C,totalMemory:g.response.totalMemory,freeMemory:g.response.freeMemory,heapTotal:g.response.heapTotal,heapUsed:g.response.heapUsed,rss:g.response.rss}))),g.method==="cpu_update"&&g.response&&g.response.cpuUsage&&(i&&console.log("SystemInfoTable received cpu_update",g),h.cpuUsage!==(g.response.cpuUsage?g.response.cpuUsage.toFixed(2)+" %":"")&&t(C=>({...C,cpuUsage:g.response.cpuUsage.toFixed(2)+" %"}))),g.method==="uptime_update"&&g.response&&g.response.systemUptime&&g.response.processUptime&&(i&&console.log("SystemInfoTable received uptime_update",g),(h.systemUptime!==g.response.systemUptime||h.processUptime!==g.response.processUptime)&&t(C=>({...C,systemUptime:g.response.systemUptime,processUptime:g.response.processUptime}))))};return i&&console.log("SystemInfoTable useEffect WebSocketMessage mounting"),n(P,x.current),i&&console.log("SystemInfoTable useEffect WebSocketMessage mounted"),()=>{i&&console.log("SystemInfoTable useEffect WebSocketMessage unmounting"),d(P),i&&console.log("SystemInfoTable useEffect WebSocketMessage unmounted")}},[n,h.cpuUsage,h.freeMemory,h.heapTotal,h.heapUsed,h.processUptime,h.rss,h.systemUptime,h.totalMemory,d,c]),h?(i&&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(h).filter(([P,g])=>g!==void 0&&g!=="").map(([P,g],C)=>e.jsxs("tr",{className:C%2===0?"table-content-even":"table-content-odd",style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:P}),e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx(qo,{value:typeof g!="string"?g.toString():g,maxChars:25})})]},P))})})})]})):null}const Uo=r.memo(zo),Tt={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"}},Bo=s=>{if(!s)return"";const m=s.toString().replace(/[^0-9]/g,"");if(m.length<5)return m;const c=m.slice(0,4),n=m.slice(4,7),d=m.slice(7,11);return[c,n,d].filter(Boolean).join("-")};function Qo({id:s}){const{online:m,sendMessage:c,addListener:n,removeListener:d,getUniqueId:v}=r.useContext(he),[h,t]=r.useState(null),[x,P]=r.useState(null),g=r.useRef(null),C=r.useRef(v()),{showConfirmCancelDialog:V}=r.useContext(Be);r.useEffect(()=>{i&&console.log(`QRDiv received storeId update "${s}"`),s&&(i&&console.log(`QRDiv sending data request for storeId "${s}"`),t(s),c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:s,server:!0}}))},[s]),r.useEffect(()=>{const b=y=>{y.src==="Matterbridge"&&y.dst==="Frontend"&&y.method==="refresh_required"&&y.response.changed==="matter"&&y.response.matter&&(i&&console.log(`QRDiv received refresh_required: changed=${y.response.changed} for storeId "${y.response.matter.id}":`,y.response.matter),h===y.response.matter.id&&(i&&console.log(`QRDiv received refresh_required/matter: setting matter data for storeId "${y.response.matter.id}":`,y.response.matter),g.current&&clearTimeout(g.current),y.response.matter.advertising&&y.response.matter.advertiseTime&&y.response.matter.advertiseTime+9e5<=Date.now()&&(y.response.matter.advertising=!1),P(y.response.matter),y.response.matter.advertising&&(i&&console.log(`QRDiv setting matter advertise timeout for storeId "${y.response.matter.id}":`,y.response.matter.advertiseTime+9e5-Date.now()),g.current=setTimeout(()=>{g.current&&clearTimeout(g.current),i&&console.log(`QRDiv clearing advertising state for storeId "${h}" after 15 minutes`),P(k=>k&&{...k,advertising:!1})},y.response.matter.advertiseTime+9e5-Date.now()))))};return n(b,C.current),i&&console.log("QRDiv webSocket effect mounted"),()=>{d(b),g.current&&clearTimeout(g.current),g.current=null,i&&console.log("QRDiv webSocket effect unmounted")}},[h]);const T=()=>{i&&console.log(`QRDiv sent matter startCommission for node "${x?.id}"`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,startCommission:!0}})},W=()=>{i&&console.log(`QRDiv sent matter stopCommission for node "${x?.id}"`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,stopCommission:!0}})},A=()=>{i&&console.log(`QRDiv sent matter advertise for node "${x?.id}"`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,advertise:!0}})},f=b=>{i&&console.log(`QRDiv sent matter removeFabric for node "${x?.id}" and fabricIndex ${b}`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,removeFabric:b}})},G=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 y=document.createElement("textarea");y.value=b,y.style.position="fixed",y.style.opacity="0",document.body.appendChild(y),y.focus(),y.select(),document.execCommand("copy"),document.body.removeChild(y)}i&&console.log("Manual pairing code copied to clipboard")}catch(y){console.error("Failed to copy manual pairing code",y)}};return!x||!m?(i&&console.log("QRDiv rendering undefined state"),null):x.online?x.advertising&&x.qrPairingCode&&x.manualPairingCode?(i&&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:A,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{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:W,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{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:h}),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: ",Bo(x.manualPairingCode)]}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx($,{title:"Copy manual pairing code",arrow:!0,children:e.jsx(Q,{"aria-label":"copy manual pairing code",size:"small",onClick:G,sx:Tt,children:e.jsx(re,{path:oo,size:.85})})})})]})]})):x.commissioned&&x.fabricInformations&&x.sessionInformations?(i&&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:A,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{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:T,sx:{color:"var(--header-text-color)",margin:"0px",padding:"0px"},children:e.jsx($,{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:h}),x.fabricInformations.map((b,y)=>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($,{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:()=>V("Remove fabric","Are you sure you want to remove this fabric? You will also need to remove it from the controller.","RemoveFabric",()=>f(b.fabricIndex),()=>{}),sx:{...Tt,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(k=>k.fabric?.fabricIndex===b.fabricIndex&&k.isPeerActive===!0).length:"0"," ","subscriptions: ",x.sessionInformations?x.sessionInformations.filter(k=>k.fabric?.fabricIndex===b.fabricIndex&&k.isPeerActive===!0&&k.numberOfActiveSubscriptions>0).length:"0"]})]},y))]}),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?(i&&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:h}),e.jsx(oe,{onClick:T,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]})})]})):(i&&console.log("QRDiv rendering unknown state"),null):(i&&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:h}),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 Ko=r.memo(Qo);function Jo(){const{logMessage:s,sendMessage:m,getUniqueId:c}=r.useContext(he),[n,d]=r.useState("matterbridge-"),[v,h]=r.useState(!1),[t,x]=r.useState(null),P=r.useRef(c()),g=y=>{y.preventDefault(),h(!0)},C=()=>{h(!1)},V=y=>{y.preventDefault(),h(!1);const k=y.dataTransfer.files[0];if(k){s("Plugins",`Installing package ${k.name}. Please wait...`);const H=new FormData;H.append("file",k),H.append("filename",k.name),fetch("./api/uploadpackage",{method:"POST",body:H}).then(R=>R.text()).then(R=>{s("Plugins",`Server response: ${R}`)}).catch(R=>{console.error("Error uploading plugin file:",R),s("Plugins",`Error installing package ${R}`)})}},T=y=>{const k=y.target.files&&y.target.files[0];if(k){s("Plugins",`Uploading package ${k.name}`);const H=new FormData;H.append("file",k),H.append("filename",k.name),fetch("./api/uploadpackage",{method:"POST",body:H}).then(R=>R.text()).then(R=>{s("Plugins",`Server response: ${R}`)}).catch(R=>{console.error("Error uploading plugin file:",R),s("Plugins",`Error uploading package ${R}`)})}},W=()=>{m({id:P.current,sender:"InstallPlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:n,restart:!1}})},A=()=>{document.getElementById("file-upload")?.click()},f=()=>{m({id:P.current,sender:"InstallPlugins",method:"/api/addplugin",src:"Frontend",dst:"Matterbridge",params:{pluginNameOrPath:n}})},G=y=>{x(y.currentTarget)},b=y=>{y!==""&&d(y),x(null)};return i&&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:g,onDragLeave:C,onDrop:V,children:[e.jsx(pe,{value:n,onChange:y=>{d(y.target.value)},size:"small",id:"plugin-name",label:"Plugin name or plugin path",variant:"outlined",fullWidth:!0}),e.jsx(Q,{onClick:G,children:e.jsx(br,{})}),e.jsxs(ze,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:!!t,onClose:()=>b(""),children:[e.jsx(D,{onClick:()=>b("matterbridge-zigbee2mqtt"),children:"matterbridge-zigbee2mqtt"}),e.jsx(D,{onClick:()=>b("matterbridge-somfy-tahoma"),children:"matterbridge-somfy-tahoma"}),e.jsx(D,{onClick:()=>b("matterbridge-shelly"),children:"matterbridge-shelly"}),e.jsx(D,{onClick:()=>b("matterbridge-hass"),children:"matterbridge-hass"}),e.jsx(D,{onClick:()=>b("matterbridge-webhooks"),children:"matterbridge-webhooks"}),e.jsx(D,{onClick:()=>b("matterbridge-bthome"),children:"matterbridge-bthome"}),e.jsx(D,{onClick:()=>b("matterbridge-test"),children:"matterbridge-test"}),e.jsx(D,{onClick:()=>b("matterbridge-example-accessory-platform"),children:"matterbridge-example-accessory-platform"}),e.jsx(D,{onClick:()=>b("matterbridge-example-dynamic-platform"),children:"matterbridge-example-dynamic-platform"}),e.jsx(D,{onClick:()=>b("matterbridge-eve-door"),children:"matterbridge-eve-door"}),e.jsx(D,{onClick:()=>b("matterbridge-eve-motion"),children:"matterbridge-eve-motion"}),e.jsx(D,{onClick:()=>b("matterbridge-eve-energy"),children:"matterbridge-eve-energy"}),e.jsx(D,{onClick:()=>b("matterbridge-eve-weather"),children:"matterbridge-eve-weather"}),e.jsx(D,{onClick:()=>b("matterbridge-eve-room"),children:"matterbridge-eve-room"})]}),e.jsx($,{title:"Install or update a plugin from npm",children:e.jsx(oe,{onClick:W,endIcon:e.jsx(we,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Install"})}),e.jsx($,{title:"Upload and install a plugin from a tarball",children:e.jsx(oe,{onClick:A,endIcon:e.jsx(vr,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px",minWidth:"90px"},children:" Upload"})}),e.jsx($,{title:"Add an installed plugin",children:e.jsx(oe,{onClick:f,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:T})]})}const Go=r.memo(Jo);function Ee({status:s,enabledText:m="Enabled",disabledText:c=void 0,tooltipText:n=void 0,onClick:d}){if(s===void 0)return null;{const v=e.jsx("div",{className:s?"status-enabled":"status-disabled",style:{cursor:"default"},onClick:d,children:s?m:c??m});return n!==void 0?e.jsx($,{title:n,children:v}):v}}function Rt(s){return s.id!==0&&s.src==="Matterbridge"&&s.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)"},Yo={fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)",backgroundColor:"var(--div-bg-color)"},Xo={fontSize:"16px",fontWeight:"bold",backgroundColor:"var(--div-bg-color)"},Ne={padding:"0px",margin:"0px"},Zo="5px 10px 5px 10px",st={},xe={},at={},lt={};let qe=[],xt=[];const en=({open:s,onClose:m,plugin:c})=>{const{sendMessage:n,addListener:d,removeListener:v,getUniqueId:h}=r.useContext(he),t=r.useRef(h()),[x,P]=r.useState(c.configJson),[g,C]=r.useState(null),[V,T]=r.useState({"ui:submitButtonOptions":{submitText:"Confirm"},"ui:globalOptions":{orderable:!0}}),[W,A]=r.useState("");let f={};r.useEffect(()=>{const N=M=>{M.src==="Matterbridge"&&M.dst==="Frontend"&&(Rt(M)&&M.id===t.current&&M.method==="/api/select/devices"&&M.response&&(i&&console.log(`ConfigPluginDialog (id: ${M.id}) received ${M.response.length} /api/select/devices:`,M.response),qe=M.response),Rt(M)&&M.id===t.current&&M.method==="/api/select/entities"&&M.response&&(i&&console.log(`ConfigPluginDialog (id: ${M.id}) received ${M.response.length} /api/select/entities:`,M.response),xt=M.response))};return d(N,t.current),i&&console.log("ConfigPluginDialog added WebSocket listener id:",t.current),x&&g&&g.properties&&(Object.keys(g.properties).forEach(M=>{Object.keys(g.properties[M]).forEach(F=>{F.startsWith("ui:")&&(V[M]={},V[M][F]=g.properties[M][F],delete g.properties[M][F])})}),T(V)),c.name&&c.configJson&&c.schemaJson&&(P(c.configJson),C(c.schemaJson),n({id:t.current,sender:"ConfigPlugin",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name}}),n({id:t.current,sender:"ConfigPlugin",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name}}),i&&console.log('HomePlugins sent "/api/select/devices" and "/api/select/entities" for plugin:',c.name)),()=>{v(N),i&&console.log("ConfigPluginDialog removed WebSocket listener")}},[d,x,c,v,g,n,V]);const G=(N,M)=>{f=N.formData},b=N=>{i&&console.log("ConfigPluginDialog handleSaveChanges:",N.formData),P(N.formData),c.configJson=N.formData,c.restartRequired=!0,n({id:t.current,sender:"ConfigPlugin",method:"/api/savepluginconfig",src:"Frontend",dst:"Matterbridge",params:{pluginName:N.formData.name,formData:N.formData}}),m()};function y(N){const{id:M,label:F,onKeyChange:O,onDropPropertyClick:Y,disabled:le,schema:de,children:U,registry:u,readonly:ee,required:ae}=N,{templates:J}=u,{RemoveButton:Ce}=J.ButtonTemplates;if(!($o in de))return e.jsx(X,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:U});const me=({target:K})=>O(K&&K.value);return e.jsxs(X,{sx:{display:"flex",flexDirection:"row",flexGrow:1,padding:0,margin:0,border:"none"},children:[e.jsx(pe,{id:`${M}-key`,name:`${M}-key`,required:ae,disabled:le||ee,defaultValue:F,onBlur:ee?void 0:me,type:"text",variant:"outlined",sx:{width:"250px",minWidth:"250px",maxWidth:"250px",marginRight:"20px"}}),e.jsx(X,{sx:{flex:1},children:U}),e.jsx(Ce,{disabled:le||ee,onClick:Y(F),registry:u})]})}function k(N){const{children:M,description:F,displayLabel:O,errors:Y,help:le,hidden:de,registry:U,uiSchema:u}=N,ee=Lo(u),ae=Fo("WrapIfAdditionalTemplate",U,ee);return de?e.jsx("div",{style:{display:"none"},children:M}):e.jsx(X,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:e.jsxs(ae,{...N,children:[O===!0&&F,M,Y,le]})})}function H(N){const{description:M}=N;return M?e.jsx(ie,{sx:_e,children:M}):null}function R(N){const{required:M,title:F}=N;return F?e.jsx(X,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsxs(ie,{sx:Ae,children:["Title ",F," ",M&&e.jsx("mark",{children:"***"})]})}):null}function z(N){const{help:M}=N;return M?e.jsx(X,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsx(ie,{sx:Yo,children:M})}):null}function j(N){const{errors:M}=N;return M?e.jsxs(X,{sx:{padding:"10px",margin:"10px",border:"1px solid grey"},children:[e.jsx(ie,{color:"error",sx:Xo,children:"Please fix the following errors:"}),e.jsx(Je,{children:M.map((F,O)=>e.jsxs(yr,{children:[e.jsx(q,{children:e.jsx(jr,{color:"error"})}),e.jsx(te,{primary:F.stack})]},O))})]}):null}function a(N){const{errors:M}=N;return M?e.jsx(X,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:M.map((F,O)=>e.jsxs(ie,{color:"error",variant:"body2",sx:{marginLeft:1},children:["This field ",F]},O))}):null}function o(N){const{id:M,name:F,_schema:O,_uiSchema:Y,value:le,options:de,label:U,type:u,placeholder:ee,required:ae,disabled:J,readonly:Ce,autofocus:ve,onChange:me,onChangeOverride:K,onBlur:ce,onFocus:be,_rawErrors:Qe,_hideError:B,_registry:I,_formContext:ue}=N,Ke=({target:{value:je}})=>me(je===""?de.emptyValue:je),Pe=({target:je})=>ce(M,je&&je.value),Ye=({target:je})=>be(M,je&&je.value);return e.jsx(X,{sx:{padding:"0px",margin:"0px"},children:e.jsx(pe,{id:M,name:M,label:ee&&ee!==""?U:void 0,variant:"outlined",placeholder:ee&&ee!==""?ee:U,required:ae,disabled:J||Ce,autoFocus:ve,value:le||le===0?le:"",type:u,autoComplete:u==="password"?"current-password":F,onChange:K||Ke,onBlur:Pe,onFocus:Ye,fullWidth:!0})})}function l(N){return console.log("ArrayFieldTitleTemplate:",N),null}function p(N){return console.log("ArrayFieldDescriptionTemplate:",N),null}function w(N){return console.log("ArrayFieldItemTemplate:",N),null}function se(N){const{canAdd:M,onAddClick:F,schema:O,title:Y}=N,[le,de]=r.useState(!1),[U,u]=r.useState(!1),[ee,ae]=r.useState(!1),[J,Ce]=r.useState(""),ve=I=>{Ce(I.target.value)},me=()=>{i&&console.log("ArrayFieldTemplate: handleDialogDeviceToggle filter:",J,"selectDevices:",qe),de(!le)},K=()=>{i&&console.log("ArrayFieldTemplate: handleDialogEntityToggle filter:",J,"selectEntities:",xt),u(!U)},ce=()=>{i&&console.log("ArrayFieldTemplate: handleDialogDeviceEntityToggle filter:",J,"selectDevices:",qe),ae(!ee)},be=I=>{de(!1),O.selectFrom==="serial"?O.items.default=I.serial:O.selectFrom==="name"&&(O.items.default=I.name),F()},Qe=I=>{u(!1),O.selectEntityFrom==="name"?O.items.default=I.name:O.selectEntityFrom==="description"&&(O.items.default=I.description),F()},B=I=>{ae(!1),O.selectDeviceEntityFrom==="name"?O.items.default=I.name:O.selectDeviceEntityFrom==="description"&&(O.items.default=I.description),F()};return e.jsxs(X,{sx:{margin:"0px",padding:"5px 10px 5px 10px",border:"1px solid grey"},children:[Y&&e.jsxs(X,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[Y&&e.jsx(ie,{sx:Ae,children:Y}),M&&e.jsxs(X,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[O.selectFrom&&e.jsx($,{title:"Add a device from the list",children:e.jsx(Q,{onClick:me,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),O.selectEntityFrom&&e.jsx($,{title:"Add an entity from the list",children:e.jsx(Q,{onClick:K,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),O.selectDeviceEntityFrom&&e.jsx($,{title:"Add a device entity from the list",children:e.jsx(Q,{onClick:ce,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),e.jsx($,{title:"Add a new item",children:e.jsx(Q,{onClick:F,size:"small",color:"primary",sx:Ne,children:e.jsx(ct,{})})})]})]}),O.description&&e.jsx(ie,{sx:_e,children:O.description}),N.items.map(I=>e.jsxs(X,{sx:{margin:"2px 0px",padding:"0px",display:"flex",alignItems:"center"},children:[e.jsx(X,{sx:{flexGrow:1,marginRight:"10px"},children:I.children}),e.jsx(Q,{disabled:!I.hasMoveUp,onClick:I.onReorderClick(I.index,I.index-1),size:"small",color:"primary",sx:Ne,children:e.jsx(Mt,{})}),e.jsx(Q,{disabled:!I.hasMoveDown,onClick:I.onReorderClick(I.index,I.index+1),size:"small",color:"primary",sx:Ne,children:e.jsx(St,{})}),e.jsx(Q,{onClick:I.onDropIndexClick(I.index),size:"small",color:"primary",sx:Ne,children:e.jsx(ut,{})})]},I.index)),e.jsxs(Se,{open:le,onClose:me,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Me,{children:"Select a device"}),e.jsxs(ke,{children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ie,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:J,onChange:ve,placeholder:"Enter serial or name"})]}),e.jsx(Je,{dense:!0,children:qe.filter(I=>I.serial.toLowerCase().includes(J.toLowerCase())||I.name.toLowerCase().includes(J.toLowerCase())).map((I,ue)=>e.jsxs(rt,{onClick:()=>be(I),sx:st,children:[I.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ge,{style:xe})}),I.icon==="ble"&&e.jsx(q,{children:e.jsx(ot,{style:xe})}),I.icon==="hub"&&e.jsx(q,{children:e.jsx(nt,{style:xe})}),e.jsx(te,{primary:I.name,secondary:I.serial,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ue))})]}),e.jsx(Fe,{children:e.jsx(oe,{onClick:me,children:"Close"})})]}),e.jsxs(Se,{open:U,onClose:K,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Me,{children:"Select an entity"}),e.jsxs(ke,{children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ie,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:J,onChange:ve,placeholder:"Enter name or description"})]}),e.jsx(Je,{dense:!0,children:xt.filter(I=>I.name.toLowerCase().includes(J.toLowerCase())||I.description.toLowerCase().includes(J.toLowerCase())).map((I,ue)=>e.jsxs(rt,{onClick:()=>Qe(I),sx:st,children:[I.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ge,{style:xe})}),I.icon==="ble"&&e.jsx(q,{children:e.jsx(ot,{style:xe})}),I.icon==="hub"&&e.jsx(q,{children:e.jsx(nt,{style:xe})}),I.icon==="component"&&e.jsx(q,{children:e.jsx(kt,{style:xe})}),I.icon==="matter"&&e.jsx(q,{children:e.jsx(It,{style:xe})}),e.jsx(te,{primary:I.name,secondary:I.description,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ue))})]}),e.jsx(Fe,{children:e.jsx(oe,{onClick:K,children:"Close"})})]}),e.jsxs(Se,{open:ee,onClose:ce,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsxs(Me,{children:["Select an entity for ",Y]}),e.jsx(ke,{children:e.jsx(Je,{dense:!0,children:qe.filter(I=>I.serial===Y||I.name===Y).map(I=>I.entities?.map((ue,Ke)=>e.jsxs(rt,{onClick:()=>B(ue),sx:st,children:[ue.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ge,{style:xe})}),ue.icon==="ble"&&e.jsx(q,{children:e.jsx(ot,{style:xe})}),ue.icon==="hub"&&e.jsx(q,{children:e.jsx(nt,{style:xe})}),ue.icon==="component"&&e.jsx(q,{children:e.jsx(kt,{style:xe})}),ue.icon==="matter"&&e.jsx(q,{children:e.jsx(It,{style:xe})}),e.jsx(te,{primary:ue.name,secondary:ue.description,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},Ke)))})}),e.jsx(Fe,{children:e.jsx(oe,{onClick:ce,children:"Close"})})]})]})}function ge(N){const{onAddClick:M,schema:F,properties:O,title:Y,description:le}=N,[de,U]=r.useState(!1),[u,ee]=r.useState(""),ae=K=>{ee(K.target.value)},J=()=>{U(!de)},Ce=K=>{i&&console.log(`ObjectFieldTemplate: handleSelectValue value "${K.serial}" for schema "${F.selectFrom}"`),U(!1);let ce="";F.selectFrom==="serial"?ce=K.serial:F.selectFrom==="name"&&(ce=K.name),A(ce),i&&console.log(`ObjectFieldTemplate: handleSelectValue newkey "${ce}"`),M(F)()},ve=()=>{M(F)()},me=!F.additionalProperties;return i&&console.log(`ObjectFieldTemplate: isRoot ${me} newkey "${W}"`),!me&&W!==""&&(i&&console.log("ObjectFieldTemplate: newkey",W,"properties",O),O.forEach(K=>{if(K.name==="newKey"&&K.content.key==="newKey"&&K.content.props.name==="newKey"&&K.content.props.onKeyChange&&W!==""){i&&console.log("ObjectFieldTemplate: newkey onKeyChange",W);const ce=W;A(""),K.content.props.onKeyChange(ce)}})),e.jsxs(X,{sx:{margin:"0px",padding:me?"10px":"5px 10px 0px 10px",border:me?"none":"1px solid grey"},children:[F.title&&me&&e.jsx(X,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(ie,{sx:Ae,children:F.title})}),Y&&!me&&e.jsxs(X,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[e.jsx(ie,{sx:Ae,children:Y}),e.jsxs(X,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[F.selectFrom&&e.jsx($,{title:"Add a device from the list",children:e.jsx(Q,{onClick:J,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),e.jsx($,{title:"Add a new item",children:e.jsx(Q,{onClick:ve,size:"small",color:"primary",sx:Ne,children:e.jsx(ct,{})})})]})]}),F.description&&e.jsx(X,{sx:{padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(ie,{sx:_e,children:F.description})}),O.map(({content:K,name:ce,hidden:be})=>!be&&e.jsxs(X,{sx:{margin:"0px",marginBottom:"10px",padding:["object","array","boolean"].includes(F.properties[ce].type)?"0px":Zo,border:["object","array","boolean"].includes(F.properties[ce].type)?"none":"1px solid grey"},children:[!["object","array","boolean"].includes(F.properties[ce].type)&&e.jsx(ie,{sx:Ae,children:ce}),e.jsx(X,{sx:{flexGrow:1,padding:"0px",margin:"0px"},children:K})]},ce)),e.jsxs(Se,{open:de,onClose:J,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(Me,{children:"Select a device"}),e.jsxs(ke,{children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ie,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:u,onChange:ae,placeholder:"Enter serial or name"})]}),e.jsx(Je,{dense:!0,children:qe.filter(K=>K.serial.toLowerCase().includes(u.toLowerCase())||K.name.toLowerCase().includes(u.toLowerCase())).map((K,ce)=>e.jsxs(rt,{onClick:()=>Ce(K),sx:st,children:[K.icon==="wifi"&&e.jsx(q,{children:e.jsx(Ge,{style:xe})}),K.icon==="ble"&&e.jsx(q,{children:e.jsx(ot,{style:xe})}),K.icon==="hub"&&e.jsx(q,{children:e.jsx(nt,{style:xe})}),e.jsx(te,{primary:K.name,secondary:K.serial,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ce))})]}),e.jsx(Fe,{children:e.jsx(oe,{onClick:J,children:"Close"})})]})]})}function fe(N){const{uiSchema:M}=N,{submitText:F,norender:O}=Wo(M);return O?null:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",margin:"10px",padding:"0px",gap:"20px"},children:[e.jsx(oe,{type:"submit",variant:"contained",color:"primary",children:F}),e.jsx(oe,{variant:"contained",color:"primary",onClick:m,children:"Cancel"})]})}function Ie(N){const{className:M,disabled:F,onClick:O,registry:Y,style:le,uiSchema:de,...U}=N;return e.jsx($,{title:"Remove the item",children:e.jsx(Q,{disabled:F,size:"small",color:"primary",onClick:O,children:e.jsx(ut,{})})})}function Z(N){const{className:M,disabled:F,onClick:O,registry:Y,uiSchema:le,...de}=N;return e.jsx($,{title:"Add an item",children:e.jsx(Q,{size:"small",color:"primary",onClick:O,children:e.jsx(ct,{})})})}function ne(N){const{disabled:M,onClick:F,registry:O,style:Y,uiSchema:le,...de}=N;return e.jsx($,{title:"Move up the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:F,children:e.jsx(Mt,{})})})}function L(N){const{disabled:M,onClick:F,registry:O,style:Y,uiSchema:le,...de}=N;return e.jsx($,{title:"Move down the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:F,children:e.jsx(St,{})})})}function E(N){const{id:M,name:F,value:O,schema:Y,readonly:le,onChange:de}=N,[U,u]=r.useState(),ee=J=>{i&&console.log(`CheckboxWidget ${F} onChangeField:`,J),u(J&&J!==""?J:void 0)},ae=()=>{i&&console.log(`CheckboxWidget onClick plugin="${c.name}" action="${F}" value="${U}"`),n({id:t.current,sender:"ConfigPlugin",method:"/api/action",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name,action:F,value:U,formData:f,id:M}}),Y.buttonClose===!0?m():Y.buttonSave===!0&&b({formData:x})};return Y.buttonText&&Y.description?e.jsxs(X,{sx:{margin:"0px",padding:"10px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(ie,{sx:_e,children:Y.description}),e.jsx(oe,{variant:"contained",color:"primary",onClick:()=>ae(),children:Y.buttonText})]}):Y.buttonField&&Y.description?e.jsxs(X,{sx:{margin:"0px",padding:"10px",gap:"20px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(ie,{sx:_e,children:Y.description}),e.jsx(pe,{id:F+"-input",name:F,label:Y.textLabel,placeholder:Y.textPlaceholder,onChange:J=>ee(J.target.value),sx:{width:"250px",minWidth:"250px",maxWidth:"250px"}}),e.jsx(oe,{id:F+"-button",variant:"contained",color:"primary",disabled:U===void 0,onClick:()=>ae(),children:Y.buttonField})]}):e.jsxs(X,{sx:{margin:"0px",padding:"5px 10px",border:"1px solid grey"},children:[F&&e.jsxs(X,{sx:{margin:"0px",padding:"0px",gap:"10px",display:"flex",justifyContent:"flex-start",alignItems:"center"},children:[e.jsx(ie,{sx:Ae,children:F}),e.jsx(Te,{checked:O,readOnly:le,onChange:()=>de(!O),sx:{padding:"0px",margin:"0px"}})]}),Y.description&&e.jsx(ie,{sx:_e,children:Y.description})]})}function S({schema:N,id:M,name:F,options:O,label:Y,hideLabel:le,required:de,disabled:U,placeholder:u,readonly:ee,value:ae,multiple:J,autofocus:Ce,onChange:ve,onBlur:me,onFocus:K,errorSchema:ce,rawErrors:be=[],registry:Qe,uiSchema:B,hideError:I,formContext:ue,...Ke}){const{enumOptions:Pe,enumDisabled:Ye,emptyValue:je}=O;J=typeof J>"u"?!1:!!J;const yt=J?[]:"",jt=typeof ae>"u"||J&&ae.length<1||!J&&ae===yt,Kt=({target:{value:De}})=>ve(ft(De,Pe,je)),Jt=({target:De})=>me(M,ft(De&&De.value,Pe,je)),Gt=({target:De})=>K(M,ft(De&&De.value,Pe,je)),Ct=No(ae,Pe,J),{InputLabelProps:Yt,SelectProps:Xt,autocomplete:Zt,...er}=Ke,tr=!J&&N.default===void 0;return e.jsxs(pe,{id:M,name:M,value:!jt&&typeof Ct<"u"?Ct:yt,required:de,disabled:U||ee,autoFocus:Ce,autoComplete:Zt,placeholder:u,error:be.length>0,onChange:Kt,onBlur:Jt,onFocus:Gt,...er,select:!0,InputLabelProps:{...Yt,shrink:!jt},SelectProps:{...Xt,multiple:J},"aria-describedby":Po(M),children:[tr&&e.jsx(D,{value:"",children:u}),Array.isArray(Pe)&&Pe.map(({value:De,label:rr},wt)=>{const or=Array.isArray(Ye)&&Ye.indexOf(De)!==-1;return e.jsx(D,{value:String(wt),disabled:or,children:rr},wt)})]})}return i&&console.log("ConfigPluginDialog rendering..."),!s||!g||!x?null:e.jsxs(Se,{open:s,onClose:m,slotProps:{paper:{sx:{maxWidth:"800px"}}},children:[e.jsx(Me,{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(ke,{style:{padding:"0px",margin:"0px",width:"800px",height:"600px",overflow:"auto"},children:e.jsx(Io,{schema:g,formData:x,uiSchema:V,validator:Do,templates:{FieldTemplate:k,BaseInputTemplate:o,TitleFieldTemplate:R,DescriptionFieldTemplate:H,FieldHelpTemplate:z,FieldErrorTemplate:a,ErrorListTemplate:j,WrapIfAdditionalTemplate:y,ArrayFieldTitleTemplate:l,ArrayFieldDescriptionTemplate:p,ArrayFieldItemTemplate:w,ArrayFieldTemplate:se,ObjectFieldTemplate:ge,ButtonTemplates:{SubmitButton:fe,RemoveButton:Ie,AddButton:Z,MoveUpButton:ne,MoveDownButton:L}},widgets:{CheckboxWidget:E,SelectWidget:S},onChange:G,onSubmit:b})})]})};function Qt(s){if(i&&console.log(`getQRColor (id: ${s?.id}) received matter:`,s??"undefined"),s===void 0||!s.online||!s.qrPairingCode&&!s.manualPairingCode&&!s.fabricInformations&&!s.sessionInformations)return"red";if(s.commissioned===!1&&s.qrPairingCode&&s.manualPairingCode)return"var(--primary-color)";let m=0,c=0;for(const n of s.sessionInformations??[])n.fabric&&n.isPeerActive===!0&&m++,n.numberOfActiveSubscriptions>0&&(c+=n.numberOfActiveSubscriptions);return s.commissioned===!0&&s.fabricInformations&&s.sessionInformations&&(m===0||c===0)?"var(--secondary-color)":"var(--div-text-color)"}function tn(s,m,c){const n=s?.[c],d=m?.[c];return n==null&&d==null?0:n==null?-1:d==null?1:typeof n=="boolean"&&typeof d=="boolean"?n===d?0:n?1:-1:typeof n=="number"&&typeof d=="number"?n-d:String(n).localeCompare(String(d))}function rn({name:s,title:m,columns:c,rows:n,getRowKey:d,footerLeft:v,footerRight:h,onRowClick:t}){const x=r.useRef(new WeakMap),P=r.useRef(1),g=a=>{if(typeof d=="string"&&a&&a[d]!=null)return a[d];if(typeof d=="function"){const p=d(a);if(p!=null)return p}const o=c?.[0]?.id;if(o&&a&&a[o]!=null)return a[o];console.warn(`MbfTable(${s}): using fallback stable row key; consider providing getRowKey prop for better React performance`);let l=x.current.get(a);return l||(l=`rk_${P.current++}`,x.current.set(a,l)),l},[C,V]=r.useState(localStorage.getItem(`${s}_table_order_by`)||null),[T,W]=r.useState(localStorage.getItem(`${s}_table_order`)||null),[A,f]=r.useState(!1),[G,b]=r.useState(()=>{try{const a=localStorage.getItem(`${s}_column_visibility`);if(a)return JSON.parse(a)}catch{}return{}}),y=r.useMemo(()=>{const a={};for(const o of c)o.hidden||(a[o.id]=o.required?!0:G[o.id]!==!1);return a},[c,G]),k=r.useMemo(()=>{if(!C||!T)return n;const a=c.find(l=>l.id===C);if(!a||a.noSort)return n;const o=n.map((l,p)=>({el:l,index:p}));return o.sort((l,p)=>{let w;return typeof a.comparator=="function"?w=a.comparator(l.el,p.el):w=tn(l.el,p.el,C),w!==0?T==="asc"?w:-w:l.index-p.index}),o.map(l=>l.el)},[n,C,T,c]),H=a=>{if(C!==a||!C){V(a),W("asc"),localStorage.setItem(`${s}_table_order_by`,a),localStorage.setItem(`${s}_table_order`,"asc");return}if(T==="asc"){W("desc"),localStorage.setItem(`${s}_table_order`,"desc");return}V(null),W(null),localStorage.removeItem(`${s}_table_order_by`),localStorage.removeItem(`${s}_table_order`)},R=()=>{f(!A)},z=a=>{b(o=>{const l=c.find(se=>se.id===a);if(l&&l.required)return o;const p=y[a]!==!1,w={...o};p?w[a]=!1:delete w[a];try{localStorage.setItem(`${s}_column_visibility`,JSON.stringify(w))}catch{}return w})},j=()=>{b({});try{localStorage.removeItem(`${s}_column_visibility`)}catch{}f(!1)};return i&&console.log(`Rendering table ${s}${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(Se,{open:A,onClose:(a,o)=>{o==="backdropClick"||o==="escapeKeyDown"||R()},disableEscapeKeyDown:!0,disableRestoreFocus:!0,children:[e.jsx(Me,{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 ${s} columns`})]})}),e.jsx(ke,{children:e.jsx(Cr,{children:c.filter(a=>!a.hidden).map(a=>e.jsx($e,{control:e.jsx(Te,{disabled:!!a.required,checked:a.required?!0:y[a.id]!==!1,onChange:()=>z(a.id)}),label:a.label},a.id))})}),e.jsxs(Fe,{children:[e.jsx(oe,{onClick:j,children:"Reset"}),e.jsx(oe,{variant:"contained",onClick:a=>{if(a?.currentTarget&&typeof a.currentTarget.blur=="function")try{a.currentTarget.blur()}catch{}const o=document.activeElement;if(o&&o instanceof HTMLElement&&typeof o.blur=="function")try{o.blur()}catch{}R()},children:"Close"})]})]}),e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between",borderBottom:"none"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:s}),m&&e.jsx("p",{className:"MbfWindowHeaderText",children:m}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(Q,{onClick:a=>{if(a?.currentTarget?.blur)try{a.currentTarget.blur()}catch{}R()},"aria-label":"Configure Columns",style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},children:e.jsx($,{title:`Configure ${s} 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":`${s} 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&&y[a.id]===!1)return null;const o=!a.noSort,l=o&&C===a.id&&!!T;return e.jsxs("th",{onClick:o?()=>H(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:o?"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":o?l?T==="asc"?"ascending":"descending":"none":void 0,children:[a.label,l&&e.jsxs("span",{style:{marginLeft:6},children:[T==="asc"&&e.jsx(re,{path:so,size:"15px"}),T==="desc"&&e.jsx(re,{path:ao,size:"15px"})]})]},a.id)})})}),e.jsx("tbody",{children:k.map((a,o)=>{const l=g(a);return e.jsx("tr",{className:o%2===0?"table-content-even":"table-content-odd",onClick:t?p=>t(a,l,p):void 0,style:{height:"30px",minHeight:"30px",border:"none",borderCollapse:"collapse",cursor:t?"pointer":void 0},children:c.map(p=>{if(p.hidden||!p.required&&y[p.id]===!1)return null;const w=a[p.id];return e.jsx("td",{style:{border:"none",borderCollapse:"collapse",textAlign:p.align||"left",padding:"5px 10px",margin:"0",maxWidth:p.maxWidth,whiteSpace:p.maxWidth?"nowrap":void 0,overflow:p.maxWidth?"hidden":void 0,textOverflow:p.maxWidth?"ellipsis":void 0},children:typeof p.render=="function"?p.render(w,l,a,p):typeof w=="boolean"?e.jsx(Te,{checked:w,disabled:!0,size:"small",sx:{m:0,p:0,color:"var(--table-text-color)","&.Mui-disabled":{color:"var(--table-text-color)",opacity:.7}}}):p.format&&typeof w=="number"?p.format(w):w!=null?String(w):null},p.id)})},l)})})]})}),(v||h)&&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:h})]})]})}function on(s){return r.memo(s)}const mt=on(rn);function nn({storeId:s,setStoreId:m}){const{online:c,sendMessage:n,addListener:d,removeListener:v,getUniqueId:h}=r.useContext(he),{showConfirmCancelDialog:t}=r.useContext(Be),x=r.useRef(h()),[P,g]=r.useState(null),[C,V]=r.useState(null),[T,W]=r.useState([]),A=[{label:"Name",id:"name",required:!0,render:(L,E,S,N)=>e.jsx($,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>a(S),children:S.name})})},{label:"Description",id:"description",render:(L,E,S,N)=>e.jsx($,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>a(S),children:S.description})})},{label:"Version",id:"version",render:(L,E,S,N)=>e.jsxs(e.Fragment,{children:[S.latestVersion!==void 0&&S.latestVersion!==S.version&&C&&!C.readOnly&&e.jsx($,{title:"New plugin stable version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>k(S),children:["Update to v.",S.latestVersion]})}),S.version.includes("-dev-")&&S.devVersion!==void 0&&S.devVersion!==S.version&&C&&!C.readOnly&&e.jsx($,{title:"New plugin dev version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>H(S),children:["Update to new dev v.",S.devVersion.split("-dev-")[0]]})}),e.jsx($,{title:"Plugin version",children:e.jsx("span",{children:S.version})})]})},{label:"Author",id:"author",render:(L,E,S,N)=>e.jsx(e.Fragment,{children:S.author?S.author.replace("https://github.com/",""):"Unknown"})},{label:"Type",id:"type",render:(L,E,S,N)=>e.jsx(e.Fragment,{children:S.type?S.type.replace("Platform",""):"Unknown"})},{label:"Devices",id:"registeredDevices"},{label:"Actions",id:"actions",required:!0,noSort:!0,render:(L,E,S,N)=>e.jsxs("div",{style:{margin:"0px",padding:"0px",gap:"4px",display:"flex",flexDirection:"row"},children:[C&&C.bridgeMode==="childbridge"&&!S.error&&S.enabled&&e.jsx($,{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(S.matter)},onClick:()=>{S.matter?.id&&m(S.matter?.id)},size:"small",children:e.jsx(At,{})})}),C&&C.bridgeMode==="childbridge"&&!S.error&&S.enabled&&e.jsx($,{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:()=>z(S),size:"small",children:e.jsx(dt,{})})}),e.jsx($,{title:"Plugin config",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{disabled:S.restartRequired===!0,style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>Ie(S),size:"small",children:e.jsx(vt,{})})}),C&&!C.readOnly&&e.jsx($,{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:()=>{G("Remove plugin","Are you sure? This will also remove all devices and configuration from the controller.","remove",S)},size:"small",children:e.jsx(ut,{})})}),S.enabled?e.jsx($,{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:()=>{G("Disable plugin","Are you sure? This will also remove all devices and configuration from the controller.","disable",S)},size:"small",children:e.jsx(wr,{})})}):e.jsx(e.Fragment,{}),S.enabled?e.jsx(e.Fragment,{}):e.jsx($,{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:()=>j(S),size:"small",children:e.jsx(Sr,{})})}),e.jsx($,{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:()=>l(S),size:"small",children:e.jsx(Mr,{})})}),e.jsx($,{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:()=>p(S),size:"small",children:e.jsx(kr,{})})}),C&&!C.readOnly&&e.jsx($,{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:()=>o(S),size:"small",children:e.jsx(Vt,{})})})]})},{label:"Status",id:"status",required:!0,noSort:!0,render:(L,E,S,N)=>e.jsx("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",margin:"0",padding:"0",gap:"5px",width:"auto",maxWidth:"max-content"},children:S.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:S.enabled===!1?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:S.enabled,enabledText:"Enabled",disabledText:"Disabled",tooltipText:"Whether the plugin is enable or disabled"})}):e.jsx(e.Fragment,{children:S.loaded&&S.started&&S.configured?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:S.loaded,enabledText:"Running",tooltipText:"Whether the plugin is running"})}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{status:S.loaded,enabledText:"Loaded",tooltipText:"Whether the plugin has been loaded"}),e.jsx(Ee,{status:S.started,enabledText:"Started",tooltipText:"Whether the plugin started"}),e.jsx(Ee,{status:S.configured,enabledText:"Configured",tooltipText:"Whether the plugin has been configured"})]})})})})}];r.useEffect(()=>{const L=E=>{E.src==="Matterbridge"&&E.dst==="Frontend"&&(E.method==="refresh_required"&&E.response.changed==="plugins"&&(i&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and sending /api/plugins request`),n({id:x.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),E.method==="refresh_required"&&E.response.changed==="matter"&&(i&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and setting matter id ${E.response.matter?.id}`),W(S=>{const N=S.findIndex(F=>F.matter?.id===E.response.matter?.id);if(N<0)return i&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and matter id ${E.response.matter?.id} not found`),S;i&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} set matter id ${E.response.matter?.id}`);const M=[...S];return M[N]={...M[N],matter:E.response.matter},M})),E.method==="refresh_required"&&E.response.changed==="settings"&&(i&&console.log(`HomePlugins received refresh_required: changed=${E.response.changed} and sending /api/settings request`),n({id:x.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),E.id===x.current&&E.method==="/api/settings"&&(i&&console.log(`HomePlugins (id: ${E.id}) received settings:`,E.response),g(E.response.systemInformation),V(E.response.matterbridgeInformation)),E.id===x.current&&E.method==="/api/plugins"&&(i&&console.log(`HomePlugins (id: ${E.id}) received ${E.response.length} plugins:`,E.response),W(E.response)))};return d(L,x.current),i&&console.log("HomePlugins added WebSocket listener id:",x.current),()=>{v(L),i&&console.log("HomePlugins removed WebSocket listener")}},[d,v,n]),r.useEffect(()=>{c&&(i&&console.log("HomePlugins sending api requests"),n({id:x.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),n({id:x.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,n]);const f=r.useRef(null),G=(L,E,S,N)=>{i&&console.log(`handleActionWithConfirmCancel ${S} ${N.name}`),f.current=N,t(L,E,S,b,y)},b=L=>{i&&console.log(`handleConfirm action confirmed ${L} ${f.current?.name}`),L==="remove"&&f.current?R(f.current):L==="disable"&&f.current&&j(f.current),f.current=null},y=L=>{i&&console.log(`handleCancel action canceled ${L} ${f.current?.name}`),f.current=null},k=L=>{i&&console.log("handleUpdatePlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:L.name,restart:!1}})},H=L=>{i&&console.log("handleUpdateDevPlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:L.name+"@dev",restart:!1}})},R=L=>{i&&console.log("handleRemovePlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/removeplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}})},z=L=>{i&&console.log("handleRestartPlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/restartplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}})},j=L=>{i&&console.log("handleEnableDisablePlugin plugin:",L.name,"enabled:",L.enabled),L.enabled===!0?(L.enabled=!1,n({id:x.current,sender:"HomePlugins",method:"/api/disableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}})):(L.enabled=!0,n({id:x.current,sender:"HomePlugins",method:"/api/enableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}}))},a=L=>{i&&console.log(`handleHomepagePlugin plugin: ${L.name} homepage: ${L.homepage}`),L.homepage&&window.open(L.homepage,"_blank")},o=L=>{i&&console.log("handleSponsorPlugin plugin:",L.name,"funding:",L.funding),L.funding&&window.open(L.funding,"_blank")},l=L=>{i&&console.log("handleHelpPlugin plugin:",L.name,"help:",L.help),L.help&&window.open(L.help,"_blank")},p=L=>{i&&console.log("handleChangelogPlugin plugin:",L.name,"changelog:",L.changelog),L.changelog&&window.open(L.changelog,"_blank")},[w,se]=r.useState(),[ge,fe]=r.useState(!1),Ie=L=>{i&&console.log("handleConfigPlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:L.name}}),n({id:x.current,sender:"HomePlugins",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:L.name}}),se(L),Z()},Z=()=>{fe(!0)},ne=()=>{fe(!1)};return i&&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:[w&&e.jsx(en,{open:ge,onClose:ne,plugin:w}),e.jsx(mt,{name:"Plugins",columns:A,rows:T,footerRight:"",footerLeft:""})]}):e.jsx(Re,{})}const sn=r.memo(nn),an=s=>`${s.pluginName}::${s.serial}`;function ln({storeId:s,setStoreId:m}){const{online:c,sendMessage:n,addListener:d,removeListener:v,getUniqueId:h}=r.useContext(he),[t,x]=r.useState(!1),[P,g]=r.useState(!0),[C,V]=r.useState(null),[T,W]=r.useState([]),[A,f]=r.useState([]),[G,b]=r.useState([]),[y,k]=r.useState([]),H=r.useRef(h()),R=[{label:"Plugin",id:"pluginName"},{label:"Name",id:"name",required:!0},{label:"Serial",id:"serial"},{label:"Availability",id:"availability",render:(a,o,l,p)=>l.reachable===!0?"Online":l.reachable===!1?e.jsx("span",{style:{color:"red"},children:"Offline"}):"",comparator:(a,o)=>{const l=a.reachable===!0?1:a.reachable===!1?0:-1,p=o.reachable===!0?1:o.reachable===!1?0:-1;return l-p}},{label:"Power",id:"powerSource",render:(a,o,l,p)=>l.powerSource==="ac"||l.powerSource==="dc"?e.jsx(_t,{fontSize:"small",sx:{color:"var(--primary-color)"}}):l.powerSource==="ok"?e.jsx(pt,{fontSize:"small",sx:{color:"green"}}):l.powerSource==="warning"?e.jsx(pt,{fontSize:"small",sx:{color:"yellow"}}):l.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,o,l,p)=>e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[l.matter!==void 0?e.jsx($,{title:"Show the QRCode or the fabrics",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{onClick:()=>m(s===l.matter?.id?C?.matterbridgeInformation.bridgeMode==="bridge"?"Matterbridge":null:l.matter?.id||null),"aria-label":"Show the QRCode",sx:{margin:0,padding:0,color:Qt(l.matter)},children:e.jsx(At,{fontSize:"small"})})}):e.jsx("div",{style:{width:"20px",height:"20px"}}),l.configUrl?e.jsx($,{title:"Open the configuration page",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Q,{onClick:()=>window.open(l.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"}}),l.selected!==void 0?e.jsx($,{title:"Select/unselect the device",slotProps:{popper:{modifiers:[{name:"offset",options:{offset:[30,15]}}]}},children:e.jsx(Te,{checked:l.selected,onChange:w=>j(w,l),sx:{margin:"0",marginLeft:"8px",padding:"0"},size:"small"})}):e.jsx("div",{style:{width:"20px",height:"20px"}})]})}],z=r.useCallback(a=>{a.selected=void 0;const o=T.find(w=>w.name===a.pluginName);if(!o)return console.error(`HomeDevices isSelected: plugin ${a.pluginName} not found for device ${a.name} `),a.selected;const l=o.schemaJson?.properties?.whiteList?.selectFrom;let p=o.configJson.postfix;return p===""&&(p=void 0),o.hasWhiteList===!0&&o.hasBlackList===!0&&l&&(a.selected=!0,l==="serial"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&o.configJson.whiteList.includes(p?a.serial.replace("-"+p,""):a.serial)&&(a.selected=!0),l==="serial"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&!o.configJson.whiteList.includes(p?a.serial.replace("-"+p,""):a.serial)&&(a.selected=!1),l==="serial"&&o.configJson.blackList&&o.configJson.blackList.length>0&&o.configJson.blackList.includes(p?a.serial.replace("-"+p,""):a.serial)&&(a.selected=!1),l==="name"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&o.configJson.whiteList.includes(a.name)&&(a.selected=!0),l==="name"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&!o.configJson.whiteList.includes(a.name)&&(a.selected=!1),l==="name"&&o.configJson.blackList&&o.configJson.blackList.length>0&&o.configJson.blackList.includes(a.name)&&(a.selected=!1)),a.selected},[T]);r.useEffect(()=>{const a=o=>{if(o.method==="refresh_required"&&o.response.changed!=="matter"?(i&&console.log(`HomeDevices received refresh_required: changed=${o.response.changed} and sending /api/plugins request`),n({id:H.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})):o.method==="refresh_required"&&o.response.changed==="matter"?(i&&console.log(`HomeDevices received refresh_required: changed=${o.response.changed} and setting matter id ${o.response.matter?.id}`),k(l=>{const p=l.findIndex(se=>se.name.replaceAll(" ","")===o.response.matter?.id);if(p<0)return i&&console.debug(`HomeDevices: matter id ${o.response.matter?.id} not found`),l;const w=[...l];return w[p]={...w[p],matter:o.response.matter},i&&console.log(`HomeDevices received refresh_required: changed=${o.response.changed} and set matter id ${o.response.matter?.id}`),w})):o.method==="restart_required"?(i&&console.log("HomeDevices received restart_required"),x(!0)):o.method==="restart_not_required"?(i&&console.log("HomeDevices received restart_not_required"),x(!1)):o.method==="state_update"&&o.response.plugin&&o.response.serialNumber&&o.response.cluster.includes("BasicInformation")&&o.response.attribute==="reachable"&&(console.log(`HomeDevices updating device reachability for plugin ${o.response.plugin} serial ${o.response.serialNumber} value ${o.response.value}`),f(l=>{const p=l.findIndex(w=>w.pluginName===o.response.plugin&&w.serial===o.response.serialNumber);return p<0?(console.warn(`HomeDevices: device to update not found for plugin ${o.response.plugin} serial ${o.response.serialNumber}`),l):(l[p]={...l[p],reachable:o.response.value},[...l])})),o.id===H.current&&o.method==="/api/settings")i&&console.log(`HomeDevices (id: ${o.id}) received settings:`,o.response),V(o.response),x(o.response.matterbridgeInformation.restartRequired||o.response.matterbridgeInformation.fixedRestartRequired);else if(o.id===H.current&&o.method==="/api/plugins"){if(i&&console.log(`HomeDevices (id: ${o.id}) received ${o.response?.length} plugins:`,o.response),o.response){let l=!0;for(const p of o.response)p.enabled===!0&&(p.loaded!==!0||p.started!==!0||p.error===!0)&&(l=!1);if(!l)return;i&&console.log("HomeDevices reset plugins, devices and selectDevices"),g(!1),W(o.response),f([]),b([]),n({id:H.current,sender:"HomeDevices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}),i&&console.log("HomeDevices sent /api/devices");for(const p of o.response)p.enabled===!0&&p.loaded===!0&&p.started===!0&&p.error!==!0&&(n({id:H.current,sender:"HomeDevices",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:p.name}}),i&&console.log(`HomeDevices sent /api/select/devices for plugin: ${p.name}`))}}else if(o.id===H.current&&o.method==="/api/devices"){if(i&&console.log(`HomeDevices (id: ${o.id}) received ${o.response?.length} devices:`,o.response),o.response){for(const l of o.response)l.selected=z(l);f(o.response)}}else o.id===H.current&&o.method==="/api/select/devices"&&(i&&console.log(`HomeDevices (id: ${o.id}) received ${o.response?.length} selectDevices for plugin ${o.response&&o.response.length>0?o.response[0].pluginName:"without select devices"}:`,o.response),o.response&&o.response.length>0&&b(l=>{const p=l.filter(se=>se.pluginName!==o.response[0].pluginName),w=o.response.map(se=>({...se,selected:z(se)}));return[...p,...w]}))};return d(a,H.current),i&&console.log(`HomeDevices added WebSocket listener id ${H.current}`),()=>{v(a),i&&console.log("HomeDevices removed WebSocket listener")}},[T,d,v,n,z]),r.useEffect(()=>{if(A.length===0&&G.length===0){k([]);return}i&&console.log(`HomeDevices mixing devices (${A.length}) and selectDevices (${G.length})`);const a=[];for(const o of A)a.push(o);for(const o of G)A.find(l=>l.pluginName===o.pluginName&&l.serial.includes(o.serial))||a.push(o);a.length>0&&(k(a),console.log(`HomeDevices mixed ${a.length} devices and selectDevices`))},[T,A,G,k]),r.useEffect(()=>{c&&(i&&console.log("HomeDevices sending /api/settings and /api/plugins requests"),n({id:H.current,sender:"HomeDevices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),n({id:H.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,n]);const j=(a,o)=>{console.log(`handleCheckboxChange: checkbox changed to ${a.target.checked} for device ${o.name} serial ${o.serial}`),A.findIndex(l=>l.pluginName===o.pluginName&&l.serial===o.serial)<0?(i&&console.warn(`handleCheckboxChange: device ${o.name} serial ${o.serial} not found in devices, trying in mixedDevices`),k(l=>{const p=l.findIndex(w=>w.pluginName===o.pluginName&&w.serial===o.serial);return p<0?(console.error(`handleCheckboxChange: device ${o.name} serial ${o.serial} not found in mixedDevices`),l):(l[p]={...l[p],selected:a.target.checked},[...l])})):f(l=>{const p=l.findIndex(w=>w.pluginName===o.pluginName&&w.serial===o.serial);return p<0?(console.error(`handleCheckboxChange: device ${o.name} serial ${o.serial} not found in devices`),l):(l[p]={...l[p],selected:a.target.checked},[...l])}),a.target.checked?n({id:H.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"selectdevice",plugin:o.pluginName,serial:o.serial,name:o.name}}):n({id:H.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"unselectdevice",plugin:o.pluginName,serial:o.serial,name:o.name}})};return i&&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(mt,{name:"Devices",getRowKey:an,rows:y,columns:R,footerLeft:P?"Waiting for the plugins to fully load...":`Registered devices: ${A.length.toString()}/${y.length.toString()}`,footerRight:t?"Restart required":""})}):e.jsx(Re,{})}const dn=r.memo(ln);function cn(){const[s,m]=r.useState(null),[c,n]=r.useState(null),[d,v]=r.useState([]),[h]=r.useState(localStorage.getItem("homePagePlugins")!=="false"),[t,x]=r.useState(localStorage.getItem("homePageMode")??"devices"),[P,g]=r.useState(""),[C,V]=r.useState(!1),[T,W]=r.useState(!1),[A,f]=r.useState(null),{addListener:G,removeListener:b,online:y,sendMessage:k,logFilterLevel:H,logFilterSearch:R,autoScroll:z,getUniqueId:j}=r.useContext(he),a=r.useRef(j());return r.useEffect(()=>{const o=l=>{l.src==="Matterbridge"&&l.dst==="Frontend"&&(l.method==="refresh_required"&&l.response.changed==="settings"&&(i&&console.log(`Home received refresh_required: changed=${l.response.changed} and sending /api/settings request`),f(null),v([]),k({id:a.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),k({id:a.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),l.method==="/api/settings"&&l.id===a.current&&(i&&console.log("Home received settings:",l.response),m(l.response.systemInformation),n(l.response.matterbridgeInformation),l.response.matterbridgeInformation.bridgeMode==="bridge"&&(A||f("Matterbridge")),l.response.matterbridgeInformation.bridgeMode==="childbridge"&&d.length>0&&A===null&&!A&&d.length>0&&d[0].matter?.id&&f(d[0].matter.id),l.response.matterbridgeInformation.matterbridgeVersion&&g(`https://github.com/Luligu/matterbridge/blob/${l.response.matterbridgeInformation.matterbridgeVersion.includes("-dev-")?"dev":"main"}/CHANGELOG.md`),localStorage.getItem("frontendVersion")===null&&l.response.matterbridgeInformation.frontendVersion?localStorage.setItem("frontendVersion",l.response.matterbridgeInformation.frontendVersion):l.response.matterbridgeInformation.frontendVersion!==localStorage.getItem("frontendVersion")&&l.response.matterbridgeInformation.frontendVersion&&(localStorage.setItem("frontendVersion",l.response.matterbridgeInformation.frontendVersion),W(!0)),localStorage.getItem("matterbridgeVersion")===null?localStorage.setItem("matterbridgeVersion",l.response.matterbridgeInformation.matterbridgeVersion):l.response.matterbridgeInformation.matterbridgeVersion!==localStorage.getItem("matterbridgeVersion")&&(localStorage.setItem("matterbridgeVersion",l.response.matterbridgeInformation.matterbridgeVersion),V(!0)),l.response.matterbridgeInformation.shellyBoard&&(localStorage.getItem("homePageMode")||(localStorage.setItem("homePageMode","devices"),x("devices")))),l.method==="/api/plugins"&&l.id===a.current&&(i&&console.log(`Home received plugins (${c?.bridgeMode}):`,l.response),v(l.response),c?.bridgeMode==="childbridge"&&l.response.length>0&&!A&&l.response.length>0&&l.response[0].matter?.id&&f(l.response[0].matter.id)))};return G(o,a.current),i&&console.log(`Home added WebSocket listener id ${a.current}`),()=>{b(o),i&&console.log("Home removed WebSocket listener")}},[G,b,k,c,d,A]),r.useEffect(()=>{y&&(i&&console.log("Home received online"),k({id:a.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),k({id:a.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[y,k]),i&&console.log("Home rendering..."),!y||!s||!c?e.jsx(Re,{}):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(Ko,{id:A}),e.jsx(Uo,{systemInfo:s,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(oe,{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"})})]})]}),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(oe,{onClick:()=>window.open(P,"_blank"),endIcon:e.jsx(Et,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Changelog"}),e.jsx(oe,{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"})]})]})]}),h&&!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(Go,{})]}),h&&e.jsx(sn,{storeId:A,setStoreId:f}),t==="devices"&&e.jsx(dn,{storeId:A,setStoreId:f}),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 "',R,'" Scroll: ',z?"auto":"manual"]})})]}),e.jsx("div",{style:{flex:"1 1 auto",margin:"0px",padding:"10px",overflow:"auto"},children:e.jsx(Bt,{})})]})]})]})}const pn=r.memo(cn),Ht={display:"flex",gap:"2px",justifyContent:"space-evenly",width:"100%",height:"40px"},un={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"},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"},hn={margin:"0",padding:"0",fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)"},fn={display:"flex",justifyContent:"center",width:"100%",height:"52px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},xn={margin:"0",padding:"0",fontSize:"14px",fontWeight:"bold",color:"var(--div-text-color)"},bn={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)"},vn=[256,257,268,269],yn=[266,267],jn=[259,260,261,271,272],Cn=[256,257,268,269,266,267,259,260,261,272];function _({icon:s,iconColor:m,cluster:c,value:n,unit:d,prefix:v}){return i&&console.log(`Render cluster "${c.clusterName}.${c.attributeName}" value(${typeof n}-${isNaN(n)}) "${n}" unit "${d}"`),v=v??!1,e.jsxs(X,{sx:Ht,children:[s&&r.cloneElement(s,{key:`${c.clusterId}-${c.attributeId}-icon`,sx:{...un,color:m??"var(--primary-color)"}}),e.jsxs(X,{sx:{...Ht,gap:"4px",alignContent:"center",alignItems:"end",justifyContent:"center"},children:[d&&v===!0&&e.jsx(ie,{sx:Ot,children:d},`${c.clusterId}-${c.attributeId}-unit`),e.jsx(ie,{sx:gn,children:n==null||typeof n=="number"&&isNaN(n)||n==="NaN"?"---":n},`${c.clusterId}-${c.attributeId}-value`),d&&v===!1&&e.jsx(ie,{sx:Ot,children:d},`${c.clusterId}-${c.attributeId}-unit`)]},`${c.clusterId}-${c.attributeId}-valueunitbox`)]},`${c.clusterId}-${c.attributeId}-box`)}function wn({device:s,endpoint:m,id:c,deviceType:n,clusters:d}){const v=["Unknown","Good","Fair","Moderate","Poor","VeryPoor","Ext.Poor"];let h="";return i&&console.log(`Device "${s.name}" endpoint "${m}" id "${c}" deviceType "0x${n.toString(16).padStart(4,"0")}" clusters (${d?.length}):`,d),n===17&&d.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batVoltage").map(t=>h=`${t.attributeLocalValue} mV`),Cn.includes(n)&&d.filter(t=>t.clusterName==="LevelControl"&&t.attributeName==="currentLevel").map(t=>h=`Level ${t.attributeValue}`),n===514&&d.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>h=`Position ${t.attributeLocalValue/100}%`),n===769&&d.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedHeatingSetpoint").map(t=>h=`Heat ${t.attributeLocalValue/100}°C `),n===769&&d.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedCoolingSetpoint").map(t=>h=h+`Cool ${t.attributeLocalValue/100}°C`),n===118&&d.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>h=`${t.attributeLocalValue===0?"No CO detected":"CO alarm!"}`),n===1296&&d.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="voltage").map(t=>h=`${t.attributeLocalValue/1e3} V, `),n===1296&&d.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activeCurrent").map(t=>h=h+`${t.attributeLocalValue/1e3} A, `),n===1296&&d.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activePower").map(t=>h=h+`${t.attributeLocalValue/1e3} W`),e.jsxs("div",{className:"MbfWindowDiv",style:{margin:"0px",padding:"5px",width:"150px",height:"150px",borderColor:"var(--div-bg-color)",borderRadius:"5px",justifyContent:"space-between"},children:[n===19&&d.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(_,{icon:t.attributeLocalValue===!0?e.jsx(Ge,{}):e.jsx(Nr,{}),iconColor:t.attributeLocalValue===!0?"green":"red",cluster:t,value:t.attributeLocalValue===!0?"Online":"Offline"})),n===17&&d.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batPercentRemaining").map(t=>e.jsx(_,{icon:e.jsx(pt,{}),cluster:t,value:t.attributeLocalValue/2,unit:"%"})),n===17&&d.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="wiredCurrentType").map(t=>e.jsx(_,{icon:e.jsx(_t,{}),cluster:t,value:t.attributeLocalValue===0?"AC":"DC"})),n===1293&&d.filter(t=>t.clusterName==="DeviceEnergyManagement"&&t.attributeName==="esaState").map(t=>e.jsx(_,{icon:e.jsx(re,{path:lo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Offline":"Online"})),vn.includes(n)&&d.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(_,{icon:e.jsx(Pr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),yn.includes(n)&&d.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(_,{icon:e.jsx(re,{path:co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),jn.includes(n)&&d.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(_,{icon:e.jsx(re,{path:po,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),n===115&&d.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(_,{icon:e.jsx(re,{path:uo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===124&&d.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(_,{icon:e.jsx(re,{path:go,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===117&&d.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(_,{icon:e.jsx(re,{path:mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===123&&d.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(_,{icon:e.jsx(Dt,{}),cluster:t,value:"Oven"})),n===112&&d.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(_,{icon:e.jsx(Wr,{}),cluster:t,value:"Fridge"})),n===113&&d.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(_,{icon:e.jsx(re,{path:ho,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===121&&d.filter(t=>t.clusterName==="OperationalState"&&t.attributeName==="operationalState").map(t=>e.jsx(_,{icon:e.jsx(Dt,{}),cluster:t,value:t.attributeLocalValue===0?"Normal":"Error"})),n===122&&d.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="fanMode").map(t=>e.jsx(_,{icon:e.jsx(re,{path:fo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===120&&d.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(_,{icon:e.jsx(re,{path:Ft,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Cooktop"})),n===119&&d.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(_,{icon:e.jsx(re,{path:Ft,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===116&&d.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(_,{icon:e.jsx(re,{path:xo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Robot"})),n===514&&d.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>e.jsx(_,{icon:e.jsx(Lr,{}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),n===769&&d.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(_,{icon:e.jsx(re,{path:bo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),n===10&&d.filter(t=>t.clusterName==="DoorLock"&&t.attributeName==="lockState").map(t=>e.jsx(_,{icon:t.attributeValue==="1"?e.jsx(Fr,{}):e.jsx($r,{}),cluster:t,value:t.attributeValue==="1"?"Locked":"Unlocked"})),n===43&&d.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(_,{icon:e.jsx(Tr,{}),cluster:t,value:t.attributeValue,unit:"%"})),n===15&&d.filter(t=>t.clusterName==="Switch"&&t.attributeName==="currentPosition").map(t=>e.jsx(_,{icon:e.jsx(re,{path:vo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeValue,unit:"pos",prefix:!0})),n===39&&d.filter(t=>t.clusterName==="ModeSelect"&&t.attributeName==="currentMode").map(t=>e.jsx(_,{icon:e.jsx(Rr,{}),cluster:t,value:t.attributeValue,unit:"mode",prefix:!0})),n===771&&d.filter(t=>t.clusterName==="OnOff"&&t.attributeName==="onOff").map(t=>e.jsx(_,{icon:e.jsx(Hr,{}),cluster:t,value:t.attributeLocalValue===!0?"On":"Off"})),n===45&&d.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(_,{icon:e.jsx(Nt,{}),cluster:t,value:t.attributeValue,unit:"%"})),n===114&&d.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="localTemperature").map(t=>e.jsx(_,{icon:e.jsx(Nt,{}),cluster:t,value:(t.attributeLocalValue??0)/100,unit:"°C"})),n===67&&d.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(_,{icon:e.jsx(Or,{}),cluster:t,value:t.attributeLocalValue===!0?"Leak":"No leak"})),n===65&&d.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(_,{icon:e.jsx(Vr,{}),cluster:t,value:t.attributeLocalValue===!0?"Freeze":"No freeze"})),n===68&&d.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(_,{icon:e.jsx(Er,{}),cluster:t,value:t.attributeLocalValue===!0?"Rain":"No rain"})),n===1292&&d.filter(t=>t.clusterName==="EnergyEvse"&&t.attributeName==="state").map(t=>e.jsx(_,{icon:e.jsx(re,{path:yo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"Free":"In use"})),n===1295&&d.filter(t=>t.clusterName==="WaterHeaterManagement"&&t.attributeName==="tankPercentage").map(t=>e.jsx(_,{icon:e.jsx(re,{path:jo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Tank "+(t.attributeLocalValue??0)+"%"})),n===777&&d.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(_,{icon:e.jsx(re,{path:Co,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"HeatPump"})),n===23&&d.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="featureMap").map(t=>e.jsx(_,{icon:e.jsx(re,{path:wo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Solar"})),n===24&&d.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="featureMap").map(t=>e.jsx(_,{icon:e.jsx(re,{path:So,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Inverter"})),n===118&&d.find(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="featureMap"&&t.attributeLocalValue.smokeAlarm===!0)&&d.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="smokeState").map(t=>e.jsx(_,{icon:e.jsx(re,{path:$t,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No smoke":"Smoke!"})),n===118&&d.find(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="featureMap"&&t.attributeLocalValue.smokeAlarm===!1)&&d.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>e.jsx(_,{icon:e.jsx(re,{path:$t,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No Co":"Co!"})),n===66&&d.filter(t=>t.clusterName==="ValveConfigurationAndControl"&&t.attributeName==="currentState").map(t=>e.jsx(_,{icon:e.jsx(Ar,{}),cluster:t,value:t.attributeLocalValue===0?"Closed":"Opened"})),n===44&&d.filter(t=>t.clusterName==="AirQuality"&&t.attributeName==="airQuality").map(t=>e.jsx(_,{icon:e.jsx(re,{path:Mo,size:"40px",color:"var(--primary-color)"}),cluster:t,value:v[t.attributeLocalValue??0]})),n===770&&d.filter(t=>t.clusterName==="TemperatureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(_,{icon:e.jsx(_r,{}),cluster:t,value:t.attributeLocalValue/100,unit:"°C"})),n===775&&d.filter(t=>t.clusterName==="RelativeHumidityMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(_,{icon:e.jsx(re,{path:ko,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue/100,unit:"%"})),n===774&&d.filter(t=>t.clusterName==="FlowMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(_,{icon:e.jsx(qr,{}),cluster:t,value:t.attributeLocalValue,unit:"l/h"})),n===773&&d.filter(t=>t.clusterName==="PressureMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(_,{icon:e.jsx(zr,{}),cluster:t,value:t.attributeLocalValue,unit:"hPa"})),n===21&&d.filter(t=>t.clusterName==="BooleanState"&&t.attributeName==="stateValue").map(t=>e.jsx(_,{icon:t.attributeValue==="true"?e.jsx(Ur,{}):e.jsx(Br,{}),cluster:t,value:t.attributeValue==="true"?"Closed":"Opened"})),n===263&&d.filter(t=>t.clusterName==="OccupancySensing"&&t.attributeName==="occupancy").map(t=>e.jsx(_,{icon:t.attributeValue==="{ occupied: true }"?e.jsx(Qr,{}):e.jsx(Kr,{}),cluster:t,value:t.attributeValue==="{ occupied: true }"?"Occupied":"Unocc."})),n===262&&d.filter(t=>t.clusterName==="IlluminanceMeasurement"&&t.attributeName==="measuredValue").map(t=>e.jsx(_,{icon:e.jsx(Jr,{}),cluster:t,value:Math.round(Math.pow(10,t.attributeLocalValue/1e4)),unit:"lx"})),n===1296&&d.filter(t=>t.clusterName==="ElectricalEnergyMeasurement"&&t.attributeName==="cumulativeEnergyImported").map(t=>e.jsx(_,{icon:e.jsx(Gr,{}),cluster:t,value:Math.round(t.attributeLocalValue?.energy/1e6),unit:"kwh"})),e.jsx(X,{sx:mn,children:e.jsx(ie,{sx:hn,children:h})}),e.jsx(X,{sx:fn,children:e.jsx(ie,{sx:xn,children:s.name})}),e.jsxs(X,{sx:bn,children:[i&&e.jsx(ie,{sx:bt,children:m}),e.jsx(ie,{sx:bt,children:c}),i&&e.jsxs(ie,{sx:bt,children:["0x",n.toString(16).padStart(4,"0")]})]})]})}function Sn({filter:s}){const{online:m,sendMessage:c,addListener:n,removeListener:d,getUniqueId:v}=r.useContext(he),[h,t]=r.useState(null),[x,P]=r.useState([]),[g,C]=r.useState([]),[V,T]=r.useState(g),[W,A]=r.useState({}),[f,G]=r.useState({}),[b,y]=r.useState({}),k=r.useRef(v()),H=r.useRef(V),R=r.useCallback(j=>{console.log(`DevicesIcons received state_update "${j.response.cluster}.${j.response.attribute}" for "${j.response.id}:${j.response.number}": "${j.response.value}"`,j.response);const a=H.current.find(l=>l.pluginName===j.response.plugin&&l.uniqueId===j.response.uniqueId);if(!a){console.warn(`DevicesIcons updater device of plugin "${j.response.plugin}" serial "${j.response.serialNumber}" not found in filteredDevicesRef.current`);return}const o=b[a.serial].find(l=>l.endpoint===j.response.number.toString()&&l.clusterName===j.response.cluster&&l.attributeName===j.response.attribute);if(!o){console.warn(`DevicesIcons updater device "${a.name}" serial "${a.serial}" cluster "${j.response.cluster}" attribute "${j.response.attribute}" not found in clusters`);return}o.attributeValue=String(j.response.value),o.attributeLocalValue=j.response.value,y({...b}),console.log(`DevicesIcons updated "${o.clusterName}.${o.attributeName}" for device "${a.name}" serial "${a.serial}" to "${o.attributeValue}"`)},[b]);r.useEffect(()=>{const j=a=>{if(a.method==="refresh_required")i&&console.log(`DevicesIcons received refresh_required: changed=${a.response.changed} and sending api requests`),c({id:k.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}});else if(a.method==="state_update"&&a.response)R(a);else if(a.method==="/api/settings"&&a.response)i&&console.log("DevicesIcons received settings:",a.response),t(a.response);else if(a.method==="/api/plugins"&&a.response)i&&console.log("DevicesIcons received plugins:",a.response),P(a.response);else if(a.method==="/api/devices"&&a.response){i&&console.log(`DevicesIcons received ${a.response.length} devices:`,a.response),C(a.response);for(const o of a.response)i&&console.log("DevicesIcons sending /api/clusters"),c({id:k.current,sender:"DevicesIcons",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:o.pluginName,endpoint:o.endpoint||0}})}else if(a.method==="/api/clusters"&&a.response){if(i&&console.log(`DevicesIcons received for device "${a.response.deviceName}" serial "${a.response.serialNumber}" deviceTypes (${a.response.deviceTypes.length}) "${a.response.deviceTypes.join(",")}" clusters (${a.response.clusters.length}):`,a.response),a.response.clusters.length===0)return;const o=a.response.serialNumber;W[o]=[],f[o]=a.response.deviceTypes,b[o]=[];for(const l of a.response.clusters)W[o].find(p=>p.endpoint===l.endpoint)||W[o].push({endpoint:l.endpoint,id:l.id,deviceTypes:l.deviceTypes}),!["FixedLabel","Descriptor","Identify","Groups","PowerTopology"].includes(l.clusterName)&&b[o].push(l);A({...W}),G({...f}),y({...b}),i&&console.log(`DevicesIcons endpoints for "${o}":`,W[o]),i&&console.log(`DevicesIcons deviceTypes for "${o}":`,f[o]),i&&console.log(`DevicesIcons clusters for "${o}":`,b[o])}};return n(j,k.current),i&&console.log("DevicesIcons useEffect webSocket mounted"),()=>{d(j),i&&console.log("DevicesIcons useEffect webSocket unmounted")}},[]),r.useEffect(()=>(i&&console.log("DevicesIcons useEffect online mounting"),m&&(i&&console.log("DevicesIcons useEffect online sending api requests"),c({id:k.current,sender:"DevicesIcons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"DevicesIcons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"DevicesIcons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),i&&console.log("DevicesIcons useEffect online mounted"),()=>{i&&console.log("DevicesIcons useEffect online unmounted")}),[m,c]),r.useEffect(()=>{if(s===""){T(g),H.current=g;return}const j=g.filter(a=>a.name.toLowerCase().includes(s)||a.serial.toLowerCase().includes(s));T(j),H.current=j},[g,s]);const z=r.memo(wn);return i&&console.log("DevicesIcons rendering..."),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"auto"},children:V.map(j=>W[j.serial]&&W[j.serial].map(a=>a.deviceTypes.map(o=>e.jsx(z,{device:j,endpoint:a.endpoint,id:a.id,deviceType:o,clusters:b[j.serial].filter(l=>l.endpoint===a.endpoint)},`${j.pluginName}-${j.uniqueId}-${a.id}-${o.toString()}`))))})}const Mn=r.memo(Sn),kn=[{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:(s,m,c,n)=>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"}],In=[{label:"Endpoint",id:"endpoint",required:!0},{label:"Id",id:"id"},{label:"Device Types",id:"deviceTypes",render:(s,m,c,n)=>Array.isArray(s)?e.jsx(e.Fragment,{children:s.map(d=>`0x${d.toString(16).padStart(4,"0")}`).join(", ")}):e.jsx(e.Fragment,{children:s})},{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:(s,m,c,n)=>e.jsx($,{title:String(s),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(s)})})}],Dn=s=>`${s.pluginName}::${s.uniqueId}`,Nn=s=>`${s.endpoint}::${s.clusterName}::${s.attributeName}`;function Pn({filter:s}){const{online:m,sendMessage:c,addListener:n,removeListener:d,getUniqueId:v}=r.useContext(he),[h,t]=r.useState([]),[x,P]=r.useState(h),[g,C]=r.useState([]),[V,T]=r.useState(0),[W,A]=r.useState(null),[f,G]=r.useState(null),[b,y]=r.useState(null),[k,H]=r.useState(null),R=r.useRef(v()),z=r.useRef(x),j=r.useCallback(o=>{console.log(`DevicesTable received state_update "${o.response.cluster}.${o.response.attribute}" for "${o.response.id}:${o.response.number}": "${o.response.value}"`,o.response);const l=z.current.find(p=>p.pluginName===o.response.plugin&&p.uniqueId===o.response.uniqueId);if(!l){console.warn(`DevicesTable updater device of plugin "${o.response.plugin}" serial "${o.response.serialNumber}" not found in filteredDevicesRef.current`);return}if(W&&f&&l.pluginName===W&&l.uniqueId===k&&o.response.number.toString()===f){const p=g.find(w=>w.endpoint===o.response.number.toString()&&w.clusterName===o.response.cluster&&w.attributeName===o.response.attribute);if(!p){console.warn(`DevicesTable updater cluster ${o.response.cluster}.${o.response.attribute} for device "${l.name}" serial "${l.serial}" not found in clusters`);return}p.attributeValue=String(o.response.value),p.attributeLocalValue=o.response.value,C([...g]),console.log(`DevicesTable updated attribute ${p.clusterName}.${p.attributeName} for device "${l.name}" serial "${l.serial}" to "${p.attributeValue}"`)}},[g,f,W,k]);r.useEffect(()=>{const o=l=>{if(i&&console.log("DevicesTable received WebSocket Message:",l),l.method==="refresh_required"&&l.response.changed==="devices")i&&console.log(`DevicesTable received refresh_required: changed=${l.response.changed} and sending /api/devices request`),c({id:R.current,sender:"DevicesTable",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}});else if(l.method==="state_update"&&l.response)j(l);else if(l.method==="/api/devices")i&&console.log(`DevicesTable received ${l.response.length} devices:`,l.response),t(l.response);else if(l.method==="/api/clusters"){i&&console.log(`DevicesTable received ${l.response.clusters.length} clusters for plugin ${l.response.plugin}:`,l.response),C(l.response.clusters);const p={};for(const w of l.response.clusters)i&&console.log("Cluster:",w.endpoint),p[w.endpoint]?p[w.endpoint]++:p[w.endpoint]=1;T(Object.keys(p).length)}};return n(o,R.current),i&&console.log("DevicesTable added WebSocket listener"),()=>{d(o),i&&console.log("DevicesTable removed WebSocket listener")}},[c,n,d,j]),r.useEffect(()=>{m&&(i&&console.log("DevicesTable sending api requests with id ",R.current),c({id:R.current,sender:"DevicesTable",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:R.current,sender:"DevicesTable",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:R.current,sender:"DevicesTable",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}))},[m,c]),r.useEffect(()=>{W&&f&&(i&&console.log("DevicesTable sending /api/clusters"),c({id:R.current,sender:"DevicesTable",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:W,endpoint:Number(f)}}))},[W,f,c]),r.useEffect(()=>{if(s===""){P(h),z.current=h;return}const o=h.filter(l=>l.name.toLowerCase().includes(s)||l.serial.toLowerCase().includes(s));P(o),z.current=o},[h,s]);const a=o=>{if(o.uniqueId===k){H(null),A(null),G(null),y(null);return}H(o.uniqueId),A(o.pluginName),G(o.endpoint?o.endpoint.toString():null),y(o.name)};return i&&console.log("DevicesTable rendering..."),m?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:`${W&&f?"50%":"100%"}`,width:"100%",flex:"1 1 auto",overflow:"hidden"},children:e.jsx(mt,{name:"Registered devices",getRowKey:Dn,onRowClick:a,rows:x,columns:kn,footerLeft:`Total devices: ${x.length.toString()}`})}),W&&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(mt,{name:"Clusters",title:b||"",getRowKey:Nn,rows:g,columns:In,footerLeft:`Total child endpoints: ${V-1}`})})]}):e.jsx(Re,{})}const Wn=r.memo(Pn);function Ln(){const{online:s}=r.useContext(he),[m,c]=r.useState(""),[n,d]=r.useState("icon");r.useEffect(()=>{const t=localStorage.getItem("devicesFilter");t&&c(t)},[]),r.useEffect(()=>{const t=localStorage.getItem("devicesViewMode");t&&d(t)},[]);const v=t=>{c(t.target.value.toLowerCase()),localStorage.setItem("devicesFilter",t.target.value.toLowerCase())},h=t=>{d(t),localStorage.setItem("devicesViewMode",t)};return i&&console.log("Devices rendering..."),s?e.jsxs("div",{className:"MbfPageDiv",children:[e.jsxs("div",{className:"MbfWindowBodyRow",style:{justifyContent:"space-between",padding:0,gap:"20px",width:"100%",height:"45px",minHeight:"45px",maxHeight:"45px"},children:[e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(ie,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{variant:"outlined",value:m,onChange:v,placeholder:"Enter the device name or serial number",sx:{width:"320px"},InputProps:{style:{backgroundColor:"var(--main-bg-color)"}}})]}),e.jsxs(X,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(ie,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"View mode:"}),e.jsx(Q,{onClick:()=>h("table"),"aria-label":"Table View",disabled:n==="table",children:e.jsx($,{title:"Table View",children:e.jsx(Yr,{style:{color:n==="table"?"var(--main-icon-color)":"var(--primary-color)"}})})}),e.jsx(Q,{onClick:()=>h("icon"),"aria-label":"Icon View",disabled:n==="icon",children:e.jsx($,{title:"Icon View (beta)",children:e.jsx(Xr,{style:{color:n==="icon"?"var(--main-icon-color)":"var(--primary-color)"}})})})]})]}),n==="table"&&e.jsx(Wn,{filter:m}),n==="icon"&&e.jsx(Mn,{filter:m})]}):e.jsx(Re,{})}const Fn=r.memo(Ln);function $n(){const[s,m]=r.useState(localStorage.getItem("logFilterLevel")??"info"),[c,n]=r.useState(localStorage.getItem("logFilterSearch")??"*"),[d,v]=r.useState(localStorage.getItem("logAutoScroll")!=="false"),{setMessages:h,setLogFilters:t,online:x,setAutoScroll:P}=r.useContext(he),g=W=>{m(W.target.value),t(W.target.value,c),localStorage.setItem("logFilterLevel",W.target.value),i&&console.log("handleChangeLevel called with value:",W.target.value)},C=W=>{n(W.target.value),t(s,W.target.value),localStorage.setItem("logFilterSearch",W.target.value),i&&console.log("handleChangeSearch called with value:",W.target.value)},V=W=>{v(W.target.checked),P(W.target.checked),localStorage.setItem("logAutoScroll",W.target.value?"true":"false"),i&&console.log("handleAutoScrollChange called with value:",W.target.checked)},T=()=>{i&&console.log("handleClearLogsClick called"),h([])};return i&&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:s,onChange:g,children:[e.jsx(D,{value:"debug",children:"Debug"}),e.jsx(D,{value:"info",children:"Info"}),e.jsx(D,{value:"notice",children:"Notice"}),e.jsx(D,{value:"warn",children:"Warn"}),e.jsx(D,{value:"error",children:"Error"}),e.jsx(D,{value:"fatal",children:"Fatal"})]}),e.jsx(Pt,{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:c,onChange:C,InputProps:{style:{height:"30px",padding:"0 0px",backgroundColor:"var(--main-bg-color)"}}}),e.jsx($e,{control:e.jsx(Te,{checked:d,onChange:V}),label:"Auto scroll",style:{color:"var(--div-text-color)"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:e.jsx($,{title:"Clear the logs",children:e.jsx(oe,{onClick:T,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(Re,{})}const Tn=r.memo($n),Rn=({open:s,ip:m,onClose:c,onSave:n})=>{const d=m?m.split(".").slice(0,3).join(".")+".1":"",[v,h]=r.useState("dhcp"),[t,x]=r.useState({ip:m??"",subnet:"255.255.255.0",gateway:d,dns:d}),P=V=>T=>{x({...t,[V]:T.target.value})},g=()=>{c()},C=()=>{n({type:v,...t}),c()};return e.jsxs(Se,{open:s,onClose:(V,T)=>{T==="backdropClick"||T==="escapeKeyDown"||c()},maxWidth:"sm",style:{maxWidth:"550px",margin:"auto"},children:[e.jsx(Me,{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(ke,{dividers:!0,children:[e.jsxs(qt,{component:"fieldset",fullWidth:!0,children:[e.jsx(ye,{component:"legend",children:"Select IP Configuration"}),e.jsxs(zt,{row:!0,value:v,onChange:V=>h(V.target.value),children:[e.jsx($e,{value:"dhcp",control:e.jsx(gt,{}),label:"DHCP"}),e.jsx($e,{value:"static",control:e.jsx(gt,{}),label:"Static"})]})]}),v==="static"&&e.jsxs(Le,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Le,{size:6,children:e.jsx(pe,{label:"IP Address",fullWidth:!0,value:t.ip,onChange:P("ip")})}),e.jsx(Le,{size:6,children:e.jsx(pe,{label:"Subnet Mask",fullWidth:!0,value:t.subnet,onChange:P("subnet")})}),e.jsx(Le,{size:6,children:e.jsx(pe,{label:"Gateway",fullWidth:!0,value:t.gateway,onChange:P("gateway")})}),e.jsx(Le,{size:6,children:e.jsx(pe,{label:"DNS Server",fullWidth:!0,value:t.dns,onChange:P("dns")})})]})]}),e.jsxs(Fe,{children:[e.jsx(oe,{onClick:g,children:"Cancel"}),e.jsx(oe,{variant:"contained",onClick:C,children:"Save"})]})]})},Hn=({open:s,onClose:m,onSave:c})=>{const[n,d]=r.useState(""),[v,h]=r.useState(""),t=T=>{d(T.target.value)},x=T=>{h(T.target.value)},P=n.length>0&&n===v,g=()=>{m()},C=()=>{P&&(c(n),m())},V=()=>{c(""),m()};return e.jsxs(Se,{open:s,onClose:(T,W)=>{W==="backdropClick"||W==="escapeKeyDown"||m()},maxWidth:"sm",style:{maxWidth:"500px",margin:"auto"},disableEscapeKeyDown:!0,children:[e.jsx(Me,{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(ke,{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(pe,{type:"password",autoComplete:"new-password",label:"New Password",size:"small",variant:"outlined",fullWidth:!0,value:n,onChange:t})}),e.jsx(Le,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"Confirm Password",size:"small",variant:"outlined",fullWidth:!0,value:v,onChange:x,error:v!==""&&n!==v,helperText:v!==""&&n!==v?"Passwords do not match":""})})]})})}),e.jsxs(Fe,{children:[e.jsx(oe,{onClick:g,children:"Cancel"}),e.jsx(oe,{variant:"contained",onClick:C,disabled:!P,children:"Change"}),e.jsx(oe,{variant:"contained",onClick:V,children:"Reset"})]})]})};function On(){const{online:s,addListener:m,removeListener:c,sendMessage:n,getUniqueId:d}=r.useContext(he),[v,h]=r.useState(null),[t,x]=r.useState(null),P=r.useRef(d());return r.useEffect(()=>{const g=C=>{C.src==="Matterbridge"&&C.dst==="Frontend"&&(C.method==="refresh_required"&&C.response.changed==="settings"&&(i&&console.log(`Settings received refresh_required: changed=${C.response.changed} and sending /api/settings request`),n({id:P.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),C.method==="/api/settings"&&(i&&console.log("Settings received /api/settings:",C.response),h(C.response.matterbridgeInformation),x(C.response.systemInformation)))};return m(g,P.current),i&&console.log("Settings added WebSocket listener"),()=>{c(g),i&&console.log("Settings removed WebSocket listener")}},[m,c,n]),r.useEffect(()=>{s&&(i&&console.log("Settings received online"),n({id:P.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[s,n]),v?(i&&console.log("Settings rendering..."),s?e.jsx("div",{className:"MbfPageDiv",children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"20px",width:"100%"},children:[e.jsx(Vn,{matterbridgeInfo:v,systemInfo:t}),e.jsx(En,{matterbridgeInfo:v}),e.jsx(An,{matterbridgeInfo:v})]})}):e.jsx(Re,{})):null}function Vn({matterbridgeInfo:s,systemInfo:m}){const{sendMessage:c,getUniqueId:n}=r.useContext(he),[d,v]=r.useState("bridge"),[h,t]=r.useState("Info"),[x,P]=r.useState(!1),[g,C]=r.useState("dark"),[V,T]=r.useState(localStorage.getItem("homePagePlugins")!=="false"),[W,A]=r.useState(localStorage.getItem("homePageMode")??"devices"),[f,G]=r.useState(localStorage.getItem("virtualMode")??"outlet"),b=r.useRef(n()),[y,k]=r.useState(!1),H=()=>k(!1),R=Z=>{i&&console.log("handleSaveNetConfig called with config:",Z),c({id:b.current,sender:"Settings",method:"/api/shellynetconfig",src:"Frontend",dst:"Matterbridge",params:Z})},[z,j]=r.useState(!1),a=()=>j(!1),o=Z=>{i&&console.log("handleSaveChangePassword called with password:",Z),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setpassword",value:Z}})};r.useEffect(()=>{s&&(v(s.bridgeMode==="bridge"?"bridge":"childbridge"),t(s.loggerLevel.charAt(0).toUpperCase()+s.loggerLevel.slice(1)),P(s.fileLogger),G(s.virtualMode))},[s]),r.useEffect(()=>{const Z=localStorage.getItem("frontendTheme");Z&&C(Z)},[]);const l=Z=>{i&&console.log("handleChangeBridgeMode called with value:",Z.target.value),v(Z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setbridgemode",value:Z.target.value}})},p=Z=>{i&&console.log("handleChangeMbLoggerLevel called with value:",Z.target.value),t(Z.target.value),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmbloglevel",value:Z.target.value}})},w=Z=>{i&&console.log("handleLogOnFileMbChange called with value:",Z.target.checked),P(Z.target.checked),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmblogfile",value:Z.target.checked}})},se=Z=>{const ne=Z.target.value;i&&console.log("handleChangeTheme called with value:",ne),C(ne),localStorage.setItem("frontendTheme",ne),document.body.setAttribute("frontend-theme",ne)},ge=Z=>{const ne=Z.target.checked;i&&console.log("handleChangeHomePagePlugins called with value:",ne),T(ne),localStorage.setItem("homePagePlugins",ne?"true":"false")},fe=Z=>{const ne=Z.target.value;i&&console.log("handleChangeHomePageMode called with value:",ne),A(ne),localStorage.setItem("homePageMode",ne)},Ie=Z=>{const ne=Z.target.value;i&&console.log("handleChangeVirtualMode called with value:",ne),G(ne),localStorage.setItem("virtualMode",ne),c({id:b.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setvirtualmode",value:ne}})};return!s||!m?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(Rn,{open:y,ip:m.ipv4Address,onClose:H,onSave:R}),e.jsx(Hn,{open:z,onClose:a,onSave:o}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(X,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},id:"matterbridgeInfo-mode",children:"Matterbridge mode:"}),e.jsxs(zt,{row:!0,name:"mode-buttons-group",value:d,onChange:l,children:[e.jsx($e,{value:"bridge",control:e.jsx(gt,{}),label:"Bridge",disabled:s.readOnly===!0}),e.jsx($e,{value:"childbridge",control:e.jsx(gt,{}),label:"Childbridge",disabled:s.readOnly===!0})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{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:h,onChange:p,children:[e.jsx(D,{value:"Debug",children:"Debug"}),e.jsx(D,{value:"Info",children:"Info"}),e.jsx(D,{value:"Notice",children:"Notice"}),e.jsx(D,{value:"Warn",children:"Warn"}),e.jsx(D,{value:"Error",children:"Error"}),e.jsx(D,{value:"Fatal",children:"Fatal"})]}),e.jsx($e,{style:{padding:"0px",margin:"0px"},control:e.jsx(Te,{checked:x,onChange:w,name:"logOnFileMb"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(ye,{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:g,onChange:se,children:[e.jsx(D,{value:"classic",children:"Classic"}),e.jsx(D,{value:"light",children:"Light"}),e.jsx(D,{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},id:"frontend-home-plugin-label",children:"Home page plugins:"}),e.jsx(Te,{checked:V,onChange:ge,name:"showPlugins"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(ye,{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:W,onChange:fe,children:[e.jsx(D,{value:"logs",children:"Logs"}),e.jsx(D,{value:"devices",children:"Devices"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"10px"},children:[e.jsx(ye,{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:f,onChange:Ie,children:[e.jsx(D,{value:"disabled",children:"Disabled"}),e.jsx(D,{value:"outlet",children:"Outlet"}),e.jsx(D,{value:"light",children:"Light"}),e.jsx(D,{value:"switch",children:"Switch"}),e.jsx(D,{value:"mounted_switch",children:"Mounted Switch"})]})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(oe,{variant:"contained",color:"primary",onClick:()=>j(!0),children:"Change password"})}),s.shellyBoard&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(oe,{variant:"contained",color:"primary",onClick:()=>k(!0),children:"Configure IP"})})]})})]})}function En({matterbridgeInfo:s}){const{sendMessage:m,getUniqueId:c}=r.useContext(he),[n,d]=r.useState("Info"),[v,h]=r.useState(!1),[t,x]=r.useState(""),[P,g]=r.useState(""),[C,V]=r.useState(""),[T,W]=r.useState(""),[A,f]=r.useState(""),[G,b]=r.useState(""),y=r.useRef(c());r.useEffect(()=>{s&&(d(["Debug","Info","Notice","Warn","Error","Fatal"][s.matterLoggerLevel]),h(s.matterFileLogger),x(s.matterMdnsInterface||""),g(s.matterIpv4Address||""),V(s.matterIpv6Address||""),W(s.matterPort?s.matterPort.toString():""),f(s.matterDiscriminator?s.matterDiscriminator.toString():""),b(s.matterPasscode?s.matterPasscode.toString():""))},[s]);const k=p=>{i&&console.log("handleChangeMjLoggerLevel called with value:",p.target.value),d(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjloglevel",value:p.target.value}})},H=p=>{i&&console.log("handleLogOnFileMjChange called with value:",p.target.checked),h(p.target.checked),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjlogfile",value:p.target.checked}})},R=p=>{i&&console.log("handleChangeMdnsInterface called with value:",p.target.value),x(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmdnsinterface",value:p.target.value}})},z=p=>{i&&console.log("handleChangeIpv4Address called with value:",p.target.value),g(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv4address",value:p.target.value}})},j=p=>{i&&console.log("handleChangeIpv6Address called with value:",p.target.value),V(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv6address",value:p.target.value}})},a=p=>{i&&console.log("handleChangeMatterPort called with value:",p.target.value),W(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterport",value:p.target.value}})},o=p=>{i&&console.log("handleChangeMatterDiscriminator called with value:",p.target.value),f(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterdiscriminator",value:p.target.value}})},l=p=>{i&&console.log("handleChangemMatterPasscode called with value:",p.target.value),b(p.target.value),m({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterpasscode",value:p.target.value}})};return s?e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matter settings"})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(X,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},id:"mjdebug-info",children:"Logger level:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"select-mjlevel",id:"mjdebug-level",value:n,onChange:k,children:[e.jsx(D,{value:"Debug",children:"Debug"}),e.jsx(D,{value:"Info",children:"Info"}),e.jsx(D,{value:"Notice",children:"Notice"}),e.jsx(D,{value:"Warn",children:"Warn"}),e.jsx(D,{value:"Error",children:"Error"}),e.jsx(D,{value:"Fatal",children:"Fatal"})]}),e.jsx($e,{style:{padding:"0px",margin:"0px"},control:e.jsx(Te,{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(ye,{style:{padding:"0px",margin:"0px"},children:"Mdns interface:"}),e.jsx(pe,{value:t,onChange:R,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:s.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},children:"Ipv4 address:"}),e.jsx(pe,{value:P,onChange:z,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:s.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},children:"Ipv6 address:"}),e.jsx(pe,{value:C,onChange:j,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:s.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},children:"Commissioning port:"}),e.jsx(pe,{value:T,onChange:a,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:s.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},children:"Commissioning discriminator:"}),e.jsx(pe,{value:A,onChange:o,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:s.readOnly===!0,style:{height:"30px",padding:"0"}}})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(ye,{style:{padding:"0px",margin:"0px"},children:"Commissioning passcode:"}),e.jsx(pe,{value:G,onChange:l,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:s.readOnly===!0,style:{height:"30px",padding:"0"}}})]})]})})]}):null}function An({matterbridgeInfo:s}){return s?e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"Matterbridge info"})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px",flex:"0 0 auto"},children:e.jsxs(X,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[" ",e.jsx(Oe,{value:s.matterbridgeVersion,label:"Current Version"}),e.jsx(Oe,{value:s.matterbridgeLatestVersion,label:"Latest Version"}),e.jsx(Oe,{value:s.homeDirectory,label:"Home Directory"}),e.jsx(Oe,{value:s.rootDirectory,label:"Root Directory"}),e.jsx(Oe,{value:s.matterbridgeDirectory,label:"Matterbridge Storage Directory"}),e.jsx(Oe,{value:s.matterbridgePluginDirectory,label:"Matterbridge Plugin Directory"}),e.jsx(Oe,{value:s.globalModulesDirectory,label:"Global Module Directory"})]})})]}):null}function Oe({value:s,label:m}){return e.jsx(pe,{focused:!0,value:s,size:"small",label:m,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 _n=r.memo(On);function qn(){const{online:s,sendMessage:m,addListener:c,removeListener:n,getUniqueId:d}=r.useContext(he),{showSnackbarMessage:v,showInstallProgress:h,addInstallProgress:t}=r.useContext(Be),[x,P]=r.useState(null),[g,C]=r.useState([]),[V,T]=r.useState([]),[W,A]=r.useState(null),[f,G]=r.useState({cpuUsage:0}),[b,y]=r.useState({totalMemory:"",freeMemory:"",heapTotal:"",heapUsed:"",external:"",arrayBuffers:"",rss:""}),[k,H]=r.useState({systemUptime:"",processUptime:""}),R=r.useRef(d());return console.log("Test uniqueId:",R),r.useEffect(()=>{console.log("Test useEffect WebSocketMessage mounting");const z=j=>{if(j.method==="restart_required")console.log("Test received restart_required"),v("Restart required",0);else if(j.method==="refresh_required")console.log(`Test received refresh_required: changed=${j.response.changed} and sending api requests`),v("Refresh required",0),m({id:R.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),m({id:R.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),m({id:R.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}});else if(j.method==="memory_update")console.log("Test received memory_update",j),y(j.response);else if(j.method==="cpu_update")console.log("Test received cpu_update",j),G(j.response);else if(j.method==="uptime_update")console.log("Test received uptime_update",j),H(j.response);else if(j.method==="/api/settings"&&j.response)console.log("Test received /api/settings:",j.response),v("Test received /api/settings",0),P(j.response);else if(j.method==="/api/plugins"&&j.response)console.log(`Test received ${j.response.length} plugins:`,j.response),v("Test received /api/plugins",0),C(j.response);else if(j.method==="/api/devices"&&j.response){console.log(`Test received ${j.response.length} devices:`,j.response),v("Test received /api/devices",0),T(j.response);for(const a of j.response)console.log("Test sending /api/clusters for device:",a.pluginName,a.name,a.endpoint),m({id:R.current,method:"/api/clusters",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{plugin:a.pluginName,endpoint:a.endpoint||0}})}else j.method==="/api/clusters"&&j.response&&(console.log(`Test received ${j.response.clusters.length} clusters for device ${j.response.deviceName} endpoint ${j.response.id}:${j.response.number}:`,j),v(`Test received /api/clusters for ${j.response.plugin}::${j.response.deviceName}`,0),A(j.response))};return c(z,R.current),console.log("Test useEffect WebSocketMessage mounted"),()=>{console.log("Test useEffect WebSocketMessage unmounting"),n(z),console.log("Test useEffect WebSocketMessage unmounted")}},[c,n,m,v]),r.useEffect(()=>(console.log("Test useEffect online mounting"),s&&console.log("Test useEffect online received online"),console.log("Test useEffect online mounted"),()=>{console.log("Test useEffect online unmounted")}),[s,m,v]),console.log("Test rendering..."),s?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(oe,{variant:"contained",onClick:()=>{h("example-package"),t("Starting installation...");for(const z of["Downloading package...","Extracting files...","Installing dependencies..."])t(z);for(let z=0;z<=500;z+=1)t(`Installing dependency package-dep${z}...`);t("Finalizing installation..."),t("Installation completed successfully.")},children:"Install"})]})}):e.jsx(Re,{})}const zn=r.memo(qn);function Un(s,m){i&&console.log("getCssVariable:",s,"defaultValue",m);const c=getComputedStyle(document.body).getPropertyValue(s).trim();return c||console.error("getCssVariable: undefined",c),c||m}function Bn(s){return Zr({palette:{primary:{main:s},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 i=!1;const Qn=()=>{i=!i};function Kn({setLoggedIn:s}){const[m,c]=r.useState(""),[n,d]=r.useState(""),v={display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",backgroundColor:"var(--main-bg-color)"},h={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 g=>{try{const C=await fetch("./api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:g})});if(C.ok){const{valid:V}=await C.json();V?s(!0):g!==""&&d("Incorrect password!")}else console.error("Failed to log in:",C.statusText)}catch(C){console.error("Failed to log in:",C)}},P=g=>{g.preventDefault(),x(m)};return x(""),e.jsx("div",{style:v,children:e.jsxs("form",{onSubmit:P,style:h,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:m,onChange:g=>c(g.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:n&&e.jsx("p",{style:{color:"red"},children:n})})]})})}function Jn(){const[s,m]=r.useState(!1);i&&console.log("Setting frontend theme");const c=localStorage.getItem("frontendTheme");i&&console.log("Saved theme:",c),c?document.body.setAttribute("frontend-theme",c):document.body.setAttribute("frontend-theme","dark");const n=Un("--primary-color","#1976d2");i&&console.log("Primary color from CSS:",n);const d=Bn(n),v=window.location.pathname.includes("/matterbridge/")?"/matterbridge":window.location.href.includes("/api/hassio_ingress/")?window.location.pathname:"/";return i&&(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}"`)),s?e.jsx(eo,{theme:d,children:e.jsx(cr,{dense:!0,maxSnack:10,preventDuplicate:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Ho,{children:e.jsx(Oo,{children:e.jsx(nr,{basename:v,children:e.jsxs("div",{className:"MbfScreen",children:[e.jsx(Eo,{}),e.jsxs(ir,{children:[e.jsx(Ve,{path:"/",element:e.jsx(pn,{})}),e.jsx(Ve,{path:"/devices",element:e.jsx(Fn,{})}),e.jsx(Ve,{path:"/log",element:e.jsx(Tn,{})}),e.jsx(Ve,{path:"/settings",element:e.jsx(_n,{})}),e.jsx(Ve,{path:"/test",element:e.jsx(zn,{})}),e.jsx(Ve,{path:"*",element:e.jsx(sr,{to:"/"})})]})]})})})})})}):e.jsx(Kn,{setLoggedIn:m})}ar.createRoot(document.getElementById("root")).render(e.jsx(lr.StrictMode,{children:e.jsx(Jn,{})}));
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 Me,a as ke,b as Ie,B as oe,c as $e,d as Z,A as pr,I as Q,C as ur,T,S as gr,F as Vt,H as mr,e as Et,f as We,R as dt,P as He,M as hr,g as ze,h as D,L as z,i as te,j as Ze,V as et,k as Se,l as ht,m as fr,n as xr,o as pe,p as br,q as vr,r as ct,s as ie,t as Te,K as St,u as Mt,v as ut,w as tt,x as Je,y as rt,W as Ge,z as ot,E as nt,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 $r,ab as Fr,ac as Tr,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 Ce,az as zt,aA as gt,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 go,n as mo,o as ho,p as fo,q as $t,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 Ft,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 $o,d as ft,A as Fo}from"./vendor_rjsf.js";import"./vendor_lodash.js";import"./vendor_emotion.js";(function(){const m=document.createElement("link").relList;if(m&&m.supports&&m.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))n(l);new MutationObserver(l=>{for(const b of l)if(b.type==="childList")for(const g of b.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&n(g)}).observe(document,{childList:!0,subtree:!0});function c(l){const b={};return l.integrity&&(b.integrity=l.integrity),l.referrerPolicy&&(b.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?b.credentials="include":l.crossOrigin==="anonymous"?b.credentials="omit":b.credentials="same-origin",b}function n(l){if(l.ep)return;l.ep=!0;const b=c(l);fetch(l.href,b)}})();function To({open:i,title:m,message:c,onConfirm:n,onCancel:l}){const b=t=>{s&&console.log("Confirmed"),t.preventDefault(),n()},g=t=>{s&&console.log("Canceled"),t.preventDefault(),l()};return e.jsxs(Me,{open:i,children:[e.jsx(ke,{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:m})]})}),e.jsxs(Ie,{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(oe,{onClick:b,variant:"contained",color:"primary",size:"small",children:"Confirm"}),e.jsx(oe,{onClick:g,variant:"contained",color:"primary",size:"small",children:"Cancel"})]})]})]})}const Ro=({open:i,output:m,packageName:c,onInstall:n,onClose:l})=>{const b=r.useRef(null);return r.useEffect(()=>{s&&console.log(`InstallProgressDialog output effect mounted, scrolling to bottom: ${b.current}`),setTimeout(()=>{s&&console.log("Scrolling to bottom:",b.current),b.current?.scrollIntoView({behavior:"smooth"})},0)},[m]),e.jsxs(Me,{open:i,onClose:(g,t)=>{t==="backdropClick"||t==="escapeKeyDown"||l()},slotProps:{paper:{sx:{width:"800px",maxWidth:"50vw",height:"600px",maxHeight:"50vh",overflow:"hidden"}}},children:[e.jsx(ke,{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.jsxs("h4",{style:{margin:0},children:["Install",n?"":"ing"," package ",c]})]})}),e.jsxs(Ie,{dividers:!0,style:{overflow:"hidden",display:"flex",flexDirection:"column",height:400,paddingBottom:0},children:[e.jsx("label",{style:{display:"block",marginBottom:"10px",fontSize:"16px",color:"var(--primary-color)"},children:"Install log"}),e.jsxs("ul",{style:{width:"100%",height:"100%",fontFamily:"monospace",fontSize:"14px",padding:8,margin:0,marginBottom:"10px",color:"var(--div-text-color)",background:"var(--div-bg-color)",overflow:"auto",listStyle:"none",boxSizing:"border-box",borderRadius:4,border:"1px solid var(--primary-color)",whiteSpace:"pre-wrap",display:"block"},children:[m.split(`
2
+ `).map((g,t)=>e.jsx("li",{style:{padding:0,margin:0},children:g},t)),e.jsx("li",{ref:b,style:{padding:0,margin:0}})]})]}),e.jsxs($e,{children:[n&&e.jsx(oe,{variant:"contained",onClick:n,children:"Install"}),e.jsx(oe,{onClick:l,children:"Close"})]})]})},it=[],Be=r.createContext(null);function Ho({children:i}){const{enqueueSnackbar:m,closeSnackbar:c}=dr(),n=r.useCallback(w=>{s&&console.log(`UiProvider closeSnackbarMessage: message ${w}`);const V=it.findIndex(ge=>ge.message===w);V!==-1&&(c(it[V].key),it.splice(V,1),s&&console.log(`UiProvider closeSnackbarMessage: message ${w} removed from persistMessages`))},[c]),l=r.useCallback((w,V,ge)=>{s&&console.log(`UiProvider showSnackbarMessage: message ${w} timeout ${V}`);const me=m(w,{variant:"default",autoHideDuration:V==null||V>0?(V??5)*1e3:null,persist:V===0,content:xe=>e.jsx(Z,{sx:{margin:"0",padding:"0",width:"300px",marginRight:"30px"},children:e.jsx(pr,{severity:ge??"info",variant:"filled",sx:{color:"#fff",fontWeight:"normal",width:"100%",cursor:"pointer",padding:"0px 10px"},onClick:()=>c(xe),action:e.jsx(Q,{size:"small",onClick:()=>c(xe),sx:{color:"#fff"},children:e.jsx(ur,{fontSize:"small"})}),children:w},xe)},xe)});V===0&&(s&&console.log(`UiProvider showSnackbarMessage: message ${w} timeout ${V} - persist key ${me}`),it.push({message:w,key:me}))},[m,c]),[b,g]=r.useState(!1),[t,x]=r.useState(""),[P,p]=r.useState(""),[C,E]=r.useState(""),H=r.useRef(null),W=r.useRef(null),_=()=>{s&&console.log(`UiProvider handle confirm action ${C}`),g(!1),H.current&&H.current(C)},f=()=>{s&&console.log(`UiProvider handle cancel action ${C}`),g(!1),W.current&&W.current(C)},X=r.useCallback((w,V,ge,me,xe)=>{s&&console.log(`UiProvider showConfirmCancelDialog for command ${ge}`),x(w),p(V),E(ge),H.current=me,W.current=xe,g(!0)},[]),[y,j]=r.useState(!1),[k,R]=r.useState(""),[O,G]=r.useState(""),v=r.useCallback(w=>{console.log(`UiProvider show install progress for package ${w}`),R(w),G(`Starting installation of ${w}...
3
+ `),j(!0)},[]),a=r.useCallback(()=>{console.log("UiProvider hide install progress"),j(!1)},[]),o=r.useCallback(w=>{console.log(`UiProvider addInstallProgress: output ${w}`),G(V=>V+w+`
4
+ `)},[]),d=()=>{console.log("UiProvider handle install close action"),j(!1),R(""),G("")},u=r.useMemo(()=>({showSnackbarMessage:l,closeSnackbarMessage:n,closeSnackbar:c,showConfirmCancelDialog:X,showInstallProgress:v,hideInstallProgress:a,addInstallProgress:o}),[l,n,c,X,v,a,o]);return e.jsxs(Be.Provider,{value:u,children:[e.jsx(To,{open:b,title:t,message:P,onConfirm:_,onCancel:f}),e.jsx(Ro,{open:y,packageName:k,output:O,onClose:d}),i]})}const Ut=r.createContext(null),fe=r.createContext(null);function Oo({children:i}){const[m,c]=r.useState(localStorage.getItem("logFilterLevel")??"info"),[n,l]=r.useState(localStorage.getItem("logFilterSearch")??"*"),[b,g]=r.useState([]),[t,x]=r.useState(1e3),[P,p]=r.useState(!0),[C,E]=r.useState(!1),{showSnackbarMessage:H,closeSnackbarMessage:W,closeSnackbar:_,showInstallProgress:f,hideInstallProgress:X,addInstallProgress:y}=r.useContext(Be),j=r.useRef([]),k=r.useRef(null),R=r.useRef(1),O=r.useRef(Math.floor(Math.random()*999e3)+1e3),G=r.useRef(null),v=r.useRef(null),a=r.useRef(null),o=r.useRef(m),d=r.useRef(n),u=r.useRef(0),w=r.useRef(null),V=r.useMemo(()=>window.location.href.replace(/^http/,"ws"),[]),ge=r.useMemo(()=>window.location.href.includes("api/hassio_ingress"),[]),me=100,xe=60,ee=50,se=300,L=10;r.useEffect(()=>(s&&console.log("WebSocket messages started counter interval"),w.current=setInterval(()=>{u.current>0&&(s&&console.log(`WebSocket messages received in the last ${L} seconds: ${u.current*(60/L)} messages/minute`),u.current=0)},L*1e3),()=>{s&&console.log("WebSocket messages stopped counter interval"),w.current&&clearInterval(w.current),w.current=null}),[]),r.useEffect(()=>{o.current=m},[m]),r.useEffect(()=>{d.current=n},[n]);const U=r.useCallback(()=>Math.floor(Math.random()*999e3)+1e3,[]),$=r.useCallback(N=>{if(k.current&&k.current.readyState===WebSocket.OPEN)try{s&&console.log(`WebSocket sending message with id ${N.id}:`,N),N.id===void 0&&(N.id=O.current);const h=JSON.stringify(N);k.current.send(h),s&&console.log("WebSocket sent message:",N)}catch(h){s&&console.error(`WebSocket error sending message: ${h}`)}else s&&console.error("WebSocket message not sent, WebSocket not connected:",N)},[]),S=r.useCallback((N,h)=>{g(ne=>[...ne,{level:N,time:"",name:"",message:h}])},[]),M=r.useCallback((N,h)=>{c(N),l(h),S("WebSocket",`Filtering by log level "${N}" and log search "${h}"`)},[S]),F=r.useCallback((N,h)=>{s&&console.log(`WebSocket addListener id ${h}:`,N),(h==null||isNaN(h)||h===0)&&console.error("WebSocket addListener called without id, listener not added:",N),j.current=[...j.current,{listener:N,id:h}],s&&console.log("WebSocket addListener total listeners:",j.current.length)},[]),A=r.useCallback(N=>{s&&console.log("WebSocket removeListener:",N),j.current=j.current.filter(h=>h.listener!==N),s&&console.log("WebSocket removeListener total listeners:",j.current.length)},[]),Y=r.useCallback(()=>{V===""||V===null||V===void 0||(S("WebSocket",`Connecting to WebSocket: ${V}`),k.current=new WebSocket(V),k.current.onmessage=N=>{C||E(!0),u.current+=1;try{const h=JSON.parse(N.data);if(h.id===void 0||h.src===void 0||h.dst===void 0){s&&console.error("WebSocket undefined message id/src/dst:",h);return}if(h.src!=="Matterbridge"||h.dst!=="Frontend"){s&&console.error("WebSocket invalid message src/dst:",h);return}if(h.error){s&&console.error("WebSocket error message response:",h);return}if(h.id===O.current&&h.method==="pong"&&h.response==="pong"){s&&console.log(`WebSocket pong response message id ${h.id}:`,h),v.current&&clearTimeout(v.current),v.current=null;return}else if(h.method==="snackbar"&&h.response&&h.response.message){s&&console.log(`WebSocket message id ${h.id} method ${h.method}:`,h),H(h.response.message,h.response.timeout,h.response.severity);return}else if(h.method==="close_snackbar"&&h.response&&h.response.message){s&&console.log(`WebSocket message id ${h.id} method ${h.method}:`,h),W(h.response.message);return}else if(h.method==="log"){if(!h.response||!h.response.level||!h.response.time||!h.response.name||!h.response.message||(h.response.level==="spawn"&&(h.response.name==="Matterbridge:spawn-init"?f(h.response.message):h.response.name==="Matterbridge:spawn-exit"||y(h.response.message+`
5
+ `)),["debug","info","notice","warn","error","fatal"].includes(h.response.level)&&(o.current==="info"&&h.response.level==="debug"||o.current==="notice"&&(h.response.level==="debug"||h.response.level==="info")||o.current==="warn"&&(h.response.level==="debug"||h.response.level==="info"||h.response.level==="notice")||o.current==="error"&&(h.response.level==="debug"||h.response.level==="info"||h.response.level==="notice"||h.response.level==="warn")||o.current==="fatal"&&(h.response.level==="debug"||h.response.level==="info"||h.response.level==="notice"||h.response.level==="warn"||h.response.level==="error")))||d.current!=="*"&&d.current!==""&&!h.response.message.toLowerCase().includes(d.current.toLowerCase())&&!h.response.name.toLowerCase().includes(d.current.toLowerCase())||h.response.name==="Commissioning"&&h.response.message.includes("is uncommissioned"))return;g(J=>{const ve=[...J,{level:h.response.level,time:h.response.time,name:h.response.name,message:h.response.message}];return ve.length>t*2?ve.slice(t):ve})}else{if(s&&console.log(`WebSocket received message id ${h.id} method ${h.method}:`,h),h.id===0)j.current.forEach(ne=>ne.listener(h));else{const ne=j.current.find(J=>J.id===h.id);ne?ne.listener(h):s&&console.debug(`WebSocket no listener found for message id ${h.id}:`,h)}return}}catch(h){console.error(`WebSocketUse error parsing message: ${h}`)}},k.current.onopen=()=>{s&&console.log(`WebSocket: Connected to WebSocket: ${V}`),S("WebSocket",`Connected to WebSocket: ${V}`),E(!0),_(),R.current=1,a.current=setTimeout(()=>{G.current=setInterval(()=>{$({id:O.current,method:"ping",src:"Frontend",dst:"Matterbridge",params:{}}),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{s&&console.error(`WebSocketUse: No pong response received from WebSocket: ${V}`),S("WebSocket",`No pong response received from WebSocket: ${V}`),E(!1)},1e3*ee)},1e3*xe)},1e3*se)},k.current.onclose=()=>{s&&console.error(`WebSocket: Disconnected from WebSocket ${ge?"with Ingress":""}: ${V}`),S("WebSocket",`Disconnected from WebSocket: ${V}`),E(!1),_(),X(),a.current&&clearTimeout(a.current),v.current&&clearTimeout(v.current),G.current&&clearInterval(G.current),S("WebSocket",`Reconnecting (attempt ${R.current} of ${me}) to WebSocket${ge?" (Ingress)":""}: ${V}`),ge?setTimeout(ae,5e3):R.current===1?ae():R.current<me?setTimeout(ae,1e3*R.current):S("WebSocket",`Reconnect attempts exceeded limit of ${me} retries, refresh the page to reconnect to: ${V}`),R.current=R.current+1},k.current.onerror=N=>{s&&console.error(`WebSocket: WebSocket error connecting to ${V}:`,N),S("WebSocket",`WebSocket error connecting to ${V}`)})},[V]),ae=r.useCallback(()=>{s&&console.log(`WebSocket attemptReconnect ${R.current}/${me} to:`,V),Y()},[Y]);r.useEffect(()=>(Y(),()=>{k.current&&k.current.readyState===WebSocket.OPEN&&k.current.close()}),[Y]);const de=r.useMemo(()=>({messages:b,maxMessages:t,autoScroll:P,setMessages:g,setLogFilters:M,setMaxMessages:x,setAutoScroll:p}),[b,g,M]),le=r.useMemo(()=>({maxMessages:t,autoScroll:P,logFilterLevel:m,logFilterSearch:n,setMessages:g,setLogFilters:M,setMaxMessages:x,setAutoScroll:p,online:C,retry:R.current,getUniqueId:U,addListener:F,removeListener:A,sendMessage:$,logMessage:S}),[t,P,g,M,x,p,C,R.current,F,A,$,S]);return e.jsx(Ut.Provider,{value:de,children:e.jsx(fe.Provider,{value:le,children:i})})}function Vo(){const{showSnackbarMessage:i,showConfirmCancelDialog:m}=r.useContext(Be),{online:c,sendMessage:n,logMessage:l,addListener:b,removeListener:g,getUniqueId:t}=r.useContext(fe),[x,P]=r.useState(!1),[p,C]=r.useState(!1),[E,H]=r.useState(!1),[W,_]=r.useState(!1),[f,X]=r.useState(null),y=r.useRef(t()),[j,k]=r.useState(null),[R,O]=r.useState(null),[G,v]=r.useState(null),[a,o]=r.useState(null),[d,u]=r.useState(null),w=()=>{window.open("https://www.buymeacoffee.com/luligugithub","_blank")},V=()=>{window.open("https://github.com/Luligu/matterbridge/blob/main/README.md","_blank")},ge=()=>{f?.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")},me=()=>{window.open("https://discord.gg/QX58CDe6hd","_blank")},xe=()=>{window.open("https://github.com/Luligu/matterbridge","_blank")},ee=()=>{n({id:y.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge",restart:!0}})},se=()=>{n({id:y.current,sender:"Header",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:"matterbridge@dev",restart:!0}})},L=()=>{n({id:y.current,sender:"Header",method:"/api/checkupdates",src:"Frontend",dst:"Matterbridge",params:{}})},U=()=>{s&&console.log("Header: handleShellySystemUpdateClick"),l("Matterbridge","Installing system updates..."),n({id:y.current,sender:"Header",method:"/api/shellysysupdate",src:"Frontend",dst:"Matterbridge",params:{}})},$=()=>{s&&console.log("Header: handleShellyMainUpdateClick"),l("Matterbridge","Installing software updates..."),n({id:y.current,sender:"Header",method:"/api/shellymainupdate",src:"Frontend",dst:"Matterbridge",params:{}})},S=()=>{s&&console.log("Header: handleShellyCreateSystemLog"),n({id:y.current,sender:"Header",method:"/api/shellycreatesystemlog",src:"Frontend",dst:"Matterbridge",params:{}})},M=()=>{s&&console.log("Header: handleShellyDownloadSystemLog"),l("Matterbridge","Downloading Shelly system log..."),i("Downloading Shelly system log...",5),window.location.href="./api/shellydownloadsystemlog"},F=()=>{f?.matterbridgeInformation.restartMode===""?n({id:y.current,sender:"Header",method:"/api/restart",src:"Frontend",dst:"Matterbridge",params:{}}):n({id:y.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},A=()=>{n({id:y.current,sender:"Header",method:"/api/shutdown",src:"Frontend",dst:"Matterbridge",params:{}})},Y=()=>{n({id:y.current,sender:"Header",method:"/api/reboot",src:"Frontend",dst:"Matterbridge",params:{}})},ae=()=>{n({id:y.current,sender:"Header",method:"/api/softreset",src:"Frontend",dst:"Matterbridge",params:{}})},de=()=>{n({id:y.current,sender:"Header",method:"/api/hardreset",src:"Frontend",dst:"Matterbridge",params:{}})},le=B=>{k(B.currentTarget)},N=B=>{s&&console.log("Header: handleMenuClose",B),k(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"?ee():B==="updatedev"?se():B==="updatecheck"?L():B==="shelly-sys-update"?U():B==="shelly-main-update"?$():B==="shelly-create-system-log"?S():B==="shelly-download-system-log"?M():B==="softreset"?ae():B==="hardreset"?de():B==="restart"?F():B==="shutdown"?A():B==="reboot"?Y():B==="create-backup"?n({id:y.current,sender:"Header",method:"/api/create-backup",src:"Frontend",dst:"Matterbridge",params:{}}):B==="unregister"?n({id:y.current,sender:"Header",method:"/api/unregister",src:"Frontend",dst:"Matterbridge",params:{}}):B==="reset"?n({id:y.current,sender:"Header",method:"/api/reset",src:"Frontend",dst:"Matterbridge",params:{}}):B==="factoryreset"&&n({id:y.current,sender:"Header",method:"/api/factoryreset",src:"Frontend",dst:"Matterbridge",params:{}})},h=B=>{s&&console.log("Header: handleMenuCloseCancel:",B),k(null)},ne=B=>{O(B.currentTarget)},J=()=>{O(null)},ve=B=>{v(B.currentTarget)},je=()=>{v(null)},he=B=>{o(B.currentTarget)},K=()=>{o(null)},ce=B=>{u(B.currentTarget)},ye=()=>{u(null)},Qe=()=>{Qn(),s&&console.log("Matterbridge logo clicked: debug is now",s)};return r.useEffect(()=>{const B=I=>{s&&console.log("Header received WebSocket Message:",I),I.method==="/api/settings"&&I.id===y.current?(s&&console.log("Header received settings:",I.response),X(I.response),P(I.response.matterbridgeInformation.restartRequired||I.response.matterbridgeInformation.fixedRestartRequired),C(I.response.matterbridgeInformation.fixedRestartRequired),H(I.response.matterbridgeInformation.updateRequired)):I.method==="refresh_required"&&I.response.changed==="settings"?(s&&console.log(`Header received refresh_required: changed=${I.response.changed} and sending /api/settings request`),n({id:y.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})):I.method==="restart_required"?(s&&console.log(`Header received restart_required with fixed: ${I.response.fixed}`),P(!0),I.response.fixed===!0&&C(!0)):I.method==="restart_not_required"?(s&&console.log("Header received restart_not_required"),P(!1)):I.method==="update_required"?(s&&console.log("Header received update_required"),I.response.devVersion===!0?_(!0):H(!0),n({id:y.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})):I.method==="shelly_sys_update"?(s&&console.log("Header received WS_ID_SHELLY_SYS_UPDATE:"),X(ue=>ue?{matterbridgeInformation:{...ue.matterbridgeInformation,shellySysUpdate:I.response.available},systemInformation:ue.systemInformation}:null)):I.method==="shelly_main_update"&&(s&&console.log("Header received WS_ID_SHELLY_MAIN_UPDATE:"),X(ue=>ue?{matterbridgeInformation:{...ue.matterbridgeInformation,shellyMainUpdate:I.response.available},systemInformation:ue.systemInformation}:null))};return b(B,y.current),s&&console.log(`Header added WebSocket listener id ${y.current}`),()=>{g(B),s&&console.log("Header removed WebSocket listener")}},[b,g,n,i]),r.useEffect(()=>{c&&(s&&console.log("Header sending /api/settings requests"),n({id:y.current,sender:"Header",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,n]),s&&console.log("Header rendering..."),!c||!f?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:[!f.matterbridgeInformation.readOnly&&E&&e.jsx(T,{title:"New Matterbridge version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:ee,children:["Update to v.",f.matterbridgeInformation.matterbridgeLatestVersion]})}),!f.matterbridgeInformation.readOnly&&W&&e.jsx(T,{title:"New Matterbridge dev version available, click to install",children:e.jsxs("span",{className:"status-warning",onClick:se,children:["Update to new dev v.",f.matterbridgeInformation.matterbridgeDevVersion.split("-dev-")[0]]})}),!f.matterbridgeInformation.readOnly&&e.jsx(T,{title:"Matterbridge version, click to see the changelog",children:e.jsxs("span",{className:"status-information",onClick:ge,children:["v.",f.matterbridgeInformation.matterbridgeVersion]})}),f.matterbridgeInformation.shellyBoard&&e.jsx("img",{src:"Shelly.svg",alt:"Shelly Icon",style:{height:"30px",padding:"0px",margin:"0px",marginRight:"30px"}}),f.matterbridgeInformation.bridgeMode!==""&&f.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Bridge mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:f.matterbridgeInformation.bridgeMode})}):null,f.matterbridgeInformation.restartMode!==""&&f.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Restart mode",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:f.matterbridgeInformation.restartMode})}):null,f.matterbridgeInformation.profile&&f.matterbridgeInformation.profile!==""&&f.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Current profile",children:e.jsx("span",{className:"status-information",style:{cursor:"default"},children:f.matterbridgeInformation.profile})}):null]}),e.jsxs("div",{className:"sub-header",style:{gap:"5px"},children:[f.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:me})}):null,f.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Give a star to Matterbridge",children:e.jsx(Q,{style:{color:"#FFD700",margin:"0",padding:"0"},onClick:xe,children:e.jsx(gr,{})})}):null,f.matterbridgeInformation.readOnly===!1?e.jsx(T,{title:"Sponsor Matterbridge",children:e.jsx(Q,{style:{color:"#b6409c",margin:"0",padding:"0"},onClick:w,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:V,children:e.jsx(mr,{})})}),e.jsx(T,{title:"Matterbridge changelog",children:e.jsx(Q,{style:{color:"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:ge,children:e.jsx(Et,{})})}),f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsx(T,{title:"Update matterbridge to latest version",children:e.jsx(Q,{style:{color:E?"var(--primary-color)":"var(--main-icon-color)",margin:"0",marginLeft:"5px",padding:"0"},onClick:ee,children:e.jsx(We,{})})}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.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:U,children:e.jsx(We,{})})}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.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:$,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:F,children:e.jsx(dt,{})})}),f.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:A,children:e.jsx(He,{})})}):null,e.jsx(T,{title:"Download, backup and more",children:e.jsx(Q,{onClick:le,children:e.jsx(hr,{style:{color:"var(--main-icon-color)"}})})}),e.jsxs(ze,{id:"command-menu",anchorEl:j,keepMounted:!0,open:!!j,onClose:()=>N(""),children:[f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>N("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)"}}})]}),f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>N("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)"}}})]}),f.matterbridgeInformation&&!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>N("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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.matterbridgeInformation.shellySysUpdate&&e.jsxs(D,{onClick:()=>N("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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&f.matterbridgeInformation.shellyMainUpdate&&e.jsxs(D,{onClick:()=>N("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(D,{onClick:()=>N("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)"}}})]}),f.matterbridgeInformation.restartMode===""?e.jsxs(D,{onClick:()=>N("shutdown"),children:[e.jsx(z,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Shutdown",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}):null,f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{m("Reboot","Are you sure you want to reboot the Shelly board?","reboot",N,h)},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(D,{onClick:ve,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:je,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{N("view-mblog"),je()},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(D,{onClick:()=>{N("view-mjlog"),je()},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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{N("view-shellylog"),je()},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(D,{onClick:he,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:K,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{N("download-mbstorage"),K()},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(D,{onClick:()=>{N("download-pluginstorage"),K()},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(D,{onClick:()=>{N("download-pluginconfig"),K()},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(D,{onClick:()=>{N("download-mblog"),K()},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(D,{onClick:()=>{N("download-mjstorage"),K()},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(D,{onClick:()=>{N("download-mjlog"),K()},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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{N("shelly-create-system-log"),K()},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)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{N("shelly-download-system-log"),K()},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(D,{onClick:ne,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:R,keepMounted:!0,open:!!R,onClose:J,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{N("create-backup"),J()},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(D,{onClick:()=>{N("download-backup"),J()},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(D,{onClick:ce,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:ye,sx:{"& .MuiPaper-root":{backgroundColor:"#e2e2e2"}},children:[e.jsxs(D,{onClick:()=>{ye(),m("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",N,h)},children:[e.jsx(z,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset all devices...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),e.jsxs(D,{onClick:()=>{ye(),m("Reset commissioning and shutdown","Are you sure you want to reset the commissioning? You will have to manually remove Matterbridge from the controller.","reset",N,h)},children:[e.jsx(z,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset commissioning...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),!f.matterbridgeInformation.readOnly&&e.jsxs(D,{onClick:()=>{ye(),m("Factory reset and shutdown","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","factoryreset",N,h)},children:[e.jsx(z,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{ye(),m("Network reset","Are you sure you want to factory reset the network parameters?","softreset",N,h)},children:[e.jsx(z,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Reset network...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]}),f.matterbridgeInformation&&f.matterbridgeInformation.shellyBoard&&e.jsxs(D,{onClick:()=>{ye(),m("Factory reset","Are you sure you want to factory reset Matterbridge? You will have to manually remove Matterbridge from the controller.","hardreset",N,h)},children:[e.jsx(z,{children:e.jsx(He,{style:{color:"var(--main-icon-color)"}})}),e.jsx(te,{primary:"Factory reset...",primaryTypographyProps:{style:{fontWeight:"normal",color:"var(--main-icon-color)"}}})]})]})]})]})]})}const Eo=r.memo(Vo),Ao=()=>"ontouchstart"in window||typeof window.DocumentTouch<"u"&&document instanceof window.DocumentTouch?(s&&console.log("WebSocketLogs detectTouchscreen = true"),!0):(s&&console.log("WebSocketLogs detectTouchscreen = false"),!1);function _o(){const{messages:i,autoScroll:m}=r.useContext(Ut),[c,n]=r.useState(!1),l=r.useRef(null),b=r.useMemo(()=>Ao(),[]),g=p=>n(!0),t=p=>n(!1);r.useEffect(()=>{s&&console.log(`WebSocketLogs autoScroll: ${m} isHovering: ${c}`),m&&!c&&!b&&l.current?.scrollIntoView({behavior:"smooth"})},[i,c,m,b]);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"}},P=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,C)=>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:P(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})]},C)),e.jsx("div",{ref:l})]})})}const Bt=r.memo(_o);function Re(){const{retry:i}=r.useContext(fe),m=()=>{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: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(oe,{variant:"contained",color:"primary",onClick:m,style:{marginTop:"20px"},children:"Refresh the Page"})]})})})}function qo({value:i,maxChars:m}){let c=i;if(i.length>m&&m>3){const n=m-3,l=i.substring(0,Math.ceil(n/2)),b=i.substring(i.length-Math.floor(n/2),i.length);c=`${l} … ${b}`}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 zo({systemInfo:i,compact:m}){const{sendMessage:c,addListener:n,removeListener:l,getUniqueId:b}=r.useContext(fe),[g,t]=r.useState(i),x=r.useRef(b());if(s&&console.log("SystemInfoTable:",g,"compact:",m),i&&m&&g.totalMemory&&g.freeMemory){const P=g.totalMemory,p=g.freeMemory;g.freeMemory=`${p} / ${P}`,g.totalMemory=""}if(i&&m&&g.heapTotal&&g.heapUsed){const P=g.heapTotal,p=g.heapUsed;g.heapUsed=`${p} / ${P}`,g.heapTotal=""}if(i&&m&&g.osRelease&&g.osType){const P=g.osType,p=g.osRelease;g.osType=`${P} (${p})`,g.osRelease=""}if(i&&m&&g.osArch&&g.osPlatform){const P=g.osPlatform,p=g.osArch;g.osPlatform=`${P} (${p})`,g.osArch=""}return r.useEffect(()=>{const P=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&&(s&&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(C=>({...C,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&&(s&&console.log("SystemInfoTable received cpu_update",p),g.cpuUsage!==(p.response.cpuUsage?p.response.cpuUsage.toFixed(2)+" %":"")&&t(C=>({...C,cpuUsage:p.response.cpuUsage.toFixed(2)+" %"}))),p.method==="uptime_update"&&p.response&&p.response.systemUptime&&p.response.processUptime&&(s&&console.log("SystemInfoTable received uptime_update",p),(g.systemUptime!==p.response.systemUptime||g.processUptime!==p.response.processUptime)&&t(C=>({...C,systemUptime:p.response.systemUptime,processUptime:p.response.processUptime}))))};return s&&console.log("SystemInfoTable useEffect WebSocketMessage mounting"),n(P,x.current),s&&console.log("SystemInfoTable useEffect WebSocketMessage mounted"),()=>{s&&console.log("SystemInfoTable useEffect WebSocketMessage unmounting"),l(P),s&&console.log("SystemInfoTable useEffect WebSocketMessage unmounted")}},[n,g.cpuUsage,g.freeMemory,g.heapTotal,g.heapUsed,g.processUptime,g.rss,g.systemUptime,g.totalMemory,l,c]),g?(s&&console.log("SystemInfoTable rendering..."),e.jsxs("div",{className:"MbfWindowDiv",style:{minWidth:"302px",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"System Information"})}),e.jsx("div",{className:"MbfWindowDivTable",children:e.jsx("table",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx("tbody",{style:{border:"none",borderCollapse:"collapse"},children:Object.entries(g).filter(([P,p])=>p!==void 0&&p!=="").map(([P,p],C)=>e.jsxs("tr",{className:C%2===0?"table-content-even":"table-content-odd",style:{border:"none",borderCollapse:"collapse"},children:[e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:P}),e.jsx("td",{style:{border:"none",borderCollapse:"collapse"},children:e.jsx(qo,{value:typeof p!="string"?p.toString():p,maxChars:25})})]},P))})})})]})):null}const Uo=r.memo(zo),Tt={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"}},Bo=i=>{if(!i)return"";const m=i.toString().replace(/[^0-9]/g,"");if(m.length<5)return m;const c=m.slice(0,4),n=m.slice(4,7),l=m.slice(7,11);return[c,n,l].filter(Boolean).join("-")};function Qo({id:i}){const{online:m,sendMessage:c,addListener:n,removeListener:l,getUniqueId:b}=r.useContext(fe),[g,t]=r.useState(null),[x,P]=r.useState(null),p=r.useRef(null),C=r.useRef(b()),{showConfirmCancelDialog:E}=r.useContext(Be);s&&console.log(`QRDiv loading with id = "${i}" storeId "${g}" and matter:`,x),r.useEffect(()=>{s&&console.log(`QRDiv id effect "${i}"`),i&&(s&&console.log(`QRDiv sending data request for storeId "${i}"`),t(i),c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:i,server:!0}}))},[i]),r.useEffect(()=>{s&&console.log(`QRDiv storeId effect "${g}"`)},[g]),r.useEffect(()=>{const y=j=>{j.method==="refresh_required"&&j.response.changed==="matter"&&j.response.matter&&(s&&console.log(`QRDiv received refresh_required: changed=${j.response.changed} for storeId "${j.response.matter.id}":`,j.response.matter),g===j.response.matter.id&&(s&&console.log(`QRDiv received refresh_required/matter: setting matter data for storeId "${j.response.matter.id}":`,j.response.matter),p.current&&clearTimeout(p.current),j.response.matter.advertising&&j.response.matter.advertiseTime&&j.response.matter.advertiseTime+9e5<=Date.now()&&(j.response.matter.advertising=!1),P(j.response.matter),j.response.matter.advertising&&(s&&console.log(`QRDiv setting matter advertise timeout for storeId "${j.response.matter.id}":`,j.response.matter.advertiseTime+9e5-Date.now()),p.current=setTimeout(()=>{p.current&&clearTimeout(p.current),s&&console.log(`QRDiv clearing advertising state for storeId "${g}" after 15 minutes`),P(k=>k&&{...k,advertising:!1})},j.response.matter.advertiseTime+9e5-Date.now()))))};return n(y,C.current),s&&console.log("QRDiv webSocket effect mounted"),()=>{l(y),p.current&&clearTimeout(p.current),p.current=null,s&&console.log("QRDiv webSocket effect unmounted")}},[n,l,g]);const H=()=>{s&&console.log(`QRDiv sent matter startCommission for node "${x?.id}"`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,startCommission:!0}})},W=()=>{s&&console.log(`QRDiv sent matter stopCommission for node "${x?.id}"`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,stopCommission:!0}})},_=()=>{s&&console.log(`QRDiv sent matter advertise for node "${x?.id}"`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,advertise:!0}})},f=y=>{s&&console.log(`QRDiv sent matter removeFabric for node "${x?.id}" and fabricIndex ${y}`),x&&c({id:C.current,sender:"QRDiv",method:"/api/matter",src:"Frontend",dst:"Matterbridge",params:{id:x.id,removeFabric:y}})},X=async()=>{if(!x||!x.manualPairingCode)return;const y=x.manualPairingCode.toString();try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(y);else{const j=document.createElement("textarea");j.value=y,j.style.position="fixed",j.style.opacity="0",document.body.appendChild(j),j.focus(),j.select(),document.execCommand("copy"),document.body.removeChild(j)}s&&console.log("Manual pairing code copied to clipboard")}catch(j){console.error("Failed to copy manual pairing code",j)}};return!x||!m?(s&&console.log("QRDiv rendering undefined state"),null):x.online?x.advertising&&x.qrPairingCode&&x.manualPairingCode?(s&&console.log("QRDiv rendering advertising state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"QR pairing code"}),e.jsxs("div",{className:"MbfWindowHeaderFooterIcons",children:[e.jsx(Q,{"aria-label":"send advertising",size:"small",onClick:_,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:W,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: ",Bo(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:X,sx:Tt,children:e.jsx(re,{path:oo,size:.85})})})})]})]})):x.commissioned&&x.fabricInformations&&x.sessionInformations?(s&&console.log("QRDiv rendering commissioned state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Paired fabrics"}),e.jsxs("div",{className:"MbfWindowHeaderFooterIcons",children:[e.jsx(Q,{"aria-label":"send advertising",size:"small",onClick:_,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:H,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((y,j)=>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: ",y.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:()=>E("Remove fabric","Are you sure you want to remove this fabric? You will also need to remove it from the controller.","RemoveFabric",()=>f(y.fabricIndex),()=>{}),sx:{...Tt,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: ",y.rootVendorId," ",y.rootVendorName]}),y.label!==""&&e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Label: ",y.label]}),e.jsxs("p",{style:{margin:"0px 20px 0px 20px",color:"var(--div-text-color)"},children:["Sessions: ",x.sessionInformations?x.sessionInformations.filter(k=>k.fabric?.fabricIndex===y.fabricIndex&&k.isPeerActive===!0).length:"0"," ","subscriptions: ",x.sessionInformations?x.sessionInformations.filter(k=>k.fabric?.fabricIndex===y.fabricIndex&&k.isPeerActive===!0&&k.numberOfActiveSubscriptions>0).length:"0"]})]},j))]}),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?(s&&console.log("QRDiv rendering not commissioned and not advertising state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsx("div",{className:"MbfWindowHeader",style:{height:"30px"},children:e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"QR pairing code"})}),e.jsx("p",{className:"MbfWindowHeaderText thin-scroll",style:{overflowX:"auto",maxWidth:"280px",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:g}),e.jsx(oe,{onClick:H,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]})})]})):(s&&console.log("QRDiv rendering unknown state"),null):(s&&console.log("QRDiv rendering offline state"),e.jsxs("div",{className:"MbfWindowDiv",style:{alignItems:"center",minWidth:"302px"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",style:{textAlign:"left"},children:"Server node"}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons"})]}),e.jsx("p",{className:"MbfWindowHeaderText",style:{overflow:"hidden",maxWidth:"280px",textOverflow:"ellipsis",textAlign:"center",fontSize:"14px",fontWeight:"bold",color:"var(--secondary-color)"},children:g}),e.jsx("p",{style:{textAlign:"center",fontSize:"14px",fontWeight:"normal"},children:"Server offline"}),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 Ko=r.memo(Qo);function Jo(){const{logMessage:i,sendMessage:m,getUniqueId:c}=r.useContext(fe),[n,l]=r.useState("matterbridge-"),[b,g]=r.useState(!1),[t,x]=r.useState(null),P=r.useRef(c()),p=j=>{j.preventDefault(),g(!0)},C=()=>{g(!1)},E=j=>{j.preventDefault(),g(!1);const k=j.dataTransfer.files[0];if(k){i("Plugins",`Installing package ${k.name}. Please wait...`);const R=new FormData;R.append("file",k),R.append("filename",k.name),fetch("./api/uploadpackage",{method:"POST",body:R}).then(O=>O.text()).then(O=>{i("Plugins",`Server response: ${O}`)}).catch(O=>{console.error("Error uploading plugin file:",O),i("Plugins",`Error installing package ${O}`)})}},H=j=>{const k=j.target.files&&j.target.files[0];if(k){i("Plugins",`Uploading package ${k.name}`);const R=new FormData;R.append("file",k),R.append("filename",k.name),fetch("./api/uploadpackage",{method:"POST",body:R}).then(O=>O.text()).then(O=>{i("Plugins",`Server response: ${O}`)}).catch(O=>{console.error("Error uploading plugin file:",O),i("Plugins",`Error uploading package ${O}`)})}},W=()=>{m({id:P.current,sender:"InstallPlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:n,restart:!1}})},_=()=>{document.getElementById("file-upload")?.click()},f=()=>{m({id:P.current,sender:"InstallPlugins",method:"/api/addplugin",src:"Frontend",dst:"Matterbridge",params:{pluginNameOrPath:n}})},X=j=>{x(j.currentTarget)},y=j=>{j!==""&&l(j),x(null)};return s&&console.log("AddRemovePlugins rendering..."),e.jsxs("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",alignItems:"center",justifyContent:"space-between",margin:"0px",padding:"10px",gap:"20px"},onDragOver:p,onDragLeave:C,onDrop:E,children:[e.jsx(pe,{value:n,onChange:j=>{l(j.target.value)},size:"small",id:"plugin-name",label:"Plugin name or plugin path",variant:"outlined",fullWidth:!0}),e.jsx(Q,{onClick:X,children:e.jsx(br,{})}),e.jsxs(ze,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:!!t,onClose:()=>y(""),children:[e.jsx(D,{onClick:()=>y("matterbridge-zigbee2mqtt"),children:"matterbridge-zigbee2mqtt"}),e.jsx(D,{onClick:()=>y("matterbridge-somfy-tahoma"),children:"matterbridge-somfy-tahoma"}),e.jsx(D,{onClick:()=>y("matterbridge-shelly"),children:"matterbridge-shelly"}),e.jsx(D,{onClick:()=>y("matterbridge-hass"),children:"matterbridge-hass"}),e.jsx(D,{onClick:()=>y("matterbridge-webhooks"),children:"matterbridge-webhooks"}),e.jsx(D,{onClick:()=>y("matterbridge-bthome"),children:"matterbridge-bthome"}),e.jsx(D,{onClick:()=>y("matterbridge-test"),children:"matterbridge-test"}),e.jsx(D,{onClick:()=>y("matterbridge-example-accessory-platform"),children:"matterbridge-example-accessory-platform"}),e.jsx(D,{onClick:()=>y("matterbridge-example-dynamic-platform"),children:"matterbridge-example-dynamic-platform"}),e.jsx(D,{onClick:()=>y("matterbridge-eve-door"),children:"matterbridge-eve-door"}),e.jsx(D,{onClick:()=>y("matterbridge-eve-motion"),children:"matterbridge-eve-motion"}),e.jsx(D,{onClick:()=>y("matterbridge-eve-energy"),children:"matterbridge-eve-energy"}),e.jsx(D,{onClick:()=>y("matterbridge-eve-weather"),children:"matterbridge-eve-weather"}),e.jsx(D,{onClick:()=>y("matterbridge-eve-room"),children:"matterbridge-eve-room"})]}),e.jsx(T,{title:"Install or update a plugin from npm",children:e.jsx(oe,{onClick:W,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(oe,{onClick:_,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(oe,{onClick:f,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:H})]})}const Go=r.memo(Jo);function Ee({status:i,enabledText:m="Enabled",disabledText:c=void 0,tooltipText:n=void 0,onClick:l}){if(i===void 0)return null;{const b=e.jsx("div",{className:i?"status-enabled":"status-disabled",style:{cursor:"default"},onClick:l,children:i?m:c??m});return n!==void 0?e.jsx(T,{title:n,children:b}):b}}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)"},Yo={fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)",backgroundColor:"var(--div-bg-color)"},Xo={fontSize:"16px",fontWeight:"bold",backgroundColor:"var(--div-bg-color)"},Ne={padding:"0px",margin:"0px"},Zo="5px 10px 5px 10px",st={},be={},at={},lt={};let qe=[],xt=[];const en=({open:i,onClose:m,plugin:c})=>{const{sendMessage:n,addListener:l,removeListener:b,getUniqueId:g}=r.useContext(fe),t=r.useRef(g()),[x,P]=r.useState(c.configJson),[p,C]=r.useState(null),[E,H]=r.useState({"ui:submitButtonOptions":{submitText:"Confirm"},"ui:globalOptions":{orderable:!0}}),[W,_]=r.useState("");let f={};r.useEffect(()=>{const S=M=>{M.src==="Matterbridge"&&M.dst==="Frontend"&&(Rt(M)&&M.id===t.current&&M.method==="/api/select/devices"&&M.response&&(s&&console.log(`ConfigPluginDialog (id: ${M.id}) received ${M.response.length} /api/select/devices:`,M.response),qe=M.response),Rt(M)&&M.id===t.current&&M.method==="/api/select/entities"&&M.response&&(s&&console.log(`ConfigPluginDialog (id: ${M.id}) received ${M.response.length} /api/select/entities:`,M.response),xt=M.response))};return l(S,t.current),s&&console.log("ConfigPluginDialog added WebSocket listener id:",t.current),x&&p&&p.properties&&(Object.keys(p.properties).forEach(M=>{Object.keys(p.properties[M]).forEach(F=>{F.startsWith("ui:")&&(E[M]={},E[M][F]=p.properties[M][F],delete p.properties[M][F])})}),H(E)),c.name&&c.configJson&&c.schemaJson&&(P(c.configJson),C(c.schemaJson),n({id:t.current,sender:"ConfigPlugin",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name}}),n({id:t.current,sender:"ConfigPlugin",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name}}),s&&console.log('HomePlugins sent "/api/select/devices" and "/api/select/entities" for plugin:',c.name)),()=>{b(S),s&&console.log("ConfigPluginDialog removed WebSocket listener")}},[l,x,c,b,p,n,E]);const X=(S,M)=>{f=S.formData},y=S=>{s&&console.log("ConfigPluginDialog handleSaveChanges:",S.formData),P(S.formData),c.configJson=S.formData,c.restartRequired=!0,n({id:t.current,sender:"ConfigPlugin",method:"/api/savepluginconfig",src:"Frontend",dst:"Matterbridge",params:{pluginName:S.formData.name,formData:S.formData}}),m()};function j(S){const{id:M,label:F,onKeyChange:A,onDropPropertyClick:Y,disabled:ae,schema:de,children:le,registry:N,readonly:h,required:ne}=S,{templates:J}=N,{RemoveButton:ve}=J.ButtonTemplates;if(!(Fo in de))return e.jsx(Z,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:le});const he=({target:K})=>A(K&&K.value);return e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",flexGrow:1,padding:0,margin:0,border:"none"},children:[e.jsx(pe,{id:`${M}-key`,name:`${M}-key`,required:ne,disabled:ae||h,defaultValue:F,onBlur:h?void 0:he,type:"text",variant:"outlined",sx:{width:"250px",minWidth:"250px",maxWidth:"250px",marginRight:"20px"}}),e.jsx(Z,{sx:{flex:1},children:le}),e.jsx(ve,{disabled:ae||h,onClick:Y(F),registry:N})]})}function k(S){const{children:M,description:F,displayLabel:A,errors:Y,help:ae,hidden:de,registry:le,uiSchema:N}=S,h=Lo(N),ne=$o("WrapIfAdditionalTemplate",le,h);return de?e.jsx("div",{style:{display:"none"},children:M}):e.jsx(Z,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:0,margin:0,border:"none"},children:e.jsxs(ne,{...S,children:[A===!0&&F,M,Y,ae]})})}function R(S){const{description:M}=S;return M?e.jsx(ie,{sx:_e,children:M}):null}function O(S){const{required:M,title:F}=S;return F?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsxs(ie,{sx:Ae,children:["Title ",F," ",M&&e.jsx("mark",{children:"***"})]})}):null}function G(S){const{help:M}=S;return M?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:e.jsx(ie,{sx:Yo,children:M})}):null}function v(S){const{errors:M}=S;return M?e.jsxs(Z,{sx:{padding:"10px",margin:"10px",border:"1px solid grey"},children:[e.jsx(ie,{color:"error",sx:Xo,children:"Please fix the following errors:"}),e.jsx(Je,{children:M.map((F,A)=>e.jsxs(yr,{children:[e.jsx(z,{children:e.jsx(jr,{color:"error"})}),e.jsx(te,{primary:F.stack})]},A))})]}):null}function a(S){const{errors:M}=S;return M?e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginTop:"5px"},children:M.map((F,A)=>e.jsxs(ie,{color:"error",variant:"body2",sx:{marginLeft:1},children:["This field ",F]},A))}):null}function o(S){const{id:M,name:F,_schema:A,_uiSchema:Y,value:ae,options:de,label:le,type:N,placeholder:h,required:ne,disabled:J,readonly:ve,autofocus:je,onChange:he,onChangeOverride:K,onBlur:ce,onFocus:ye,_rawErrors:Qe,_hideError:B,_registry:I,_formContext:ue}=S,Ke=({target:{value:we}})=>he(we===""?de.emptyValue:we),Pe=({target:we})=>ce(M,we&&we.value),Ye=({target:we})=>ye(M,we&&we.value);return e.jsx(Z,{sx:{padding:"0px",margin:"0px"},children:e.jsx(pe,{id:M,name:M,label:h&&h!==""?le:void 0,variant:"outlined",placeholder:h&&h!==""?h:le,required:ne,disabled:J||ve,autoFocus:je,value:ae||ae===0?ae:"",type:N,autoComplete:N==="password"?"current-password":F,onChange:K||Ke,onBlur:Pe,onFocus:Ye,fullWidth:!0})})}function d(S){return console.log("ArrayFieldTitleTemplate:",S),null}function u(S){return console.log("ArrayFieldDescriptionTemplate:",S),null}function w(S){return console.log("ArrayFieldItemTemplate:",S),null}function V(S){const{canAdd:M,onAddClick:F,schema:A,title:Y}=S,[ae,de]=r.useState(!1),[le,N]=r.useState(!1),[h,ne]=r.useState(!1),[J,ve]=r.useState(""),je=I=>{ve(I.target.value)},he=()=>{s&&console.log("ArrayFieldTemplate: handleDialogDeviceToggle filter:",J,"selectDevices:",qe),de(!ae)},K=()=>{s&&console.log("ArrayFieldTemplate: handleDialogEntityToggle filter:",J,"selectEntities:",xt),N(!le)},ce=()=>{s&&console.log("ArrayFieldTemplate: handleDialogDeviceEntityToggle filter:",J,"selectDevices:",qe),ne(!h)},ye=I=>{de(!1),A.selectFrom==="serial"?A.items.default=I.serial:A.selectFrom==="name"&&(A.items.default=I.name),F()},Qe=I=>{N(!1),A.selectEntityFrom==="name"?A.items.default=I.name:A.selectEntityFrom==="description"&&(A.items.default=I.description),F()},B=I=>{ne(!1),A.selectDeviceEntityFrom==="name"?A.items.default=I.name:A.selectDeviceEntityFrom==="description"&&(A.items.default=I.description),F()};return e.jsxs(Z,{sx:{margin:"0px",padding:"5px 10px 5px 10px",border:"1px solid grey"},children:[Y&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[Y&&e.jsx(ie,{sx:Ae,children:Y}),M&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[A.selectFrom&&e.jsx(T,{title:"Add a device from the list",children:e.jsx(Q,{onClick:he,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),A.selectEntityFrom&&e.jsx(T,{title:"Add an entity from the list",children:e.jsx(Q,{onClick:K,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),A.selectDeviceEntityFrom&&e.jsx(T,{title:"Add a device entity from the list",children:e.jsx(Q,{onClick:ce,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),e.jsx(T,{title:"Add a new item",children:e.jsx(Q,{onClick:F,size:"small",color:"primary",sx:Ne,children:e.jsx(ct,{})})})]})]}),A.description&&e.jsx(ie,{sx:_e,children:A.description}),S.items.map(I=>e.jsxs(Z,{sx:{margin:"2px 0px",padding:"0px",display:"flex",alignItems:"center"},children:[e.jsx(Z,{sx:{flexGrow:1,marginRight:"10px"},children:I.children}),e.jsx(Q,{disabled:!I.hasMoveUp,onClick:I.onReorderClick(I.index,I.index-1),size:"small",color:"primary",sx:Ne,children:e.jsx(Mt,{})}),e.jsx(Q,{disabled:!I.hasMoveDown,onClick:I.onReorderClick(I.index,I.index+1),size:"small",color:"primary",sx:Ne,children:e.jsx(St,{})}),e.jsx(Q,{onClick:I.onDropIndexClick(I.index),size:"small",color:"primary",sx:Ne,children:e.jsx(ut,{})})]},I.index)),e.jsxs(Me,{open:ae,onClose:he,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(ke,{children:"Select a device"}),e.jsxs(Ie,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ie,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:J,onChange:je,placeholder:"Enter serial or name"})]}),e.jsx(Je,{dense:!0,children:qe.filter(I=>I.serial.toLowerCase().includes(J.toLowerCase())||I.name.toLowerCase().includes(J.toLowerCase())).map((I,ue)=>e.jsxs(rt,{onClick:()=>ye(I),sx:st,children:[I.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:be})}),I.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:be})}),I.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:be})}),e.jsx(te,{primary:I.name,secondary:I.serial,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ue))})]}),e.jsx($e,{children:e.jsx(oe,{onClick:he,children:"Close"})})]}),e.jsxs(Me,{open:le,onClose:K,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(ke,{children:"Select an entity"}),e.jsxs(Ie,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ie,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:J,onChange:je,placeholder:"Enter name or description"})]}),e.jsx(Je,{dense:!0,children:xt.filter(I=>I.name.toLowerCase().includes(J.toLowerCase())||I.description.toLowerCase().includes(J.toLowerCase())).map((I,ue)=>e.jsxs(rt,{onClick:()=>Qe(I),sx:st,children:[I.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:be})}),I.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:be})}),I.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:be})}),I.icon==="component"&&e.jsx(z,{children:e.jsx(kt,{style:be})}),I.icon==="matter"&&e.jsx(z,{children:e.jsx(It,{style:be})}),e.jsx(te,{primary:I.name,secondary:I.description,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ue))})]}),e.jsx($e,{children:e.jsx(oe,{onClick:K,children:"Close"})})]}),e.jsxs(Me,{open:h,onClose:ce,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsxs(ke,{children:["Select an entity for ",Y]}),e.jsx(Ie,{children:e.jsx(Je,{dense:!0,children:qe.filter(I=>I.serial===Y||I.name===Y).map(I=>I.entities?.map((ue,Ke)=>e.jsxs(rt,{onClick:()=>B(ue),sx:st,children:[ue.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:be})}),ue.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:be})}),ue.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:be})}),ue.icon==="component"&&e.jsx(z,{children:e.jsx(kt,{style:be})}),ue.icon==="matter"&&e.jsx(z,{children:e.jsx(It,{style:be})}),e.jsx(te,{primary:ue.name,secondary:ue.description,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},Ke)))})}),e.jsx($e,{children:e.jsx(oe,{onClick:ce,children:"Close"})})]})]})}function ge(S){const{onAddClick:M,schema:F,properties:A,title:Y,description:ae}=S,[de,le]=r.useState(!1),[N,h]=r.useState(""),ne=K=>{h(K.target.value)},J=()=>{le(!de)},ve=K=>{s&&console.log(`ObjectFieldTemplate: handleSelectValue value "${K.serial}" for schema "${F.selectFrom}"`),le(!1);let ce="";F.selectFrom==="serial"?ce=K.serial:F.selectFrom==="name"&&(ce=K.name),_(ce),s&&console.log(`ObjectFieldTemplate: handleSelectValue newkey "${ce}"`),M(F)()},je=()=>{M(F)()},he=!F.additionalProperties;return s&&console.log(`ObjectFieldTemplate: isRoot ${he} newkey "${W}"`),!he&&W!==""&&(s&&console.log("ObjectFieldTemplate: newkey",W,"properties",A),A.forEach(K=>{if(K.name==="newKey"&&K.content.key==="newKey"&&K.content.props.name==="newKey"&&K.content.props.onKeyChange&&W!==""){s&&console.log("ObjectFieldTemplate: newkey onKeyChange",W);const ce=W;_(""),K.content.props.onKeyChange(ce)}})),e.jsxs(Z,{sx:{margin:"0px",padding:he?"10px":"5px 10px 0px 10px",border:he?"none":"1px solid grey"},children:[F.title&&he&&e.jsx(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(ie,{sx:Ae,children:F.title})}),Y&&!he&&e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[e.jsx(ie,{sx:Ae,children:Y}),e.jsxs(Z,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0px",margin:"0px"},children:[F.selectFrom&&e.jsx(T,{title:"Add a device from the list",children:e.jsx(Q,{onClick:J,size:"small",color:"primary",sx:Ne,children:e.jsx(tt,{})})}),e.jsx(T,{title:"Add a new item",children:e.jsx(Q,{onClick:je,size:"small",color:"primary",sx:Ne,children:e.jsx(ct,{})})})]})]}),F.description&&e.jsx(Z,{sx:{padding:"0px",margin:"0px",marginBottom:"10px"},children:e.jsx(ie,{sx:_e,children:F.description})}),A.map(({content:K,name:ce,hidden:ye})=>!ye&&e.jsxs(Z,{sx:{margin:"0px",marginBottom:"10px",padding:["object","array","boolean"].includes(F.properties[ce].type)?"0px":Zo,border:["object","array","boolean"].includes(F.properties[ce].type)?"none":"1px solid grey"},children:[!["object","array","boolean"].includes(F.properties[ce].type)&&e.jsx(ie,{sx:Ae,children:ce}),e.jsx(Z,{sx:{flexGrow:1,padding:"0px",margin:"0px"},children:K})]},ce)),e.jsxs(Me,{open:de,onClose:J,PaperProps:{sx:{maxHeight:"50vh",maxWidth:"50vw",overflow:"auto"}},children:[e.jsx(ke,{children:"Select a device"}),e.jsxs(Ie,{children:[e.jsxs(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px",marginBottom:"10px"},children:[e.jsx(ie,{variant:"subtitle1",sx:{whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{fullWidth:!0,variant:"outlined",value:N,onChange:ne,placeholder:"Enter serial or name"})]}),e.jsx(Je,{dense:!0,children:qe.filter(K=>K.serial.toLowerCase().includes(N.toLowerCase())||K.name.toLowerCase().includes(N.toLowerCase())).map((K,ce)=>e.jsxs(rt,{onClick:()=>ve(K),sx:st,children:[K.icon==="wifi"&&e.jsx(z,{children:e.jsx(Ge,{style:be})}),K.icon==="ble"&&e.jsx(z,{children:e.jsx(ot,{style:be})}),K.icon==="hub"&&e.jsx(z,{children:e.jsx(nt,{style:be})}),e.jsx(te,{primary:K.name,secondary:K.serial,primaryTypographyProps:{style:at},secondaryTypographyProps:{style:lt}})]},ce))})]}),e.jsx($e,{children:e.jsx(oe,{onClick:J,children:"Close"})})]})]})}function me(S){const{uiSchema:M}=S,{submitText:F,norender:A}=Wo(M);return A?null:e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",margin:"10px",padding:"0px",gap:"20px"},children:[e.jsx(oe,{type:"submit",variant:"contained",color:"primary",children:F}),e.jsx(oe,{variant:"contained",color:"primary",onClick:m,children:"Cancel"})]})}function xe(S){const{className:M,disabled:F,onClick:A,registry:Y,style:ae,uiSchema:de,...le}=S;return e.jsx(T,{title:"Remove the item",children:e.jsx(Q,{disabled:F,size:"small",color:"primary",onClick:A,children:e.jsx(ut,{})})})}function ee(S){const{className:M,disabled:F,onClick:A,registry:Y,uiSchema:ae,...de}=S;return e.jsx(T,{title:"Add an item",children:e.jsx(Q,{size:"small",color:"primary",onClick:A,children:e.jsx(ct,{})})})}function se(S){const{disabled:M,onClick:F,registry:A,style:Y,uiSchema:ae,...de}=S;return e.jsx(T,{title:"Move up the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:F,children:e.jsx(Mt,{})})})}function L(S){const{disabled:M,onClick:F,registry:A,style:Y,uiSchema:ae,...de}=S;return e.jsx(T,{title:"Move down the item",children:e.jsx(Q,{size:"small",color:"primary",onClick:F,children:e.jsx(St,{})})})}function U(S){const{id:M,name:F,value:A,schema:Y,readonly:ae,onChange:de}=S,[le,N]=r.useState(),h=J=>{s&&console.log(`CheckboxWidget ${F} onChangeField:`,J),N(J&&J!==""?J:void 0)},ne=()=>{s&&console.log(`CheckboxWidget onClick plugin="${c.name}" action="${F}" value="${le}"`),n({id:t.current,sender:"ConfigPlugin",method:"/api/action",src:"Frontend",dst:"Matterbridge",params:{plugin:c.name,action:F,value:le,formData:f,id:M}}),Y.buttonClose===!0?m():Y.buttonSave===!0&&y({formData:x})};return Y.buttonText&&Y.description?e.jsxs(Z,{sx:{margin:"0px",padding:"10px",border:"1px solid grey",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(ie,{sx:_e,children:Y.description}),e.jsx(oe,{variant:"contained",color:"primary",onClick:()=>ne(),children:Y.buttonText})]}):Y.buttonField&&Y.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(ie,{sx:_e,children:Y.description}),e.jsx(pe,{id:F+"-input",name:F,label:Y.textLabel,placeholder:Y.textPlaceholder,onChange:J=>h(J.target.value),sx:{width:"250px",minWidth:"250px",maxWidth:"250px"}}),e.jsx(oe,{id:F+"-button",variant:"contained",color:"primary",disabled:le===void 0,onClick:()=>ne(),children:Y.buttonField})]}):e.jsxs(Z,{sx:{margin:"0px",padding:"5px 10px",border:"1px solid grey"},children:[F&&e.jsxs(Z,{sx:{margin:"0px",padding:"0px",gap:"10px",display:"flex",justifyContent:"flex-start",alignItems:"center"},children:[e.jsx(ie,{sx:Ae,children:F}),e.jsx(Te,{checked:A,readOnly:ae,onChange:()=>de(!A),sx:{padding:"0px",margin:"0px"}})]}),Y.description&&e.jsx(ie,{sx:_e,children:Y.description})]})}function $({schema:S,id:M,name:F,options:A,label:Y,hideLabel:ae,required:de,disabled:le,placeholder:N,readonly:h,value:ne,multiple:J,autofocus:ve,onChange:je,onBlur:he,onFocus:K,errorSchema:ce,rawErrors:ye=[],registry:Qe,uiSchema:B,hideError:I,formContext:ue,...Ke}){const{enumOptions:Pe,enumDisabled:Ye,emptyValue:we}=A;J=typeof J>"u"?!1:!!J;const yt=J?[]:"",jt=typeof ne>"u"||J&&ne.length<1||!J&&ne===yt,Kt=({target:{value:De}})=>je(ft(De,Pe,we)),Jt=({target:De})=>he(M,ft(De&&De.value,Pe,we)),Gt=({target:De})=>K(M,ft(De&&De.value,Pe,we)),Ct=No(ne,Pe,J),{InputLabelProps:Yt,SelectProps:Xt,autocomplete:Zt,...er}=Ke,tr=!J&&S.default===void 0;return e.jsxs(pe,{id:M,name:M,value:!jt&&typeof Ct<"u"?Ct:yt,required:de,disabled:le||h,autoFocus:ve,autoComplete:Zt,placeholder:N,error:ye.length>0,onChange:Kt,onBlur:Jt,onFocus:Gt,...er,select:!0,InputLabelProps:{...Yt,shrink:!jt},SelectProps:{...Xt,multiple:J},"aria-describedby":Po(M),children:[tr&&e.jsx(D,{value:"",children:N}),Array.isArray(Pe)&&Pe.map(({value:De,label:rr},wt)=>{const or=Array.isArray(Ye)&&Ye.indexOf(De)!==-1;return e.jsx(D,{value:String(wt),disabled:or,children:rr},wt)})]})}return s&&console.log("ConfigPluginDialog rendering..."),!i||!p||!x?null:e.jsxs(Me,{open:i,onClose:m,slotProps:{paper:{sx:{maxWidth:"800px"}}},children:[e.jsx(ke,{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(Ie,{style:{padding:"0px",margin:"0px",width:"800px",height:"600px",overflow:"auto"},children:e.jsx(Io,{schema:p,formData:x,uiSchema:E,validator:Do,templates:{FieldTemplate:k,BaseInputTemplate:o,TitleFieldTemplate:O,DescriptionFieldTemplate:R,FieldHelpTemplate:G,FieldErrorTemplate:a,ErrorListTemplate:v,WrapIfAdditionalTemplate:j,ArrayFieldTitleTemplate:d,ArrayFieldDescriptionTemplate:u,ArrayFieldItemTemplate:w,ArrayFieldTemplate:V,ObjectFieldTemplate:ge,ButtonTemplates:{SubmitButton:me,RemoveButton:xe,AddButton:ee,MoveUpButton:se,MoveDownButton:L}},widgets:{CheckboxWidget:U,SelectWidget:$},onChange:X,onSubmit:y})})]})};function Qt(i){if(s&&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 m=0,c=0;for(const n of i.sessionInformations??[])n.fabric&&n.isPeerActive===!0&&m++,n.numberOfActiveSubscriptions>0&&(c+=n.numberOfActiveSubscriptions);return i.commissioned===!0&&i.fabricInformations&&i.sessionInformations&&(m===0||c===0)?"var(--secondary-color)":"var(--div-text-color)"}function tn(i,m,c){const n=i?.[c],l=m?.[c];return n==null&&l==null?0:n==null?-1:l==null?1:typeof n=="boolean"&&typeof l=="boolean"?n===l?0:n?1:-1:typeof n=="number"&&typeof l=="number"?n-l:String(n).localeCompare(String(l))}function rn({name:i,title:m,columns:c,rows:n,getRowKey:l,footerLeft:b,footerRight:g,onRowClick:t}){const x=r.useRef(new WeakMap),P=r.useRef(1),p=a=>{if(typeof l=="string"&&a&&a[l]!=null)return a[l];if(typeof l=="function"){const u=l(a);if(u!=null)return u}const o=c?.[0]?.id;if(o&&a&&a[o]!=null)return a[o];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_${P.current++}`,x.current.set(a,d)),d},[C,E]=r.useState(localStorage.getItem(`${i}_table_order_by`)||null),[H,W]=r.useState(localStorage.getItem(`${i}_table_order`)||null),[_,f]=r.useState(!1),[X,y]=r.useState(()=>{try{const a=localStorage.getItem(`${i}_column_visibility`);if(a)return JSON.parse(a)}catch{}return{}}),j=r.useMemo(()=>{const a={};for(const o of c)o.hidden||(a[o.id]=o.required?!0:X[o.id]!==!1);return a},[c,X]),k=r.useMemo(()=>{if(!C||!H)return n;const a=c.find(d=>d.id===C);if(!a||a.noSort)return n;const o=n.map((d,u)=>({el:d,index:u}));return o.sort((d,u)=>{let w;return typeof a.comparator=="function"?w=a.comparator(d.el,u.el):w=tn(d.el,u.el,C),w!==0?H==="asc"?w:-w:d.index-u.index}),o.map(d=>d.el)},[n,C,H,c]),R=a=>{if(C!==a||!C){E(a),W("asc"),localStorage.setItem(`${i}_table_order_by`,a),localStorage.setItem(`${i}_table_order`,"asc");return}if(H==="asc"){W("desc"),localStorage.setItem(`${i}_table_order`,"desc");return}E(null),W(null),localStorage.removeItem(`${i}_table_order_by`),localStorage.removeItem(`${i}_table_order`)},O=()=>{f(!_)},G=a=>{y(o=>{const d=c.find(V=>V.id===a);if(d&&d.required)return o;const u=j[a]!==!1,w={...o};u?w[a]=!1:delete w[a];try{localStorage.setItem(`${i}_column_visibility`,JSON.stringify(w))}catch{}return w})},v=()=>{y({});try{localStorage.removeItem(`${i}_column_visibility`)}catch{}f(!1)};return s&&console.log(`Rendering table ${i}${C&&H?` ordered by ${C}:${H}`:""}`),e.jsxs("div",{style:{display:"flex",flexDirection:"column",margin:"0",padding:"0",gap:"0",width:"100%",flex:"1 1 auto",height:"100%",minHeight:0,overflow:"hidden"},children:[e.jsxs(Me,{open:_,onClose:(a,o)=>{o==="backdropClick"||o==="escapeKeyDown"||O()},disableEscapeKeyDown:!0,disableRestoreFocus:!0,children:[e.jsx(ke,{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(Ie,{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:j[a.id]!==!1,onChange:()=>G(a.id)}),label:a.label},a.id))})}),e.jsxs($e,{children:[e.jsx(oe,{onClick:v,children:"Reset"}),e.jsx(oe,{variant:"contained",onClick:a=>{if(a?.currentTarget&&typeof a.currentTarget.blur=="function")try{a.currentTarget.blur()}catch{}const o=document.activeElement;if(o&&o instanceof HTMLElement&&typeof o.blur=="function")try{o.blur()}catch{}O()},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}),m&&e.jsx("p",{className:"MbfWindowHeaderText",children:m}),e.jsx("div",{className:"MbfWindowHeaderFooterIcons",children:e.jsx(Q,{onClick:a=>{if(a?.currentTarget?.blur)try{a.currentTarget.blur()}catch{}O()},"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&&j[a.id]===!1)return null;const o=!a.noSort,d=o&&C===a.id&&!!H;return e.jsxs("th",{onClick:o?()=>R(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:o?"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":o?d?H==="asc"?"ascending":"descending":"none":void 0,children:[a.label,d&&e.jsxs("span",{style:{marginLeft:6},children:[H==="asc"&&e.jsx(re,{path:so,size:"15px"}),H==="desc"&&e.jsx(re,{path:ao,size:"15px"})]})]},a.id)})})}),e.jsx("tbody",{children:k.map((a,o)=>{const d=p(a);return e.jsx("tr",{className:o%2===0?"table-content-even":"table-content-odd",onClick:t?u=>t(a,d,u):void 0,style:{height:"30px",minHeight:"30px",border:"none",borderCollapse:"collapse",cursor:t?"pointer":void 0},children:c.map(u=>{if(u.hidden||!u.required&&j[u.id]===!1)return null;const w=a[u.id];return e.jsx("td",{style:{border:"none",borderCollapse:"collapse",textAlign:u.align||"left",padding:"5px 10px",margin:"0",maxWidth:u.maxWidth,whiteSpace:u.maxWidth?"nowrap":void 0,overflow:u.maxWidth?"hidden":void 0,textOverflow:u.maxWidth?"ellipsis":void 0},children:typeof u.render=="function"?u.render(w,d,a,u):typeof w=="boolean"?e.jsx(Te,{checked:w,disabled:!0,size:"small",sx:{m:0,p:0,color:"var(--table-text-color)","&.Mui-disabled":{color:"var(--table-text-color)",opacity:.7}}}):u.format&&typeof w=="number"?u.format(w):w!=null?String(w):null},u.id)})},d)})})]})}),(b||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:b}),e.jsx("p",{className:"MbfWindowFooterText",style:{fontSize:"14px",fontWeight:"normal",color:"var(--secondary-color)"},children:g})]})]})}function on(i){return r.memo(i)}const mt=on(rn);function nn({storeId:i,setStoreId:m}){const{online:c,sendMessage:n,addListener:l,removeListener:b,getUniqueId:g}=r.useContext(fe),{showConfirmCancelDialog:t}=r.useContext(Be),x=r.useRef(g()),[P,p]=r.useState(null),[C,E]=r.useState(null),[H,W]=r.useState([]),_=[{label:"Name",id:"name",required:!0,render:(L,U,$,S)=>e.jsx(T,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>a($),children:$.name})})},{label:"Description",id:"description",render:(L,U,$,S)=>e.jsx(T,{title:"Open the plugin homepage",children:e.jsx("span",{style:{cursor:"pointer"},onClick:()=>a($),children:$.description})})},{label:"Version",id:"version",render:(L,U,$,S)=>e.jsxs(e.Fragment,{children:[$.latestVersion!==void 0&&$.latestVersion!==$.version&&C&&!C.readOnly&&e.jsx(T,{title:"New plugin stable version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>k($),children:["Update to v.",$.latestVersion]})}),$.version.includes("-dev-")&&$.devVersion!==void 0&&$.devVersion!==$.version&&C&&!C.readOnly&&e.jsx(T,{title:"New plugin dev version available, click to install",children:e.jsxs("span",{className:"status-warning",style:{marginRight:"10px"},onClick:()=>R($),children:["Update to new dev v.",$.devVersion.split("-dev-")[0]]})}),e.jsx(T,{title:"Plugin version",children:e.jsx("span",{children:$.version})})]})},{label:"Author",id:"author",render:(L,U,$,S)=>e.jsx(e.Fragment,{children:$.author?$.author.replace("https://github.com/",""):"Unknown"})},{label:"Type",id:"type",render:(L,U,$,S)=>e.jsx(e.Fragment,{children:$.type?$.type.replace("Platform",""):"Unknown"})},{label:"Devices",id:"registeredDevices"},{label:"Actions",id:"actions",required:!0,noSort:!0,render:(L,U,$,S)=>e.jsxs("div",{style:{margin:"0px",padding:"0px",gap:"4px",display:"flex",flexDirection:"row"},children:[C&&C.bridgeMode==="childbridge"&&!$.error&&$.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($.matter)},onClick:()=>{$.matter?.id&&m($.matter?.id)},size:"small",children:e.jsx(At,{})})}),C&&C.bridgeMode==="childbridge"&&!$.error&&$.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($),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:$.restartRequired===!0,style:{margin:"0px",padding:"0px",width:"19px",height:"19px"},onClick:()=>xe($),size:"small",children:e.jsx(vt,{})})}),C&&!C.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:()=>{X("Remove plugin","Are you sure? This will also remove all devices and configuration from the controller.","remove",$)},size:"small",children:e.jsx(ut,{})})}),$.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:()=>{X("Disable plugin","Are you sure? This will also remove all devices and configuration from the controller.","disable",$)},size:"small",children:e.jsx(wr,{})})}):e.jsx(e.Fragment,{}),$.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:()=>v($),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($),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:()=>u($),size:"small",children:e.jsx(kr,{})})}),C&&!C.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:()=>o($),size:"small",children:e.jsx(Vt,{})})})]})},{label:"Status",id:"status",required:!0,noSort:!0,render:(L,U,$,S)=>e.jsx("div",{style:{display:"flex",flexDirection:"row",flex:"1 1 auto",margin:"0",padding:"0",gap:"5px",width:"auto",maxWidth:"max-content"},children:$.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:$.enabled===!1?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:$.enabled,enabledText:"Enabled",disabledText:"Disabled",tooltipText:"Whether the plugin is enable or disabled"})}):e.jsx(e.Fragment,{children:$.loaded&&$.started&&$.configured?e.jsx(e.Fragment,{children:e.jsx(Ee,{status:$.loaded,enabledText:"Running",tooltipText:"Whether the plugin is running"})}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{status:$.loaded,enabledText:"Loaded",tooltipText:"Whether the plugin has been loaded"}),e.jsx(Ee,{status:$.started,enabledText:"Started",tooltipText:"Whether the plugin started"}),e.jsx(Ee,{status:$.configured,enabledText:"Configured",tooltipText:"Whether the plugin has been configured"})]})})})})}];r.useEffect(()=>{const L=U=>{U.src==="Matterbridge"&&U.dst==="Frontend"&&(U.method==="refresh_required"&&U.response.changed==="plugins"&&(s&&console.log(`HomePlugins received refresh_required: changed=${U.response.changed} and sending /api/plugins request`),n({id:x.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),U.method==="refresh_required"&&U.response.changed==="matter"&&(s&&console.log(`HomePlugins received refresh_required: changed=${U.response.changed} and setting matter id ${U.response.matter?.id}`),W($=>{const S=$.findIndex(F=>F.matter?.id===U.response.matter?.id);if(S<0)return s&&console.log(`HomePlugins received refresh_required: changed=${U.response.changed} and matter id ${U.response.matter?.id} not found`),$;s&&console.log(`HomePlugins received refresh_required: changed=${U.response.changed} set matter id ${U.response.matter?.id}`);const M=[...$];return M[S]={...M[S],matter:U.response.matter},M})),U.method==="refresh_required"&&U.response.changed==="settings"&&(s&&console.log(`HomePlugins received refresh_required: changed=${U.response.changed} and sending /api/settings request`),n({id:x.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),U.id===x.current&&U.method==="/api/settings"&&(s&&console.log(`HomePlugins (id: ${U.id}) received settings:`,U.response),p(U.response.systemInformation),E(U.response.matterbridgeInformation)),U.id===x.current&&U.method==="/api/plugins"&&(s&&console.log(`HomePlugins (id: ${U.id}) received ${U.response.length} plugins:`,U.response),W(U.response)))};return l(L,x.current),s&&console.log("HomePlugins added WebSocket listener id:",x.current),()=>{b(L),s&&console.log("HomePlugins removed WebSocket listener")}},[l,b,n]),r.useEffect(()=>{c&&(s&&console.log("HomePlugins sending api requests"),n({id:x.current,sender:"HomePlugins",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),n({id:x.current,sender:"HomePlugins",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,n]);const f=r.useRef(null),X=(L,U,$,S)=>{s&&console.log(`handleActionWithConfirmCancel ${$} ${S.name}`),f.current=S,t(L,U,$,y,j)},y=L=>{s&&console.log(`handleConfirm action confirmed ${L} ${f.current?.name}`),L==="remove"&&f.current?O(f.current):L==="disable"&&f.current&&v(f.current),f.current=null},j=L=>{s&&console.log(`handleCancel action canceled ${L} ${f.current?.name}`),f.current=null},k=L=>{s&&console.log("handleUpdatePlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:L.name,restart:!1}})},R=L=>{s&&console.log("handleUpdateDevPlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/install",src:"Frontend",dst:"Matterbridge",params:{packageName:L.name+"@dev",restart:!1}})},O=L=>{s&&console.log("handleRemovePlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/removeplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}})},G=L=>{s&&console.log("handleRestartPlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/restartplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}})},v=L=>{s&&console.log("handleEnableDisablePlugin plugin:",L.name,"enabled:",L.enabled),L.enabled===!0?(L.enabled=!1,n({id:x.current,sender:"HomePlugins",method:"/api/disableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}})):(L.enabled=!0,n({id:x.current,sender:"HomePlugins",method:"/api/enableplugin",src:"Frontend",dst:"Matterbridge",params:{pluginName:L.name}}))},a=L=>{s&&console.log(`handleHomepagePlugin plugin: ${L.name} homepage: ${L.homepage}`),L.homepage&&window.open(L.homepage,"_blank")},o=L=>{s&&console.log("handleSponsorPlugin plugin:",L.name,"funding:",L.funding),L.funding&&window.open(L.funding,"_blank")},d=L=>{s&&console.log("handleHelpPlugin plugin:",L.name,"help:",L.help),L.help&&window.open(L.help,"_blank")},u=L=>{s&&console.log("handleChangelogPlugin plugin:",L.name,"changelog:",L.changelog),L.changelog&&window.open(L.changelog,"_blank")},[w,V]=r.useState(),[ge,me]=r.useState(!1),xe=L=>{s&&console.log("handleConfigPlugin plugin:",L.name),n({id:x.current,sender:"HomePlugins",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:L.name}}),n({id:x.current,sender:"HomePlugins",method:"/api/select/entities",src:"Frontend",dst:"Matterbridge",params:{plugin:L.name}}),V(L),ee()},ee=()=>{me(!0)},se=()=>{me(!1)};return s&&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:[w&&e.jsx(en,{open:ge,onClose:se,plugin:w}),e.jsx(mt,{name:"Plugins",columns:_,rows:H,footerRight:"",footerLeft:""})]}):e.jsx(Re,{})}const sn=r.memo(nn),an=i=>`${i.pluginName}::${i.serial}`;function ln({storeId:i,setStoreId:m}){const{online:c,sendMessage:n,addListener:l,removeListener:b,getUniqueId:g}=r.useContext(fe),[t,x]=r.useState(!1),[P,p]=r.useState(!0),[C,E]=r.useState(null),[H,W]=r.useState([]),[_,f]=r.useState([]),[X,y]=r.useState([]),[j,k]=r.useState([]),R=r.useRef(g()),O=[{label:"Plugin",id:"pluginName"},{label:"Name",id:"name",required:!0},{label:"Serial",id:"serial"},{label:"Availability",id:"availability",render:(a,o,d,u)=>d.reachable===!0?"Online":d.reachable===!1?e.jsx("span",{style:{color:"red"},children:"Offline"}):"",comparator:(a,o)=>{const d=a.reachable===!0?1:a.reachable===!1?0:-1,u=o.reachable===!0?1:o.reachable===!1?0:-1;return d-u}},{label:"Power",id:"powerSource",render:(a,o,d,u)=>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,o,d,u)=>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:()=>m(i===d.matter?.id?C?.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:w=>v(w,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 o=H.find(w=>w.name===a.pluginName);if(!o)return console.error(`HomeDevices isSelected: plugin ${a.pluginName} not found for device ${a.name} `),a.selected;const d=o.schemaJson?.properties?.whiteList?.selectFrom;let u=o.configJson.postfix;return u===""&&(u=void 0),o.hasWhiteList===!0&&o.hasBlackList===!0&&d&&(a.selected=!0,d==="serial"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&o.configJson.whiteList.includes(u?a.serial.replace("-"+u,""):a.serial)&&(a.selected=!0),d==="serial"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&!o.configJson.whiteList.includes(u?a.serial.replace("-"+u,""):a.serial)&&(a.selected=!1),d==="serial"&&o.configJson.blackList&&o.configJson.blackList.length>0&&o.configJson.blackList.includes(u?a.serial.replace("-"+u,""):a.serial)&&(a.selected=!1),d==="name"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&o.configJson.whiteList.includes(a.name)&&(a.selected=!0),d==="name"&&o.configJson.whiteList&&o.configJson.whiteList.length>0&&!o.configJson.whiteList.includes(a.name)&&(a.selected=!1),d==="name"&&o.configJson.blackList&&o.configJson.blackList.length>0&&o.configJson.blackList.includes(a.name)&&(a.selected=!1)),a.selected},[H]);r.useEffect(()=>{const a=o=>{if(o.method==="refresh_required"&&o.response.changed!=="matter"?(s&&console.log(`HomeDevices received refresh_required: changed=${o.response.changed} and sending /api/plugins request`),n({id:R.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})):o.method==="refresh_required"&&o.response.changed==="matter"?(s&&console.log(`HomeDevices received refresh_required: changed=${o.response.changed} and setting matter id ${o.response.matter?.id}`),k(d=>{const u=d.findIndex(V=>V.name.replaceAll(" ","")===o.response.matter?.id);if(u<0)return s&&console.debug(`HomeDevices: matter id ${o.response.matter?.id} not found`),d;const w=[...d];return w[u]={...w[u],matter:o.response.matter},s&&console.log(`HomeDevices received refresh_required: changed=${o.response.changed} and set matter id ${o.response.matter?.id}`),w})):o.method==="restart_required"?(s&&console.log("HomeDevices received restart_required"),x(!0)):o.method==="restart_not_required"?(s&&console.log("HomeDevices received restart_not_required"),x(!1)):o.method==="state_update"&&o.response.plugin&&o.response.serialNumber&&o.response.cluster.includes("BasicInformation")&&o.response.attribute==="reachable"&&(console.log(`HomeDevices updating device reachability for plugin ${o.response.plugin} serial ${o.response.serialNumber} value ${o.response.value}`),f(d=>{const u=d.findIndex(w=>w.pluginName===o.response.plugin&&w.serial===o.response.serialNumber);return u<0?(console.warn(`HomeDevices: device to update not found for plugin ${o.response.plugin} serial ${o.response.serialNumber}`),d):(d[u]={...d[u],reachable:o.response.value},[...d])})),o.id===R.current&&o.method==="/api/settings")s&&console.log(`HomeDevices (id: ${o.id}) received settings:`,o.response),E(o.response),x(o.response.matterbridgeInformation.restartRequired||o.response.matterbridgeInformation.fixedRestartRequired);else if(o.id===R.current&&o.method==="/api/plugins"){if(s&&console.log(`HomeDevices (id: ${o.id}) received ${o.response?.length} plugins:`,o.response),o.response){let d=!0;for(const u of o.response)u.enabled===!0&&(u.loaded!==!0||u.started!==!0||u.error===!0)&&(d=!1);if(!d)return;s&&console.log("HomeDevices reset plugins, devices and selectDevices"),p(!1),W(o.response),f([]),y([]),n({id:R.current,sender:"HomeDevices",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}),s&&console.log("HomeDevices sent /api/devices");for(const u of o.response)u.enabled===!0&&u.loaded===!0&&u.started===!0&&u.error!==!0&&(n({id:R.current,sender:"HomeDevices",method:"/api/select/devices",src:"Frontend",dst:"Matterbridge",params:{plugin:u.name}}),s&&console.log(`HomeDevices sent /api/select/devices for plugin: ${u.name}`))}}else if(o.id===R.current&&o.method==="/api/devices"){if(s&&console.log(`HomeDevices (id: ${o.id}) received ${o.response?.length} devices:`,o.response),o.response){for(const d of o.response)d.selected=G(d);f(o.response)}}else o.id===R.current&&o.method==="/api/select/devices"&&(s&&console.log(`HomeDevices (id: ${o.id}) received ${o.response?.length} selectDevices for plugin ${o.response&&o.response.length>0?o.response[0].pluginName:"without select devices"}:`,o.response),o.response&&o.response.length>0&&y(d=>{const u=d.filter(V=>V.pluginName!==o.response[0].pluginName),w=o.response.map(V=>({...V,selected:G(V)}));return[...u,...w]}))};return l(a,R.current),s&&console.log(`HomeDevices added WebSocket listener id ${R.current}`),()=>{b(a),s&&console.log("HomeDevices removed WebSocket listener")}},[H,l,b,n,G]),r.useEffect(()=>{if(_.length===0&&X.length===0){k([]);return}s&&console.log(`HomeDevices mixing devices (${_.length}) and selectDevices (${X.length})`);const a=[];for(const o of _)a.push(o);for(const o of X)_.find(d=>d.pluginName===o.pluginName&&d.serial.includes(o.serial))||a.push(o);a.length>0&&(k(a),console.log(`HomeDevices mixed ${a.length} devices and selectDevices`))},[H,_,X,k]),r.useEffect(()=>{c&&(s&&console.log("HomeDevices sending /api/settings and /api/plugins requests"),n({id:R.current,sender:"HomeDevices",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),n({id:R.current,sender:"HomeDevices",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[c,n]);const v=(a,o)=>{console.log(`handleCheckboxChange: checkbox changed to ${a.target.checked} for device ${o.name} serial ${o.serial}`),_.findIndex(d=>d.pluginName===o.pluginName&&d.serial===o.serial)<0?(s&&console.warn(`handleCheckboxChange: device ${o.name} serial ${o.serial} not found in devices, trying in mixedDevices`),k(d=>{const u=d.findIndex(w=>w.pluginName===o.pluginName&&w.serial===o.serial);return u<0?(console.error(`handleCheckboxChange: device ${o.name} serial ${o.serial} not found in mixedDevices`),d):(d[u]={...d[u],selected:a.target.checked},[...d])})):f(d=>{const u=d.findIndex(w=>w.pluginName===o.pluginName&&w.serial===o.serial);return u<0?(console.error(`handleCheckboxChange: device ${o.name} serial ${o.serial} not found in devices`),d):(d[u]={...d[u],selected:a.target.checked},[...d])}),a.target.checked?n({id:R.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"selectdevice",plugin:o.pluginName,serial:o.serial,name:o.name}}):n({id:R.current,sender:"HomeDevices",method:"/api/command",src:"Frontend",dst:"Matterbridge",params:{command:"unselectdevice",plugin:o.pluginName,serial:o.serial,name:o.name}})};return s&&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(mt,{name:"Devices",getRowKey:an,rows:j,columns:O,footerLeft:P?"Waiting for the plugins to fully load...":`Registered devices: ${_.length.toString()}/${j.length.toString()}`,footerRight:t?"Restart required":""})}):e.jsx(Re,{})}const dn=r.memo(ln);function cn(){const[i,m]=r.useState(null),[c,n]=r.useState(null),[l,b]=r.useState([]),[g]=r.useState(localStorage.getItem("homePagePlugins")!=="false"),[t,x]=r.useState(localStorage.getItem("homePageMode")??"devices"),[P,p]=r.useState(""),[C,E]=r.useState(!1),[H,W]=r.useState(!1),[_,f]=r.useState(null),{addListener:X,removeListener:y,online:j,sendMessage:k,logFilterLevel:R,logFilterSearch:O,autoScroll:G,getUniqueId:v}=r.useContext(fe),a=r.useRef(v());return r.useEffect(()=>{const o=d=>{d.method==="refresh_required"&&d.response.changed==="settings"&&(console.log(`Home received refresh_required: changed=${d.response.changed} and sending /api/settings request`),f(null),b([]),k({id:a.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),k({id:a.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}})),d.method==="/api/settings"&&d.id===a.current&&(console.log("Home received settings:",d.response),m(d.response.systemInformation),n(d.response.matterbridgeInformation),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),W(!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),E(!0)),d.response.matterbridgeInformation.shellyBoard&&(localStorage.getItem("homePageMode")||(localStorage.setItem("homePageMode","devices"),x("devices")))),d.method==="/api/plugins"&&d.id===a.current&&(console.log("Home received plugins:",d.response),b(d.response))};return X(o,a.current),console.log(`Home added WebSocket listener id ${a.current}`),()=>{y(o),console.log("Home removed WebSocket listener")}},[X,y,k]),r.useEffect(()=>{if(console.log(`Home settings and plugins effect with storeId ${_}`),c?.bridgeMode==="bridge"&&!_&&(console.log(`Home set storeId from ${_} to Matterbridge`),f("Matterbridge")),c?.bridgeMode==="childbridge"&&!_&&l){for(const o of l)if(o.matter?.id){console.log(`Home set storeId from ${_} to ${o.matter.id}`),f(o.matter.id);break}}},[c,l,_]),r.useEffect(()=>{j&&(console.log("Home online effect, sending /api/settings and /api/plugins requests"),k({id:a.current,sender:"Home",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),k({id:a.current,sender:"Home",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}))},[j,k]),console.log("Home rendering..."),!j||!i||!c?e.jsx(Re,{}):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(Ko,{id:_}),e.jsx(Uo,{systemInfo:i,compact:!0})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%",gap:"20px"},children:[H&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"0 0 auto",width:"100%",overflow:"hidden"},children:[e.jsx("div",{className:"MbfWindowHeader",children:e.jsx("p",{className:"MbfWindowHeaderText",children:"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(oe,{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"})})]})]}),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(oe,{onClick:()=>window.open(P,"_blank"),endIcon:e.jsx(Et,{}),style:{color:"var(--main-button-color)",backgroundColor:"var(--main-button-bg-color)",height:"30px"},children:"Changelog"}),e.jsx(oe,{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(Go,{})]}),g&&e.jsx(sn,{storeId:_,setStoreId:f}),t==="devices"&&e.jsx(dn,{storeId:_,setStoreId:f}),t==="logs"&&e.jsxs("div",{className:"MbfWindowDiv",style:{flex:"1 1 auto",width:"100%",overflow:"hidden"},children:[e.jsxs("div",{className:"MbfWindowHeader",style:{height:"30px",minHeight:"30px",justifyContent:"space-between"},children:[e.jsx("p",{className:"MbfWindowHeaderText",children:"Logs"}),e.jsx("div",{className:"MbfWindowHeaderText",style:{display:"flex",justifyContent:"space-between"},children:e.jsxs("span",{style:{fontWeight:"normal",fontSize:"12px",marginTop:"2px"},children:['Filter: logger level "',R,'" and search "',O,'" Scroll: ',G?"auto":"manual"]})})]}),e.jsx("div",{style:{flex:"1 1 auto",margin:"0px",padding:"10px",overflow:"auto"},children:e.jsx(Bt,{})})]})]})]})}const pn=r.memo(cn),Ht={display:"flex",gap:"2px",justifyContent:"space-evenly",width:"100%",height:"40px"},un={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"},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"},hn={margin:"0",padding:"0",fontSize:"12px",fontWeight:"normal",color:"var(--div-text-color)"},fn={display:"flex",justifyContent:"center",width:"100%",height:"52px",margin:"0",padding:"0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"normal"},xn={margin:"0",padding:"0",fontSize:"14px",fontWeight:"bold",color:"var(--div-text-color)"},bn={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)"},vn=[256,257,268,269],yn=[266,267],jn=[259,260,261,271,272],Cn=[256,257,268,269,266,267,259,260,261,272];function q({icon:i,iconColor:m,cluster:c,value:n,unit:l,prefix:b}){return s&&console.log(`Render cluster "${c.clusterName}.${c.attributeName}" value(${typeof n}-${isNaN(n)}) "${n}" unit "${l}"`),b=b??!1,e.jsxs(Z,{sx:Ht,children:[i&&r.cloneElement(i,{key:`${c.clusterId}-${c.attributeId}-icon`,sx:{...un,color:m??"var(--primary-color)"}}),e.jsxs(Z,{sx:{...Ht,gap:"4px",alignContent:"center",alignItems:"end",justifyContent:"center"},children:[l&&b===!0&&e.jsx(ie,{sx:Ot,children:l},`${c.clusterId}-${c.attributeId}-unit`),e.jsx(ie,{sx:gn,children:n==null||typeof n=="number"&&isNaN(n)||n==="NaN"?"---":n},`${c.clusterId}-${c.attributeId}-value`),l&&b===!1&&e.jsx(ie,{sx:Ot,children:l},`${c.clusterId}-${c.attributeId}-unit`)]},`${c.clusterId}-${c.attributeId}-valueunitbox`)]},`${c.clusterId}-${c.attributeId}-box`)}function wn({device:i,endpoint:m,id:c,deviceType:n,clusters:l}){const b=["Unknown","Good","Fair","Moderate","Poor","VeryPoor","Ext.Poor"];let g="";return s&&console.log(`Device "${i.name}" endpoint "${m}" id "${c}" deviceType "0x${n.toString(16).padStart(4,"0")}" clusters (${l?.length}):`,l),n===17&&l.filter(t=>t.clusterName==="PowerSource"&&t.attributeName==="batVoltage").map(t=>g=`${t.attributeLocalValue} mV`),Cn.includes(n)&&l.filter(t=>t.clusterName==="LevelControl"&&t.attributeName==="currentLevel").map(t=>g=`Level ${t.attributeValue}`),n===514&&l.filter(t=>t.clusterName==="WindowCovering"&&t.attributeName==="currentPositionLiftPercent100ths").map(t=>g=`Position ${t.attributeLocalValue/100}%`),n===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedHeatingSetpoint").map(t=>g=`Heat ${t.attributeLocalValue/100}°C `),n===769&&l.filter(t=>t.clusterName==="Thermostat"&&t.attributeName==="occupiedCoolingSetpoint").map(t=>g=g+`Cool ${t.attributeLocalValue/100}°C`),n===118&&l.filter(t=>t.clusterName==="SmokeCoAlarm"&&t.attributeName==="coState").map(t=>g=`${t.attributeLocalValue===0?"No CO detected":"CO alarm!"}`),n===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="voltage").map(t=>g=`${t.attributeLocalValue/1e3} V, `),n===1296&&l.filter(t=>t.clusterName==="ElectricalPowerMeasurement"&&t.attributeName==="activeCurrent").map(t=>g=g+`${t.attributeLocalValue/1e3} A, `),n===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:[n===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"})),n===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:"%"})),n===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"})),n===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"})),vn.includes(n)&&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"})),yn.includes(n)&&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"})),jn.includes(n)&&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"})),n===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"})),n===124&&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"})),n===117&&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"})),n===123&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(Dt,{}),cluster:t,value:"Oven"})),n===112&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(Wr,{}),cluster:t,value:"Fridge"})),n===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})),n===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"})),n===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})),n===120&&l.filter(t=>t.clusterName==="BridgedDeviceBasicInformation"&&t.attributeName==="reachable").map(t=>e.jsx(q,{icon:e.jsx(re,{path:$t,size:"40px",color:"var(--primary-color)"}),cluster:t,value:"Cooktop"})),n===119&&l.filter(t=>t.clusterName==="TemperatureControl"&&t.attributeName==="selectedTemperatureLevel").map(t=>e.jsx(q,{icon:e.jsx(re,{path:$t,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue,unit:"mode",prefix:!0})),n===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"})),n===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:"%"})),n===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"})),n===10&&l.filter(t=>t.clusterName==="DoorLock"&&t.attributeName==="lockState").map(t=>e.jsx(q,{icon:t.attributeValue==="1"?e.jsx($r,{}):e.jsx(Fr,{}),cluster:t,value:t.attributeValue==="1"?"Locked":"Unlocked"})),n===43&&l.filter(t=>t.clusterName==="FanControl"&&t.attributeName==="percentCurrent").map(t=>e.jsx(q,{icon:e.jsx(Tr,{}),cluster:t,value:t.attributeValue,unit:"%"})),n===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})),n===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})),n===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"})),n===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:"%"})),n===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"})),n===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"})),n===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"})),n===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"})),n===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"})),n===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)+"%"})),n===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"})),n===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"})),n===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"})),n===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:Ft,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No smoke":"Smoke!"})),n===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:Ft,size:"40px",color:"var(--primary-color)"}),cluster:t,value:t.attributeLocalValue===0?"No Co":"Co!"})),n===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"})),n===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:b[t.attributeLocalValue??0]})),n===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"})),n===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:"%"})),n===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"})),n===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"})),n===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"})),n===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."})),n===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"})),n===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(Z,{sx:mn,children:e.jsx(ie,{sx:hn,children:g})}),e.jsx(Z,{sx:fn,children:e.jsx(ie,{sx:xn,children:i.name})}),e.jsxs(Z,{sx:bn,children:[s&&e.jsx(ie,{sx:bt,children:m}),e.jsx(ie,{sx:bt,children:c}),s&&e.jsxs(ie,{sx:bt,children:["0x",n.toString(16).padStart(4,"0")]})]})]})}function Sn({filter:i}){const{online:m,sendMessage:c,addListener:n,removeListener:l,getUniqueId:b}=r.useContext(fe),[g,t]=r.useState(null),[x,P]=r.useState([]),[p,C]=r.useState([]),[E,H]=r.useState(p),[W,_]=r.useState({}),[f,X]=r.useState({}),[y,j]=r.useState({}),k=r.useRef(b()),R=r.useRef(E),O=r.useCallback(v=>{console.log(`DevicesIcons received state_update "${v.response.cluster}.${v.response.attribute}" for "${v.response.id}:${v.response.number}": "${v.response.value}"`,v.response);const a=R.current.find(d=>d.pluginName===v.response.plugin&&d.uniqueId===v.response.uniqueId);if(!a){console.warn(`DevicesIcons updater device of plugin "${v.response.plugin}" serial "${v.response.serialNumber}" not found in filteredDevicesRef.current`);return}const o=y[a.serial].find(d=>d.endpoint===v.response.number.toString()&&d.clusterName===v.response.cluster&&d.attributeName===v.response.attribute);if(!o){console.warn(`DevicesIcons updater device "${a.name}" serial "${a.serial}" cluster "${v.response.cluster}" attribute "${v.response.attribute}" not found in clusters`);return}o.attributeValue=String(v.response.value),o.attributeLocalValue=v.response.value,j({...y}),console.log(`DevicesIcons updated "${o.clusterName}.${o.attributeName}" for device "${a.name}" serial "${a.serial}" to "${o.attributeValue}"`)},[y]);r.useEffect(()=>{const v=a=>{if(a.method==="refresh_required")s&&console.log(`DevicesIcons received refresh_required: changed=${a.response.changed} and sending api requests`),c({id:k.current,sender:"Icons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"Icons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"Icons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}});else if(a.method==="state_update"&&a.response)O(a);else if(a.method==="/api/settings"&&a.response)s&&console.log("DevicesIcons received settings:",a.response),t(a.response);else if(a.method==="/api/plugins"&&a.response)s&&console.log("DevicesIcons received plugins:",a.response),P(a.response);else if(a.method==="/api/devices"&&a.response){s&&console.log(`DevicesIcons received ${a.response.length} devices:`,a.response),C(a.response);for(const o of a.response)s&&console.log("DevicesIcons sending /api/clusters"),c({id:k.current,sender:"DevicesIcons",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:o.pluginName,endpoint:o.endpoint||0}})}else if(a.method==="/api/clusters"&&a.response){if(s&&console.log(`DevicesIcons received for device "${a.response.deviceName}" serial "${a.response.serialNumber}" deviceTypes (${a.response.deviceTypes.length}) "${a.response.deviceTypes.join(",")}" clusters (${a.response.clusters.length}):`,a.response),a.response.clusters.length===0)return;const o=a.response.serialNumber;W[o]=[],f[o]=a.response.deviceTypes,y[o]=[];for(const d of a.response.clusters)W[o].find(u=>u.endpoint===d.endpoint)||W[o].push({endpoint:d.endpoint,id:d.id,deviceTypes:d.deviceTypes}),!["FixedLabel","Descriptor","Identify","Groups","PowerTopology"].includes(d.clusterName)&&y[o].push(d);_({...W}),X({...f}),j({...y}),s&&console.log(`DevicesIcons endpoints for "${o}":`,W[o]),s&&console.log(`DevicesIcons deviceTypes for "${o}":`,f[o]),s&&console.log(`DevicesIcons clusters for "${o}":`,y[o])}};return n(v,k.current),s&&console.log("DevicesIcons useEffect webSocket mounted"),()=>{l(v),s&&console.log("DevicesIcons useEffect webSocket unmounted")}},[]),r.useEffect(()=>(s&&console.log("DevicesIcons useEffect online mounting"),m&&(s&&console.log("DevicesIcons useEffect online sending api requests"),c({id:k.current,sender:"DevicesIcons",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"DevicesIcons",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:k.current,sender:"DevicesIcons",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}})),s&&console.log("DevicesIcons useEffect online mounted"),()=>{s&&console.log("DevicesIcons useEffect online unmounted")}),[m,c]),r.useEffect(()=>{if(i===""){H(p),R.current=p;return}const v=p.filter(a=>a.name.toLowerCase().includes(i)||a.serial.toLowerCase().includes(i));H(v),R.current=v},[p,i]);const G=r.memo(wn);return s&&console.log("DevicesIcons rendering..."),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",paddingBottom:"5px",gap:"20px",width:"100%",overflow:"auto"},children:E.map(v=>W[v.serial]&&W[v.serial].map(a=>a.deviceTypes.map(o=>e.jsx(G,{device:v,endpoint:a.endpoint,id:a.id,deviceType:o,clusters:y[v.serial].filter(d=>d.endpoint===a.endpoint)},`${v.pluginName}-${v.uniqueId}-${a.id}-${o.toString()}`))))})}const Mn=r.memo(Sn),kn=[{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,m,c,n)=>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"}],In=[{label:"Endpoint",id:"endpoint",required:!0},{label:"Id",id:"id"},{label:"Device Types",id:"deviceTypes",render:(i,m,c,n)=>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,m,c,n)=>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)})})}],Dn=i=>`${i.pluginName}::${i.uniqueId}`,Nn=i=>`${i.endpoint}::${i.clusterName}::${i.attributeName}`;function Pn({filter:i}){const{online:m,sendMessage:c,addListener:n,removeListener:l,getUniqueId:b}=r.useContext(fe),[g,t]=r.useState([]),[x,P]=r.useState(g),[p,C]=r.useState([]),[E,H]=r.useState(0),[W,_]=r.useState(null),[f,X]=r.useState(null),[y,j]=r.useState(null),[k,R]=r.useState(null),O=r.useRef(b()),G=r.useRef(x),v=r.useCallback(o=>{console.log(`DevicesTable received state_update "${o.response.cluster}.${o.response.attribute}" for "${o.response.id}:${o.response.number}": "${o.response.value}"`,o.response);const d=G.current.find(u=>u.pluginName===o.response.plugin&&u.uniqueId===o.response.uniqueId);if(!d){console.warn(`DevicesTable updater device of plugin "${o.response.plugin}" serial "${o.response.serialNumber}" not found in filteredDevicesRef.current`);return}if(W&&f&&d.pluginName===W&&d.uniqueId===k&&o.response.number.toString()===f){const u=p.find(w=>w.endpoint===o.response.number.toString()&&w.clusterName===o.response.cluster&&w.attributeName===o.response.attribute);if(!u){console.warn(`DevicesTable updater cluster ${o.response.cluster}.${o.response.attribute} for device "${d.name}" serial "${d.serial}" not found in clusters`);return}u.attributeValue=String(o.response.value),u.attributeLocalValue=o.response.value,C([...p]),console.log(`DevicesTable updated attribute ${u.clusterName}.${u.attributeName} for device "${d.name}" serial "${d.serial}" to "${u.attributeValue}"`)}},[p,f,W,k]);r.useEffect(()=>{const o=d=>{if(s&&console.log("DevicesTable received WebSocket Message:",d),d.method==="refresh_required"&&d.response.changed==="devices")s&&console.log(`DevicesTable received refresh_required: changed=${d.response.changed} and sending /api/devices request`),c({id:O.current,sender:"DevicesTable",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}});else if(d.method==="state_update"&&d.response)v(d);else if(d.method==="/api/devices")s&&console.log(`DevicesTable received ${d.response.length} devices:`,d.response),t(d.response);else if(d.method==="/api/clusters"){s&&console.log(`DevicesTable received ${d.response.clusters.length} clusters for plugin ${d.response.plugin}:`,d.response),C(d.response.clusters);const u={};for(const w of d.response.clusters)s&&console.log("Cluster:",w.endpoint),u[w.endpoint]?u[w.endpoint]++:u[w.endpoint]=1;H(Object.keys(u).length)}};return n(o,O.current),s&&console.log("DevicesTable added WebSocket listener"),()=>{l(o),s&&console.log("DevicesTable removed WebSocket listener")}},[c,n,l,v]),r.useEffect(()=>{m&&(s&&console.log("DevicesTable sending api requests with id ",O.current),c({id:O.current,sender:"DevicesTable",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:O.current,sender:"DevicesTable",method:"/api/plugins",src:"Frontend",dst:"Matterbridge",params:{}}),c({id:O.current,sender:"DevicesTable",method:"/api/devices",src:"Frontend",dst:"Matterbridge",params:{}}))},[m,c]),r.useEffect(()=>{W&&f&&(s&&console.log("DevicesTable sending /api/clusters"),c({id:O.current,sender:"DevicesTable",method:"/api/clusters",src:"Frontend",dst:"Matterbridge",params:{plugin:W,endpoint:Number(f)}}))},[W,f,c]),r.useEffect(()=>{if(i===""){P(g),G.current=g;return}const o=g.filter(d=>d.name.toLowerCase().includes(i)||d.serial.toLowerCase().includes(i));P(o),G.current=o},[g,i]);const a=o=>{if(o.uniqueId===k){R(null),_(null),X(null),j(null);return}R(o.uniqueId),_(o.pluginName),X(o.endpoint?o.endpoint.toString():null),j(o.name)};return s&&console.log("DevicesTable rendering..."),m?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:`${W&&f?"50%":"100%"}`,width:"100%",flex:"1 1 auto",overflow:"hidden"},children:e.jsx(mt,{name:"Registered devices",getRowKey:Dn,onRowClick:a,rows:x,columns:kn,footerLeft:`Total devices: ${x.length.toString()}`})}),W&&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(mt,{name:"Clusters",title:y||"",getRowKey:Nn,rows:p,columns:In,footerLeft:`Total child endpoints: ${E-1}`})})]}):e.jsx(Re,{})}const Wn=r.memo(Pn);function Ln(){const{online:i}=r.useContext(fe),[m,c]=r.useState(""),[n,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 b=t=>{c(t.target.value.toLowerCase()),localStorage.setItem("devicesFilter",t.target.value.toLowerCase())},g=t=>{l(t),localStorage.setItem("devicesViewMode",t)};return s&&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(Z,{sx:{display:"flex",flexDirection:"row",alignItems:"center",gap:"10px"},children:[e.jsx(ie,{sx:{fontSize:"16px",fontWeight:"normal",color:"var(--div-text-color)",marginLeft:"5px",whiteSpace:"nowrap"},children:"Filter by:"}),e.jsx(pe,{variant:"outlined",value:m,onChange:b,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(ie,{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:n==="table",children:e.jsx(T,{title:"Table View",children:e.jsx(Yr,{style:{color:n==="table"?"var(--main-icon-color)":"var(--primary-color)"}})})}),e.jsx(Q,{onClick:()=>g("icon"),"aria-label":"Icon View",disabled:n==="icon",children:e.jsx(T,{title:"Icon View (beta)",children:e.jsx(Xr,{style:{color:n==="icon"?"var(--main-icon-color)":"var(--primary-color)"}})})})]})]}),n==="table"&&e.jsx(Wn,{filter:m}),n==="icon"&&e.jsx(Mn,{filter:m})]}):e.jsx(Re,{})}const $n=r.memo(Ln);function Fn(){const[i,m]=r.useState(localStorage.getItem("logFilterLevel")??"info"),[c,n]=r.useState(localStorage.getItem("logFilterSearch")??"*"),[l,b]=r.useState(localStorage.getItem("logAutoScroll")!=="false"),{setMessages:g,setLogFilters:t,online:x,setAutoScroll:P}=r.useContext(fe),p=W=>{m(W.target.value),t(W.target.value,c),localStorage.setItem("logFilterLevel",W.target.value),s&&console.log("handleChangeLevel called with value:",W.target.value)},C=W=>{n(W.target.value),t(i,W.target.value),localStorage.setItem("logFilterSearch",W.target.value),s&&console.log("handleChangeSearch called with value:",W.target.value)},E=W=>{b(W.target.checked),P(W.target.checked),localStorage.setItem("logAutoScroll",W.target.value?"true":"false"),s&&console.log("handleAutoScrollChange called with value:",W.target.checked)},H=()=>{s&&console.log("handleClearLogsClick called"),g([])};return s&&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(D,{value:"debug",children:"Debug"}),e.jsx(D,{value:"info",children:"Info"}),e.jsx(D,{value:"notice",children:"Notice"}),e.jsx(D,{value:"warn",children:"Warn"}),e.jsx(D,{value:"error",children:"Error"}),e.jsx(D,{value:"fatal",children:"Fatal"})]}),e.jsx(Pt,{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:c,onChange:C,InputProps:{style:{height:"30px",padding:"0 0px",backgroundColor:"var(--main-bg-color)"}}}),e.jsx(Fe,{control:e.jsx(Te,{checked:l,onChange:E}),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(oe,{onClick:H,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(Re,{})}const Tn=r.memo(Fn),Rn=({open:i,ip:m,onClose:c,onSave:n})=>{const l=m?m.split(".").slice(0,3).join(".")+".1":"",[b,g]=r.useState("dhcp"),[t,x]=r.useState({ip:m??"",subnet:"255.255.255.0",gateway:l,dns:l}),P=E=>H=>{x({...t,[E]:H.target.value})},p=()=>{c()},C=()=>{n({type:b,...t}),c()};return e.jsxs(Me,{open:i,onClose:(E,H)=>{H==="backdropClick"||H==="escapeKeyDown"||c()},maxWidth:"sm",style:{maxWidth:"550px",margin:"auto"},children:[e.jsx(ke,{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(Ie,{dividers:!0,children:[e.jsxs(qt,{component:"fieldset",fullWidth:!0,children:[e.jsx(Ce,{component:"legend",children:"Select IP Configuration"}),e.jsxs(zt,{row:!0,value:b,onChange:E=>g(E.target.value),children:[e.jsx(Fe,{value:"dhcp",control:e.jsx(gt,{}),label:"DHCP"}),e.jsx(Fe,{value:"static",control:e.jsx(gt,{}),label:"Static"})]})]}),b==="static"&&e.jsxs(Le,{container:!0,spacing:2,sx:{mt:2},children:[e.jsx(Le,{size:6,children:e.jsx(pe,{label:"IP Address",fullWidth:!0,value:t.ip,onChange:P("ip")})}),e.jsx(Le,{size:6,children:e.jsx(pe,{label:"Subnet Mask",fullWidth:!0,value:t.subnet,onChange:P("subnet")})}),e.jsx(Le,{size:6,children:e.jsx(pe,{label:"Gateway",fullWidth:!0,value:t.gateway,onChange:P("gateway")})}),e.jsx(Le,{size:6,children:e.jsx(pe,{label:"DNS Server",fullWidth:!0,value:t.dns,onChange:P("dns")})})]})]}),e.jsxs($e,{children:[e.jsx(oe,{onClick:p,children:"Cancel"}),e.jsx(oe,{variant:"contained",onClick:C,children:"Save"})]})]})},Hn=({open:i,onClose:m,onSave:c})=>{const[n,l]=r.useState(""),[b,g]=r.useState(""),t=H=>{l(H.target.value)},x=H=>{g(H.target.value)},P=n.length>0&&n===b,p=()=>{m()},C=()=>{P&&(c(n),m())},E=()=>{c(""),m()};return e.jsxs(Me,{open:i,onClose:(H,W)=>{W==="backdropClick"||W==="escapeKeyDown"||m()},maxWidth:"sm",style:{maxWidth:"500px",margin:"auto"},disableEscapeKeyDown:!0,children:[e.jsx(ke,{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(Ie,{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(pe,{type:"password",autoComplete:"new-password",label:"New Password",size:"small",variant:"outlined",fullWidth:!0,value:n,onChange:t})}),e.jsx(Le,{size:12,children:e.jsx(pe,{type:"password",autoComplete:"new-password",label:"Confirm Password",size:"small",variant:"outlined",fullWidth:!0,value:b,onChange:x,error:b!==""&&n!==b,helperText:b!==""&&n!==b?"Passwords do not match":""})})]})})}),e.jsxs($e,{children:[e.jsx(oe,{onClick:p,children:"Cancel"}),e.jsx(oe,{variant:"contained",onClick:C,disabled:!P,children:"Change"}),e.jsx(oe,{variant:"contained",onClick:E,children:"Reset"})]})]})};function On(){const{online:i,addListener:m,removeListener:c,sendMessage:n,getUniqueId:l}=r.useContext(fe),[b,g]=r.useState(null),[t,x]=r.useState(null),P=r.useRef(l());return r.useEffect(()=>{const p=C=>{C.src==="Matterbridge"&&C.dst==="Frontend"&&(C.method==="refresh_required"&&C.response.changed==="settings"&&(s&&console.log(`Settings received refresh_required: changed=${C.response.changed} and sending /api/settings request`),n({id:P.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}})),C.method==="/api/settings"&&(s&&console.log("Settings received /api/settings:",C.response),g(C.response.matterbridgeInformation),x(C.response.systemInformation)))};return m(p,P.current),s&&console.log("Settings added WebSocket listener"),()=>{c(p),s&&console.log("Settings removed WebSocket listener")}},[m,c,n]),r.useEffect(()=>{i&&(s&&console.log("Settings received online"),n({id:P.current,sender:"Settings",method:"/api/settings",src:"Frontend",dst:"Matterbridge",params:{}}))},[i,n]),b?(s&&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(Vn,{matterbridgeInfo:b,systemInfo:t}),e.jsx(En,{matterbridgeInfo:b}),e.jsx(An,{matterbridgeInfo:b})]})}):e.jsx(Re,{})):null}function Vn({matterbridgeInfo:i,systemInfo:m}){const{sendMessage:c,getUniqueId:n}=r.useContext(fe),[l,b]=r.useState("bridge"),[g,t]=r.useState("Info"),[x,P]=r.useState(!1),[p,C]=r.useState("dark"),[E,H]=r.useState(localStorage.getItem("homePagePlugins")!=="false"),[W,_]=r.useState(localStorage.getItem("homePageMode")??"devices"),[f,X]=r.useState(localStorage.getItem("virtualMode")??"outlet"),y=r.useRef(n()),[j,k]=r.useState(!1),R=()=>k(!1),O=ee=>{s&&console.log("handleSaveNetConfig called with config:",ee),c({id:y.current,sender:"Settings",method:"/api/shellynetconfig",src:"Frontend",dst:"Matterbridge",params:ee})},[G,v]=r.useState(!1),a=()=>v(!1),o=ee=>{s&&console.log("handleSaveChangePassword called with password:",ee),c({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setpassword",value:ee}})};r.useEffect(()=>{i&&(b(i.bridgeMode==="bridge"?"bridge":"childbridge"),t(i.loggerLevel.charAt(0).toUpperCase()+i.loggerLevel.slice(1)),P(i.fileLogger),X(i.virtualMode))},[i]),r.useEffect(()=>{const ee=localStorage.getItem("frontendTheme");ee&&C(ee)},[]);const d=ee=>{s&&console.log("handleChangeBridgeMode called with value:",ee.target.value),b(ee.target.value),c({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setbridgemode",value:ee.target.value}})},u=ee=>{s&&console.log("handleChangeMbLoggerLevel called with value:",ee.target.value),t(ee.target.value),c({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmbloglevel",value:ee.target.value}})},w=ee=>{s&&console.log("handleLogOnFileMbChange called with value:",ee.target.checked),P(ee.target.checked),c({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmblogfile",value:ee.target.checked}})},V=ee=>{const se=ee.target.value;s&&console.log("handleChangeTheme called with value:",se),C(se),localStorage.setItem("frontendTheme",se),document.body.setAttribute("frontend-theme",se)},ge=ee=>{const se=ee.target.checked;s&&console.log("handleChangeHomePagePlugins called with value:",se),H(se),localStorage.setItem("homePagePlugins",se?"true":"false")},me=ee=>{const se=ee.target.value;s&&console.log("handleChangeHomePageMode called with value:",se),_(se),localStorage.setItem("homePageMode",se)},xe=ee=>{const se=ee.target.value;s&&console.log("handleChangeVirtualMode called with value:",se),X(se),localStorage.setItem("virtualMode",se),c({id:y.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setvirtualmode",value:se}})};return!i||!m?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(Rn,{open:j,ip:m.ipv4Address,onClose:R,onSave:O}),e.jsx(Hn,{open:G,onClose:a,onSave:o}),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(Ce,{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(gt,{}),label:"Bridge",disabled:i.readOnly===!0}),e.jsx(Fe,{value:"childbridge",control:e.jsx(gt,{}),label:"Childbridge",disabled:i.readOnly===!0})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ce,{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:u,children:[e.jsx(D,{value:"Debug",children:"Debug"}),e.jsx(D,{value:"Info",children:"Info"}),e.jsx(D,{value:"Notice",children:"Notice"}),e.jsx(D,{value:"Warn",children:"Warn"}),e.jsx(D,{value:"Error",children:"Error"}),e.jsx(D,{value:"Fatal",children:"Fatal"})]}),e.jsx(Fe,{style:{padding:"0px",margin:"0px"},control:e.jsx(Te,{checked:x,onChange:w,name:"logOnFileMb"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ce,{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:V,children:[e.jsx(D,{value:"classic",children:"Classic"}),e.jsx(D,{value:"light",children:"Light"}),e.jsx(D,{value:"dark",children:"Dark"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ce,{style:{padding:"0px",margin:"0px"},id:"frontend-home-plugin-label",children:"Home page plugins:"}),e.jsx(Te,{checked:E,onChange:ge,name:"showPlugins"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"5px"},children:[e.jsx(Ce,{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:W,onChange:me,children:[e.jsx(D,{value:"logs",children:"Logs"}),e.jsx(D,{value:"devices",children:"Devices"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"10px"},children:[e.jsx(Ce,{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:f,onChange:xe,children:[e.jsx(D,{value:"disabled",children:"Disabled"}),e.jsx(D,{value:"outlet",children:"Outlet"}),e.jsx(D,{value:"light",children:"Light"}),e.jsx(D,{value:"switch",children:"Switch"}),e.jsx(D,{value:"mounted_switch",children:"Mounted Switch"})]})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(oe,{variant:"contained",color:"primary",onClick:()=>v(!0),children:"Change password"})}),i.shellyBoard&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"15px",marginTop:"20px"},children:e.jsx(oe,{variant:"contained",color:"primary",onClick:()=>k(!0),children:"Configure IP"})})]})})]})}function En({matterbridgeInfo:i}){const{sendMessage:m,getUniqueId:c}=r.useContext(fe),[n,l]=r.useState("Info"),[b,g]=r.useState(!1),[t,x]=r.useState(""),[P,p]=r.useState(""),[C,E]=r.useState(""),[H,W]=r.useState(""),[_,f]=r.useState(""),[X,y]=r.useState(""),j=r.useRef(c());r.useEffect(()=>{i&&(l(["Debug","Info","Notice","Warn","Error","Fatal"][i.matterLoggerLevel]),g(i.matterFileLogger),x(i.matterMdnsInterface||""),p(i.matterIpv4Address||""),E(i.matterIpv6Address||""),W(i.matterPort?i.matterPort.toString():""),f(i.matterDiscriminator?i.matterDiscriminator.toString():""),y(i.matterPasscode?i.matterPasscode.toString():""))},[i]);const k=u=>{s&&console.log("handleChangeMjLoggerLevel called with value:",u.target.value),l(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjloglevel",value:u.target.value}})},R=u=>{s&&console.log("handleLogOnFileMjChange called with value:",u.target.checked),g(u.target.checked),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmjlogfile",value:u.target.checked}})},O=u=>{s&&console.log("handleChangeMdnsInterface called with value:",u.target.value),x(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmdnsinterface",value:u.target.value}})},G=u=>{s&&console.log("handleChangeIpv4Address called with value:",u.target.value),p(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv4address",value:u.target.value}})},v=u=>{s&&console.log("handleChangeIpv6Address called with value:",u.target.value),E(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setipv6address",value:u.target.value}})},a=u=>{s&&console.log("handleChangeMatterPort called with value:",u.target.value),W(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterport",value:u.target.value}})},o=u=>{s&&console.log("handleChangeMatterDiscriminator called with value:",u.target.value),f(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterdiscriminator",value:u.target.value}})},d=u=>{s&&console.log("handleChangemMatterPasscode called with value:",u.target.value),y(u.target.value),m({id:j.current,sender:"Settings",method:"/api/config",src:"Frontend",dst:"Matterbridge",params:{name:"setmatterpasscode",value:u.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(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(Ce,{style:{padding:"0px",margin:"0px"},id:"mjdebug-info",children:"Logger level:"}),e.jsxs(Ue,{style:{height:"30px"},labelId:"select-mjlevel",id:"mjdebug-level",value:n,onChange:k,children:[e.jsx(D,{value:"Debug",children:"Debug"}),e.jsx(D,{value:"Info",children:"Info"}),e.jsx(D,{value:"Notice",children:"Notice"}),e.jsx(D,{value:"Warn",children:"Warn"}),e.jsx(D,{value:"Error",children:"Error"}),e.jsx(D,{value:"Fatal",children:"Fatal"})]}),e.jsx(Fe,{style:{padding:"0px",margin:"0px"},control:e.jsx(Te,{checked:b,onChange:R,name:"logOnFileMj"}),label:"Log on file:",labelPlacement:"start"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"15px"},children:[e.jsx(Ce,{style:{padding:"0px",margin:"0px"},children:"Mdns interface:"}),e.jsx(pe,{value:t,onChange:O,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(Ce,{style:{padding:"0px",margin:"0px"},children:"Ipv4 address:"}),e.jsx(pe,{value:P,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(Ce,{style:{padding:"0px",margin:"0px"},children:"Ipv6 address:"}),e.jsx(pe,{value:C,onChange:v,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(Ce,{style:{padding:"0px",margin:"0px"},children:"Commissioning port:"}),e.jsx(pe,{value:H,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(Ce,{style:{padding:"0px",margin:"0px"},children:"Commissioning discriminator:"}),e.jsx(pe,{value:_,onChange:o,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(Ce,{style:{padding:"0px",margin:"0px"},children:"Commissioning passcode:"}),e.jsx(pe,{value:X,onChange:d,size:"small",variant:"outlined",style:{height:"30px",flexGrow:1},InputProps:{readOnly:i.readOnly===!0,style:{height:"30px",padding:"0"}}})]})]})})]}):null}function An({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(Z,{sx:{gap:"10px",margin:"0px",padding:"10px",width:"400px",backgroundColor:"var(--div-bg-color)",color:"var(--div-text-color)"},children:[" ",e.jsx(Oe,{value:i.matterbridgeVersion,label:"Current Version"}),e.jsx(Oe,{value:i.matterbridgeLatestVersion,label:"Latest Version"}),e.jsx(Oe,{value:i.homeDirectory,label:"Home Directory"}),e.jsx(Oe,{value:i.rootDirectory,label:"Root Directory"}),e.jsx(Oe,{value:i.matterbridgeDirectory,label:"Matterbridge Storage Directory"}),e.jsx(Oe,{value:i.matterbridgePluginDirectory,label:"Matterbridge Plugin Directory"}),e.jsx(Oe,{value:i.globalModulesDirectory,label:"Global Module Directory"})]})})]}):null}function Oe({value:i,label:m}){return e.jsx(pe,{focused:!0,value:i,size:"small",label:m,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 _n=r.memo(On);function qn(){const{online:i,sendMessage:m,addListener:c,removeListener:n,getUniqueId:l}=r.useContext(fe),{showSnackbarMessage:b,showInstallProgress:g,addInstallProgress:t}=r.useContext(Be),[x,P]=r.useState(null),[p,C]=r.useState([]),[E,H]=r.useState([]),[W,_]=r.useState(null),[f,X]=r.useState({cpuUsage:0}),[y,j]=r.useState({totalMemory:"",freeMemory:"",heapTotal:"",heapUsed:"",external:"",arrayBuffers:"",rss:""}),[k,R]=r.useState({systemUptime:"",processUptime:""}),O=r.useRef(l());return console.log("Test uniqueId:",O),r.useEffect(()=>{console.log("Test useEffect WebSocketMessage mounting");const G=v=>{if(v.method==="restart_required")console.log("Test received restart_required"),b("Restart required",0);else if(v.method==="refresh_required")console.log(`Test received refresh_required: changed=${v.response.changed} and sending api requests`),b("Refresh required",0),m({id:O.current,method:"/api/settings",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),m({id:O.current,method:"/api/plugins",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}}),m({id:O.current,method:"/api/devices",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{}});else if(v.method==="memory_update")console.log("Test received memory_update",v),j(v.response);else if(v.method==="cpu_update")console.log("Test received cpu_update",v),X(v.response);else if(v.method==="uptime_update")console.log("Test received uptime_update",v),R(v.response);else if(v.method==="/api/settings"&&v.response)console.log("Test received /api/settings:",v.response),b("Test received /api/settings",0),P(v.response);else if(v.method==="/api/plugins"&&v.response)console.log(`Test received ${v.response.length} plugins:`,v.response),b("Test received /api/plugins",0),C(v.response);else if(v.method==="/api/devices"&&v.response){console.log(`Test received ${v.response.length} devices:`,v.response),b("Test received /api/devices",0),H(v.response);for(const a of v.response)console.log("Test sending /api/clusters for device:",a.pluginName,a.name,a.endpoint),m({id:O.current,method:"/api/clusters",sender:"Test",src:"Frontend",dst:"Matterbridge",params:{plugin:a.pluginName,endpoint:a.endpoint||0}})}else v.method==="/api/clusters"&&v.response&&(console.log(`Test received ${v.response.clusters.length} clusters for device ${v.response.deviceName} endpoint ${v.response.id}:${v.response.number}:`,v),b(`Test received /api/clusters for ${v.response.plugin}::${v.response.deviceName}`,0),_(v.response))};return c(G,O.current),console.log("Test useEffect WebSocketMessage mounted"),()=>{console.log("Test useEffect WebSocketMessage unmounting"),n(G),console.log("Test useEffect WebSocketMessage unmounted")}},[c,n,m,b]),r.useEffect(()=>(console.log("Test useEffect online mounting"),i&&console.log("Test useEffect online received online"),console.log("Test useEffect online mounted"),()=>{console.log("Test useEffect online unmounted")}),[i,m,b]),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(oe,{variant:"contained",onClick:()=>{g("example-package"),t("Starting installation...");for(const G of["Downloading package...","Extracting files...","Installing dependencies..."])t(G);for(let G=0;G<=500;G+=1)t(`Installing dependency package-dep${G}...`);t("Finalizing installation..."),t("Installation completed successfully.")},children:"Install"})]})}):e.jsx(Re,{})}const zn=r.memo(qn);function Un(i,m){s&&console.log("getCssVariable:",i,"defaultValue",m);const c=getComputedStyle(document.body).getPropertyValue(i).trim();return c||console.error("getCssVariable: undefined",c),c||m}function Bn(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 s=!1;const Qn=()=>{s=!s};function Kn({setLoggedIn:i}){const[m,c]=r.useState(""),[n,l]=r.useState(""),b={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 C=await fetch("./api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:p})});if(C.ok){const{valid:E}=await C.json();E?i(!0):p!==""&&l("Incorrect password!")}else console.error("Failed to log in:",C.statusText)}catch(C){console.error("Failed to log in:",C)}},P=p=>{p.preventDefault(),x(m)};return x(""),e.jsx("div",{style:b,children:e.jsxs("form",{onSubmit:P,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:m,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:n&&e.jsx("p",{style:{color:"red"},children:n})})]})})}function Jn(){const[i,m]=r.useState(!1);s&&console.log("Setting frontend theme");const c=localStorage.getItem("frontendTheme");s&&console.log("Saved theme:",c),c?document.body.setAttribute("frontend-theme",c):document.body.setAttribute("frontend-theme","dark");const n=Un("--primary-color","#1976d2");s&&console.log("Primary color from CSS:",n);const l=Bn(n),b=window.location.pathname.includes("/matterbridge/")?"/matterbridge":window.location.href.includes("/api/hassio_ingress/")?window.location.pathname:"/";return s&&(console.log("Loading App..."),console.log(`- with href = "${window.location.href}"`),console.log(`- pathname = "${window.location.pathname}"`),console.log(`- baseName = "${b}"`)),i?e.jsx(eo,{theme:l,children:e.jsx(cr,{dense:!0,maxSnack:10,preventDuplicate:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Ho,{children:e.jsx(Oo,{children:e.jsx(nr,{basename:b,children:e.jsxs("div",{className:"MbfScreen",children:[e.jsx(Eo,{}),e.jsxs(ir,{children:[e.jsx(Ve,{path:"/",element:e.jsx(pn,{})}),e.jsx(Ve,{path:"/devices",element:e.jsx($n,{})}),e.jsx(Ve,{path:"/log",element:e.jsx(Tn,{})}),e.jsx(Ve,{path:"/settings",element:e.jsx(_n,{})}),e.jsx(Ve,{path:"/test",element:e.jsx(zn,{})}),e.jsx(Ve,{path:"*",element:e.jsx(sr,{to:"/"})})]})]})})})})})}):e.jsx(Kn,{setLoggedIn:m})}ar.createRoot(document.getElementById("root")).render(e.jsx(lr.StrictMode,{children:e.jsx(Jn,{})}));
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge",
3
- "version": "3.2.9-dev-20250924-c639a33",
3
+ "version": "3.2.9-dev-20250926-85736bb",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge",
9
- "version": "3.2.9-dev-20250924-c639a33",
9
+ "version": "3.2.9-dev-20250926-85736bb",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@matter/main": "0.15.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge",
3
- "version": "3.2.9-dev-20250924-c639a33",
3
+ "version": "3.2.9-dev-20250926-85736bb",
4
4
  "description": "Matterbridge plugin manager for Matter",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",