import{r as m,u as _,j as r,D as E}from"./index-B_eahVWI.js";import{S as N}from"./react-select.esm-BQis7zht.js";const C=m.memo(({devices:c,value:n,label:d,detail:u,required:f,disabled:b,onChange:p,groups:i=[]})=>{const{t:a}=_("common"),h=e=>{if(e)if(e.value.startsWith("0x"))p(c.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=c.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,S)=>l.label.localeCompare(S.label));e.push({label:a(l=>l.devices),options:t}),e.push({label:a(l=>l.groups),options:s})}else e.push({label:a(s=>s.devices),options:t});return e},[c,i,a]),x=m.useMemo(()=>n==null||n===""?null:typeof n=="number"?o[1]?.options.find(e=>e.value===`${n}`)??null:o[0]?.options.find(e=>e.value===n)??null,[n,o]);return r.jsxs("fieldset",{className:"fieldset",children:[d&&r.jsxs("legend",{className:"fieldset-legend",children:[d,f?" *":""]}),r.jsx(N,{unstyled:!0,placeholder:a(e=>e.select_device),"aria-label":d??a(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};
