import{au as b,aI as F,v,at as S,aw as C,c as D,a as A,r as x,i as E,G as w,j as m}from"./index-6a654fd1.js";import{D as B}from"./DashboardDevice-42d2020b.js";import{i as I,b as j,g as k,D as T}from"./DashboardFeatureWrapper-da048f13.js";import{_ as G}from"./_baseSet-f3b093ad.js";import{c as N}from"./_getAllKeysIn-8e18f3ff.js";import{a as P,g as L,G as K,p as M}from"./persist-684591ba.js";import{D as y}from"./DEVICES_GLOBAL_NAME-6620c611.js";import{F as p}from"./DeviceImage-8f8abcdd.js";import"./index-3e75459d.js";import"./powerSourceTypeToTranslationKey-452dac81.js";import"./isEqual-a00f752b.js";import"./index-f13e0cb5.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=S,z=C,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(I(t)||j(t)){r=r.map(d=>g(d,e?a[e]:a)).filter(d=>d);const c=k(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&p.ACCESS_STATE&&!re.includes(a[e]))?!1:s=="voltage"&&a.battery==null?i:Y.includes(s)?!1:n===p.ACCESS_STATE||n===p.ACCESS_STATE+p.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 f={...r,globalFilter:o};i(f),M(y,f)},d=X(l,(o,f)=>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 m.jsxs("div",{className:"row",children:[m.jsx("div",{className:"col-12",children:m.jsx("div",{className:"flex-fill card flex-shrink-1",children:m.jsx("div",{className:"card-footer",children:m.jsx(K,{globalFilter:r.globalFilter,setGlobalFilter:c})})})}),ae(d,e,g).map(({device:o,deviceState:f,filteredFeatures:u})=>m.jsx(B,{feature:{features:u},device:o,deviceState:f,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};
