import{j as t,a as v,F as H}from"./index.ade10008.js";import{E as J}from"./index.de365a74.js";import{g as L,S as V,P as Q,a as i,I as q,F as G}from"./Filter.f2d5a535.js";import{u as K,r as a}from"./react.0dd1ea4b.js";import{u as z}from"./Measurements.ae81467d.js";import{E as U,C as W,T as X,R as Y}from"./Room.740ee64b.js";import"./dev-log.2ac7388a.js";const Z="_wrap_ev091_4",ee="_bar_ev091_7",te="_filter_ev091_48",se="_list_ev091_66",ae="_skeleton_ev091_76";var u={wrap:Z,bar:ee,filter:te,"filter-icon":"_filter-icon_ev091_54","filter-text":"_filter-text_ev091_59",list:se,skeleton:ae};const re="_card_1a1iz_1",ne="_info_1a1iz_7",le="_describe_1a1iz_10",oe="_name_1a1iz_13";var g={card:re,info:ne,describe:le,"name-row":"_name-row_1a1iz_13",name:oe,"tag-row":"_tag-row_1a1iz_24"};const ie=({room:r,measurements:n})=>{const m=K(),{customField:d,id:E}=r,f=d.iot_events?JSON.parse(d.iot_events):[],S=z(),[x,b]=a.exports.useState([]);return a.exports.useEffect(()=>{if(n&&S){let l=[];const p=Object.entries(S).filter(_=>n.includes(_[0]));e:for(let _ of p){if(f&&f.length)for(let N of f){const[$,c]=N.split(":");if(c.includes(_[1].title)){l.push({color:U[$],title:c});continue e}}l.push({color:"#40dc00",title:`${_[1].title} \u6B63\u5E38`})}b(l)}},[n,S]),t(W,{className:g.card,onClick:()=>m(`/surveillance/${E}`),children:t("div",{className:g.info,children:v("div",{className:g.describe,children:[t("div",{className:g["name-row"],children:t("div",{className:g.name,children:`${r.building.path}-${r.building.name}-${r.code}(${r.name})`})}),t("div",{className:g["tag-row"],children:x?x.map((l,p)=>t(X,{color:l.color,children:l.title},p)):null})]})})})},ce=L("Filter");function ue(r){for(const n in r)r[n]===null&&delete r[n]}const Se=()=>{const[r,n]=a.exports.useState(!1),[m,d]=a.exports.useState([]),[E,f]=a.exports.useState(1),[S,x]=a.exports.useState([]),b=z(),[l,p]=a.exports.useState({pg:1,pp:20}),[_,N]=a.exports.useState(!0),[$,c]=a.exports.useState(!0),[h,C]=a.exports.useState({}),[T,k]=a.exports.useState(!1),[M,me]=a.exports.useState({includes:"building,role/room_master,custom",operable:1,customField:{iot_device_count$:"[1,)",od:"iot_event_urgency:desc"}}),[A,w]=a.exports.useState("");a.exports.useEffect(()=>{document.title="\u5B9E\u65F6\u76D1\u63A7";let e=!0;return(async()=>!e||await F())(),()=>{e=!1}},[]),a.exports.useEffect(()=>{let e=[];for(let s of m)e.push(...P(s));x(e)},[m]),a.exports.useEffect(()=>{F()},[h]);const P=e=>{var B;let s=[];const o=JSON.parse((B=e==null?void 0:e.customField)==null?void 0:B.iot_measurements)||[];for(let j of o)s.includes(j)||s.push(j);return s},F=async()=>{try{const e=await Y.findAndCountAll({...M,customField:{...M.customField,...h},...l});return d(s=>[...s,...e.items]),f(e.total),N(!!e.items.length),c(!1),e}catch{return c(!1),null}};let y=null;const O=async e=>{w(e),y&&clearTimeout(y),y=setTimeout(async()=>{if(R(),!e)C({...h,iot_measurements$:null});else try{if(!b)return;const[[s]]=Object.entries(b).filter(o=>o[1].title==e);if(s!=null){let o={iot_measurements$:`*${s}*`};C({...h,...o})}}catch{d([]),f(0),c(!1)}},500)},D=e=>{w(e||"")},I=async e=>{let s={};s.iot_events$=e.level?`*${e.level}*`:null,s.groups=e.group?`${e.group}`:null,s.iot_measurements$=e.measurement?`*${e.measurement}*`:T?h.iot_measurements$:null;let o={...h,...s};ue(o),C({...o}),k(!1)},R=()=>{c(!0),window.scrollTo(0,0),d([]),p({pg:1,pp:20})};return v("div",{className:u.wrap,children:[v("div",{className:u.bar,children:[t(V,{placeholder:"\u641C\u7D22\u73AF\u5883\u6307\u6807\u5173\u952E\u5B57",value:A,onChange:e=>{k(!0),O(e)}}),v("div",{className:u.filter,onClick:()=>n(!0),children:[t(ce,{className:u["filter-icon"]}),t("div",{className:u["filter-text"],children:"\u7B5B\u9009"})]})]}),t("div",{className:u.list,children:t(Q,{onRefresh:async()=>{C({})},children:$?v("div",{className:u.skeleton,children:[t(i.Title,{animated:!0}),t(i.Paragraph,{lineCount:3,animated:!0}),t(i.Title,{animated:!0}),t(i.Paragraph,{lineCount:3,animated:!0}),t(i.Title,{animated:!0}),t(i.Paragraph,{lineCount:3,animated:!0}),t(i.Title,{animated:!0}),t(i.Paragraph,{lineCount:3,animated:!0})]}):m.length?v(H,{children:[m.map((e,s)=>t(ie,{room:e,measurements:P(e)},s)),t(q,{loadMore:async()=>{p({pg:l.pg+=1,pp:20}),await F()},threshold:0,hasMore:_})]}):t(J,{status:"empty"})})}),t(G,{visible:r,hasSearch:T,options:["level","group","measurement"],measurements:S,onSelect:D,onCallback:e=>{R(),I(e)},onClose:()=>n(!1)})]})};export{Se as default};
