import{as as b,aG as F,p as v,ar as C,au as S,c as D,a as A,r as x,i as E,C as w,j as p}from"./index-a77bd902.js";import{D as B}from"./DashboardDevice-c02266db.js";import{i as j,b as k,g as I,c as f,D as T}from"./DashboardFeatureWrapper-fc8d0f26.js";import{_ as G}from"./_baseSet-2ead6744.js";import{c as N}from"./_getAllKeysIn-bf2f2df3.js";import{a as P,g as L,G as K,p as M}from"./persist-4349f4e2.js";import{D as y}from"./DEVICES_GLOBAL_NAME-6620c611.js";import"./index-6ddbc65b.js";import"./powerSourceTypeToTranslationKey-452dac81.js";import"./DeviceImage-3bec68ff.js";import"./index-f7288b4b.js";import"./isEqual-997da78b.js";var O=b,R=G,V=F;function W(t,a,n){for(var e=-1,s=a.length,l={};++e<s;){var r=a[e],i=O(t,r);n(i,r)&&R(l,V(r,t),i)}return l}var $=W,q=C,z=S,H=$,J=N;function Q(t,a){if(t==null)return{};var n=q(J(t),function(e){return[e]});return a=z(a),H(t,n,function(e,s){return a(e,s[0])})}var U=Q;const X=v(U),Y=["linkquality","battery","battery_low","battery_state","color_temp_startup","voltage","strength","color_options","warning","position","operation_mode","operation_mode2","programming_mode","options","programming","schedule_monday","schedule_tuesday","schedule_wednesday","schedule_thursday","schedule_friday","schedule_saturday","schedule_sunday","holiday_mode_date"],Z=["state","brightness","color_temp","mode","sound","occupancy","tamper","alarm"],ee=["light"],re=["",null,void 0],g=(t,a={})=>{const{access:n,property:e,name:s,type:l}=t;let{features:r}=t;if(j(t)||k(t)){r=r.map(d=>g(d,e?a[e]:a)).filter(d=>d);const c=I(r,"property");r=Object.values(c).map(d=>d[0])}const i={...t,features:r};return Z.includes(s)||ee.includes(l)?i:n&&!(n&f.ACCESS_STATE&&!re.includes(a[e]))?!1:s=="voltage"&&a.battery==null?i:Y.includes(s)?!1:n===f.ACCESS_STATE||n===f.ACCESS_STATE+f.ACCESS_READ||Array.isArray(r)&&r.length>0?i:!1},te=["friendly_name","description","ieee_address","manufacturer","type","power_source","model_id","definition.model","definition.vendor"];function ae(t,a,n){return Object.values(t).filter(e=>e.supported).map(e=>({device:e,deviceState:a[e.friendly_name]??{}})).map(({device:e,deviceState:s})=>{var i;const r=(((i=e.definition)==null?void 0:i.exposes)??[]).map(c=>n(c,s)).filter(c=>c);return{device:e,deviceState:s,filteredFeatures:r}}).filter(({filteredFeatures:e})=>e.length>0).sort((e,s)=>e.device.friendly_name.localeCompare(s.device.friendly_name))}function se(t){const{setDeviceState:a,getDeviceState:n,deviceStates:e,bridgeInfo:s,devices:l}=t,[r,i]=x.useState(()=>P(L(y))??{}),c=o=>{const m={...r,globalFilter:o};i(m),M(y,m)},d=X(l,(o,m)=>E(o,s.config)?!1:r.globalFilter?te.map(u=>w(o,u)).filter(Boolean).map(String).map(u=>u.toLowerCase()).some(u=>u.includes(r.globalFilter.toLowerCase())):!0);return p.jsxs("div",{className:"row",children:[p.jsx("div",{className:"col-12",children:p.jsx("div",{className:"flex-fill card flex-shrink-1",children:p.jsx("div",{className:"card-footer",children:p.jsx(K,{globalFilter:r.globalFilter,setGlobalFilter:c})})})}),ae(d,e,g).map(({device:o,deviceState:m,filteredFeatures:u})=>p.jsx(B,{feature:{features:u},device:o,deviceState:m,onChange:(h,_)=>a(o.friendly_name,_),onRead:(h,_)=>n(o.friendly_name,_),featureWrapperClass:T,lastSeenType:s.config.advanced.last_seen},o.ieee_address))]})}const ge=D(["devices","deviceStates","bridgeInfo"],A)(se);export{ge as ConnectedDashboardPage};
