import{a as d,j as t,u as g}from"./index-b983ad9b.js";import{r as u}from"./react-b0e0d18a.js";import{u as N,D as b}from"./Device-e8d48614.js";/* empty css                *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              */import{e as x}from"./KB-757eebe4.js";import{A as M,i as C,j as h,m as y,B as D,z as j}from"./antd-8ca2e36c.js";import{u as k}from"./Messenger-5d5560db.js";const S="_device-card_9l9yf_1",T={deviceCard:S};function A({name:e,measurement:r}){const[s,o]=u.useState(e);if(u.useEffect(()=>{if(!e)return;let a=!0;const[l,i]=e.split("/");return x(l).then(c=>{let p=(c==null?void 0:c.title)||l;i!==void 0&&(p+=`/${i}`),a&&o(p)}).catch(()=>{a&&o("未知")}),()=>{a=!1}},[e]),!s)return null;const{value:m,unit:f}=r;return d("div",{className:"measurement",children:[t("span",{className:"title",children:s}),t("span",{className:"value",children:typeof m=="boolean"?m?"ON":"OFF":`${m||"--"}`}),f&&t("span",{className:"unit",children:f})]})}function E({device:e}){const[r,s]=u.useState(!1);return t(C,{title:d(h,{children:[t(h.Title,{level:5,children:"您确定进行此操作吗"}),t(h.Paragraph,{children:"报警用于现场安全警示，请务必在现场状况被确认无误后再进行操作。"})]}),onConfirm:async()=>{s(!0);try{await e.mute(),y.success("指令下发成功")}catch{y.error("指令下发失败")}finally{s(!1)}},children:t(D,{shape:"circle",type:"primary",danger:!0,loading:r,title:"远程静音",icon:t(j,{})})})}function O({device:e}){const r=N(e);return d("div",{className:T.deviceCard,children:[d("div",{className:"device-title",children:[t(M,{size:"large",shape:"square",src:e.icon}),t("span",{className:"name",children:e.name}),e.protocol==="zigbee"&&t("div",{style:{flex:1,textAlign:"right"},children:t(E,{device:e})})]}),t("div",{className:"device-content",children:r&&Object.keys(r).sort().map(s=>t(A,{name:s,measurement:r[s]},s))})]})}function K({roomId:e}){const[r,s]=u.useState(),o=g(),{subscribe:m}=k(),f=u.useRef({});return u.useEffect(()=>{f.current.accessToken=o.accessToken},[o.accessToken]),u.useEffect(()=>{if(!e)return;let a=!0,l;return(async()=>{const i=await b.findAll({roomId:e}).catch(()=>{});i&&(l=m(i.map(c=>`device/${c.uuid}/senml`),(c,p)=>{const v=i.find(n=>n.uuid===c);if(v)for(let n of p)n.n!=="model"&&v.addMeasurementData(n.n,{value:n.vb!==void 0?n.vb:Number(n.v).toFixed(2),unit:n.u})}),a&&s(i))})(),()=>{a=!1,l&&l()}},[e]),e?d("div",{style:{paddingRight:"12px"},children:[t("h4",{children:"设备"}),r&&r.map(a=>t(O,{device:a},a.id))]}):null}export{K as default};
