import{a as g,r as p,W as D,b as w,j as a,B as C,w as E,F as _,x as N,f as A}from"./index-vDL8KyrI.js";import{D as F}from"./DashboardFeatureWrapper-CotxeSO1.js";import{D as S}from"./DeviceCard-C0AcffeR.js";import{D as k,R as T}from"./DeviceControlEditName-BXFSFs5f.js";import{D as R}from"./DebouncedInput-DpBqTOhq.js";import"./Feature-Dn8iv4tk.js";import"./DisplayValue-CvjefE6V.js";import"./_createCompounder-Bmfmbzn9.js";import"./capitalize-Cw1mPDhM.js";import"./LastSeen-BB0rwxhg.js";import"./Lqi-C8sPb_IK.js";import"./PowerSource-DFW6CjuU.js";import"./snakeCase-B_0CeYWc.js";import"./DeviceImage-BpknBFw1.js";import"./index-C4Y7ujGQ.js";import"./CheckboxField-m1WCeVZk.js";import"./InputField-B5sOh_uD.js";const I=["schedule_","_mode","_options","_startup"],L=["battery","linkquality","options","position","programming","strength","voltage","warning","gradient"],M=["state","brightness","color_temp","mode","sound","occupancy","tamper","alarm","action","contact"],j=(t,r)=>{if(t){if(M.includes(t))return!0;for(const i of I)if(t.includes(i))return!1;if(L.includes(t))return!1}return!0},y=(t,r={})=>{const{property:i,name:o,access:d}=t;if("features"in t&&t.features&&t.features.length>0){const n=[],m=i?r[i]:r;for(const f of t.features){const c=y(f,m);c&&!n.some(b=>b.property===c.property)&&n.push(c)}return n.length>0||j(o)?{...t,features:n}:void 0}return j(o)?{...t}:void 0};function ee(){const t=g(e=>e.deviceStates),r=g(e=>e.bridgeInfo.config),i=g(e=>e.devices),{sendMessage:o}=p.useContext(D),{t:d}=w("zigbee"),[n,m]=p.useState(""),f=p.useCallback(async(e,l,s)=>{await o("bridge/request/device/rename",{from:e,to:l,homeassistant_rename:s,last:!1})},[o]),c=p.useCallback(async(e,l,s)=>{await o("bridge/request/device/remove",{id:e,force:l,block:s})},[o]),b=p.useMemo(()=>{var l;const e=[];for(const s of i)if(!s.disabled&&s.supported&&(!n||s.friendly_name.toLowerCase().includes(n.toLowerCase()))){const v=t[s.friendly_name]??{},h=[];if((l=s.definition)!=null&&l.exposes)for(const u of s.definition.exposes){const x=y(u,v);if(x&&(h.push(x),h.length===10))break}h.length>0&&e.push(a.jsx("ul",{className:"flex-auto basis-sm list rounded-box shadow-md",children:a.jsx(S,{features:h,device:s,deviceState:v,onChange:async u=>await o(`${s.ieee_address}/set`,u),onRead:async u=>await o(`${s.ieee_address}/get`,u),featureWrapperClass:F,lastSeenConfig:r.advanced.last_seen,children:a.jsxs("div",{className:"join join-vertical lg:join-horizontal",children:[a.jsx(k,{name:s.friendly_name,renameDevice:f,homeassistantEnabled:r.homeassistant.enabled,style:"btn-primary btn-square btn-sm join-item"}),a.jsx(C,{onClick:async()=>await E.show(T,{device:s,removeDevice:c}),className:"btn btn-error btn-square btn-sm join-item",title:d("remove_device"),children:a.jsx(_,{icon:N})})]})})},s.ieee_address))}return e},[i,t,r.advanced.last_seen,r.homeassistant.enabled,o,c,f,d,n]);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex flex-row justify-center items-center gap-3 mb-3",children:a.jsxs("label",{className:"input w-64",children:[a.jsx(_,{icon:A}),a.jsx(R,{className:"",type:"search",onChange:e=>m(e.toString()),placeholder:d("common:search"),value:n,disabled:b.length===0}),a.jsx("kbd",{className:"kbd kbd-sm cursor-pointer",onClick:()=>m(""),onKeyUp:e=>{e.key==="enter"&&m("")},title:d("common:clear"),children:"x"})]})}),a.jsx("div",{className:"flex flex-row flex-wrap justify-between items-stretch gap-3",children:b})]})}export{ee as default};
