import{a as _,r as l,W as A,b as N,s as y,v as D,j as e,B as v,w as S,F as g,x as F,f as T,y as k,z as L,A as R}from"./index-BeDhuS24.js";import{D as I}from"./DashboardFeatureWrapper-QO-XFtKk.js";import{D as M}from"./DeviceCard-D2ifb9S1.js";import{D as q,R as $}from"./DeviceControlEditName-D6ss-GnK.js";import{D as B}from"./DebouncedInput-jeSVRz3c.js";import"./envs-DFlyG_dH.js";import"./Feature-B18PTY7Z.js";import"./DisplayValue-y4u-p3TF.js";import"./_createCompounder-HA4t3BbU.js";import"./LastSeen-Tt-X3bir.js";import"./format-LeabZw87.js";import"./Lqi-Bexjv2VI.js";import"./PowerSource-M8I2qqUm.js";import"./snakeCase-DF3cbatb.js";import"./DeviceImage-CGx5yo8m.js";import"./index-CIWfMo3U.js";import"./CheckboxField-BhwpagjA.js";import"./InputField-E2g5qJCn.js";const W=["schedule_","_mode","_options","_startup","_type","inching_","cyclic_"],U=["battery","linkquality","options","position","programming","strength","voltage","warning","gradient","power_outage_memory","power_on_behavior"],z=["state","brightness","color_temp","mode","sound","occupancy","tamper","alarm","action","contact"],K=(a,o)=>{if(a){if(z.includes(a))return!0;for(const c of W)if(a.includes(c))return!1;if(U.includes(a))return!1}return!0},C=(a,o={})=>{const{property:c,name:n,access:d}=a;if(K(n)){if("features"in a&&a.features&&a.features.length>0){const i=[],f=c?o[c]:o;for(const r of a.features){const u=C(r,f);u&&!i.some(b=>b.property===u.property)&&i.push(u)}return{...a,features:i}}return{...a}}};function ce(){const a=_(s=>s.deviceStates),o=_(s=>s.bridgeInfo.config),c=_(s=>s.devices),{sendMessage:n}=l.useContext(A),{t:d}=N(["zigbee","settings"]),[i,f]=l.useState(""),[r,u]=l.useState(y.get(D,!1)),b=l.useCallback(async(s,t,m)=>{await n("bridge/request/device/rename",{from:s,to:t,homeassistant_rename:m,last:!1})},[n]),x=l.useCallback(async(s,t,m)=>{await n("bridge/request/device/remove",{id:s,force:t,block:m})},[n]),w=l.useCallback(s=>{y.set(D,s),u(s)},[]),E=l.useMemo(()=>{const s=[];for(const t of c)if(!t.disabled&&t.supported&&(!i||t.friendly_name.toLowerCase().includes(i.toLowerCase()))){const m=a[t.friendly_name]??{},h=[];if(t.definition?.exposes)for(const p of t.definition.exposes){const j=C(p,m);if(j&&(h.push(j),h.length===10))break}h.length>0&&s.push(e.jsx("div",{className:`${r?"break-inside-avoid-column mb-3":"w-[23rem]"} card bg-base-200 rounded-box shadow-md`,children:e.jsx(M,{features:h,device:t,deviceState:m,onChange:async p=>await n(`${t.ieee_address}/set`,p),onRead:async p=>await n(`${t.ieee_address}/get`,p),featureWrapperClass:I,lastSeenConfig:o.advanced.last_seen,children:e.jsxs("div",{className:"join join-horizontal",children:[e.jsx(q,{name:t.friendly_name,renameDevice:b,homeassistantEnabled:o.homeassistant.enabled,style:"btn-outline btn-primary btn-square btn-sm join-item"}),e.jsx(v,{onClick:async()=>await S.show($,{device:t,removeDevice:x}),className:"btn btn-outline btn-error btn-square btn-sm join-item",title:d("remove_device"),children:e.jsx(g,{icon:F})})]})})},t.ieee_address))}return s},[c,a,o.advanced.last_seen,o.homeassistant.enabled,n,x,b,d,i,r]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-row justify-center items-center gap-3 mb-3",children:[e.jsxs("div",{className:"join",children:[e.jsxs("label",{className:"input w-64 join-item",children:[e.jsx(g,{icon:T}),e.jsx(B,{className:"",type:"search",onChange:s=>f(s.toString()),placeholder:d("common:search"),value:i})]}),e.jsx(v,{item:"",onClick:f,className:"btn btn-square join-item",title:d("common:clear"),children:e.jsx(g,{icon:k})})]}),e.jsx(v,{className:"btn btn-square",item:!r,onClick:w,title:`${d("settings:dashboard_column_display")}: ${r}`,children:e.jsx(g,{icon:r?L:R})})]}),e.jsx("div",{className:`${r?"columns-md":"flex flex-row flex-wrap justify-center"} gap-3 mb-3`,children:E})]})}export{ce as default};
