var b=Object.defineProperty;var p=(e,t,s)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var n=(e,t,s)=>(p(e,typeof t!="symbol"?t+"":t,s),s);import{M as c,G as h,c as d}from"./index-b983ad9b.js";import{r as f}from"./react-b0e0d18a.js";const m=new Map;class a{constructor(t){n(this,"_subscribers",{});this.measurementData={},this.setData(t)}setData(t){Object.assign(this,t)}static async findAll(t,s){const r=c(),{items:i}=await r.get({path:"api/v1/devices",query:{...t}});return(i||[]).map(u=>a.get(u))}static async findAndCountAll(t,s){const r=c(),{items:i,...u}=await r.get({path:"api/v1/devices",query:{...t}});return{...u,items:(i||[]).map(o=>a.get(o))}}static async findByUuid(t,s){const i=await c().get({path:`api/v1/device/${s}`,query:{...t}});return a.get(i)}static get(t){let s=m.get(t.id);return s?s.setData(t):(s=new a(t),m.set(s.id,s)),s}addMeasurementData(t,s){this.measurementData[t]=s,this.$publish("measurement",t,s)}mute(){return h().patch(`api/v1/device/${this.id}/state`,{mute:!0})}$subscribe(t,s){return this._subscribers[t]||(this._subscribers[t]=[]),this._subscribers[t].push(s),()=>{this._subscribers[t]=this._subscribers[t].filter(r=>r!==s)}}$publish(t,...s){var r;(r=this._subscribers[t])==null||r.forEach(i=>i(...s))}}function y(e){const t=d();return f.useEffect(()=>e.$subscribe("measurement",()=>t()),[e]),e.measurementData}const D=a;export{D,y as u};
