import{dq as m,dG as S,dm as r,V as E}from"./index-D_pphaE2.js";import{a as N}from"./react-select.esm-OUcOCR-x.js";const C=m.memo(({devices:d,value:a,label:c,detail:u,required:f,disabled:b,onChange:p,groups:i=[]})=>{const{t:n}=S("common"),h=e=>{if(e)if(e.value.startsWith("0x"))p(d.find(t=>t.ieee_address===e.value));else{const t=Number.parseInt(e.value,10);p(i.find(s=>t===s.id))}},o=m.useMemo(()=>{const e=[],t=d.map(s=>({value:s.ieee_address,label:`${s.friendly_name} ${s.definition?.model?`(${s.definition?.model})`:""}`})).sort((s,l)=>s.label.localeCompare(l.label));if(i?.length){const s=i.map(l=>({value:`${l.id}`,label:l.friendly_name})).sort((l,_)=>l.label.localeCompare(_.label));e.push({label:n(l=>l.devices),options:t}),e.push({label:n(l=>l.groups),options:s})}else e.push({label:n(s=>s.devices),options:t});return e},[d,i,n]),x=m.useMemo(()=>a==null||a===""?null:typeof a=="number"?o[1]?.options.find(e=>e.value===`${a}`)??null:o[0]?.options.find(e=>e.value===a)??null,[a,o]);return r.jsxs("fieldset",{className:"fieldset",children:[c&&r.jsxs("legend",{className:"fieldset-legend",children:[c,f?" *":""]}),r.jsx(N,{unstyled:!0,placeholder:n(e=>e.select_device),"aria-label":c??n(e=>e.select_device),options:o,value:x,isSearchable:!0,isDisabled:b,onChange:h,className:"min-w-64",classNames:E}),u&&r.jsx("span",{className:"label",children:u})]})});export{C as D};
