import{a as v,r as l,W as N,b as S,s as y,v as D,j as e,B as _,w as F,F as g,x as T,f as k,y as L,z as R,A as I}from"./index-DtyjNqrf.js";import{D as M}from"./DashboardFeatureWrapper-CWbT-TyR.js";import{D as q}from"./DeviceCard-Bz1iBm0H.js";import{D as $,R as B}from"./DeviceControlEditName-CIF4s9nK.js";import{D as W}from"./DebouncedInput-DnWGzIEH.js";import"./envs-DFlyG_dH.js";import"./Feature-VsMzzVJz.js";import"./DisplayValue-B5Rw3jLu.js";import"./_createCompounder-CbLsIfEE.js";import"./capitalize-C89IAw35.js";import"./LastSeen-CvhRQlEh.js";import"./format-6Yb6jWnA.js";import"./Lqi-CoNVuBvb.js";import"./PowerSource-DgFKG_xU.js";import"./snakeCase-DmoQhYQA.js";import"./DeviceImage-D-FjKeE6.js";import"./index-Q3KOJDn9.js";import"./CheckboxField-DKhAwA85.js";import"./InputField-CYbmpJqW.js";const U=["schedule_","_mode","_options","_startup","_type","inching_"],z=["battery","linkquality","options","position","programming","strength","voltage","warning","gradient","power_outage_memory","power_on_behavior"],K=["state","brightness","color_temp","mode","sound","occupancy","tamper","alarm","action","contact"],C=(a,i)=>{if(a){if(K.includes(a))return!0;for(const c of U)if(a.includes(c))return!1;if(z.includes(a))return!1}return!0},w=(a,i={})=>{const{property:c,name:n,access:d}=a;if("features"in a&&a.features&&a.features.length>0){const o=[],f=c?i[c]:i;for(const r of a.features){const u=w(r,f);u&&!o.some(b=>b.property===u.property)&&o.push(u)}return o.length>0||C(n)?{...a,features:o}:void 0}return C(n)?{...a}:void 0};function le(){const a=v(s=>s.deviceStates),i=v(s=>s.bridgeInfo.config),c=v(s=>s.devices),{sendMessage:n}=l.useContext(N),{t:d}=S(["zigbee","settings"]),[o,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]),E=l.useCallback(s=>{y.set(D,s),u(s)},[]),A=l.useMemo(()=>{const s=[];for(const t of c)if(!t.disabled&&t.supported&&(!o||t.friendly_name.toLowerCase().includes(o.toLowerCase()))){const m=a[t.friendly_name]??{},h=[];if(t.definition?.exposes)for(const p of t.definition.exposes){const j=w(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(q,{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:M,lastSeenConfig:i.advanced.last_seen,children:e.jsxs("div",{className:"join join-horizontal",children:[e.jsx($,{name:t.friendly_name,renameDevice:b,homeassistantEnabled:i.homeassistant.enabled,style:"btn-outline btn-primary btn-square btn-sm join-item"}),e.jsx(_,{onClick:async()=>await F.show(B,{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:T})})]})})},t.ieee_address))}return s},[c,a,i.advanced.last_seen,i.homeassistant.enabled,n,x,b,d,o,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:k}),e.jsx(W,{className:"",type:"search",onChange:s=>f(s.toString()),placeholder:d("common:search"),value:o})]}),e.jsx(_,{item:"",onClick:f,className:"btn btn-square join-item",title:d("common:clear"),children:e.jsx(g,{icon:L})})]}),e.jsx(_,{className:"btn btn-square",item:!r,onClick:E,title:`${d("settings:dashboard_column_display")}: ${r}`,children:e.jsx(g,{icon:r?R:I})})]}),e.jsx("div",{className:`${r?"columns-md":"flex flex-row flex-wrap justify-center"} gap-3 mb-3`,children:A})]})}export{le as default};
