import{r as p,a as C,D as S,u as h,j as m,y as N}from"./index-KAtljJVt.js";import{S as y}from"./react-select.esm-DL84IisZ.js";const M=e=>e.type>=32&&e.type<=47||e.type>=56&&e.type<=58||e.type>=224&&e.type<=226,A=(e,r,t)=>{const o=e.custom_clusters[r];if(o){const u=o[t];if(u)return u.attributes}const a=e.clusters[t];return a?a.attributes:{}},k=(e,r,t,o)=>A(e,r,t)[o],T=(e,r)=>({isNew:e,reportable_change:0,minimum_report_interval:60,maximum_report_interval:3600,endpoint:r,cluster:"",attribute:""}),w=e=>{const r=[];for(const t in e.endpoints){const a=e.endpoints[t].configured_reportings.map(u=>({...u,endpoint:t}));r.push({endpointId:t,rules:a})}return r},E=(e,r,t)=>!(e==null||e===""||Number.isNaN(e)||r==null||r===""||Number.isNaN(r)||t===""||Number.isNaN(t)||e>r&&!(r===0&&e===65535&&t===0)),O=e=>e.endpoint===void 0||e.endpoint===""||e.cluster===void 0||e.cluster===""||e.attribute===void 0||e.attribute===""?!1:E(e.minimum_report_interval,e.maximum_report_interval,e.reportable_change),L=p.memo(({sourceIdx:e,cluster:r,device:t,onChange:o,value:a,label:u,required:c,disabled:_})=>{const f=C(S(s=>s.bridgeDefinitions[e])),{t:b}=h("zigbee"),n=p.useMemo(()=>A(f,t.ieee_address,r),[f,t.ieee_address,r]),d=p.useMemo(()=>{const s=[];for(const l in n)s.push({value:l,label:l});return s},[n]),i=p.useMemo(()=>a==null||a===""?null:d.find(s=>s.value===a)??null,[a,d]);return m.jsxs("fieldset",{className:"fieldset",children:[u&&m.jsxs("legend",{className:"fieldset-legend",children:[u,c?" *":""]}),m.jsx(y,{unstyled:!0,placeholder:b(s=>s.select_attribute),"aria-label":u??b(s=>s.select_attribute),options:d,value:i,isSearchable:!0,isDisabled:_,onChange:s=>{s!=null&&o(s.value,n[s.value])},className:"min-w-64",classNames:N})]})}),v=p.memo(({clusters:e,onChange:r,value:t,label:o,disabled:a,required:u})=>{const{t:c}=h(["zigbee","common"]),[_,f]=p.useMemo(()=>{const n=[],d=[];if(Array.isArray(e))for(const i of e){const s=[];for(const l of i.clusters){const g={value:l,label:l};s.push(g),d.push(g)}s.sort((l,g)=>l.label.localeCompare(g.label)),n.push({label:c(l=>l[i.name]),options:s})}else{const i=[];for(const s of e){const l={value:s,label:s};i.push(l),d.push(l)}i.sort((s,l)=>s.label.localeCompare(l.label)),n.push({label:c(s=>s.cluster),options:i})}return[n,d]},[e,c]),b=p.useMemo(()=>t==null||t===""?null:f.find(n=>n.value===t)??null,[t,f]);return m.jsxs("fieldset",{className:"fieldset",children:[o&&m.jsxs("legend",{className:"fieldset-legend",children:[o,u?" *":""]}),m.jsx(y,{unstyled:!0,placeholder:c(n=>n.select_cluster),"aria-label":o??c(n=>n.select_cluster),options:_,value:b,isSearchable:!0,isDisabled:a,onChange:n=>{n!=null&&r(n.value)},className:"min-w-64",classNames:N})]})});export{L as A,v as C,M as a,w as b,A as c,O as d,k as g,E as i,T as m};
