import{j as e,u as g,L as f,F as b,bd as h,be as j,a9 as _,a0 as N,r as l,D as C,ab as v,s as x,B as w,a as S,I as G}from"./index-VJpwYvBU.js";import{u as k,g as E}from"./useColumnCount-BNJ8FuYE.js";import{E as y}from"./EndpointPicker-DlYDImDR.js";import{S as M}from"./react-select.esm-DM_HiCZr.js";import"./envs-CRUy-_iG.js";import"./SelectField-BkTP72p-.js";import"./defineProperty-CegpTSss.js";import"./extends-CF3RwP-h.js";import"./floating-ui.dom-DbzrgdRQ.js";const A=({sourceIdx:o,group:s,endpoint:d,removeFromGroup:i})=>{const{t:n}=g(["groups","common","zigbee"]);return e.jsxs("div",{className:"mb-3 card card-border bg-base-200 border-base-300 rounded-box shadow-md",children:[e.jsx("div",{className:"card-body p-3",children:e.jsx("div",{className:"flex flex-row items-center gap-3 w-full",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs(f,{to:`/group/${o}/${s.id}/devices`,className:"link link-hover font-semibold",children:["#",s.id," - ",s.friendly_name,d?` (${n(a=>a.endpoint,{ns:"zigbee"})}: ${d})`:""]}),s.description&&e.jsx("div",{className:"text-xs opacity-50 truncate",title:s.description,children:s.description})]})})}),e.jsxs("div",{className:"flex flex-row flex-wrap gap-1 mx-2 mb-2 justify-around items-center",children:[e.jsxs("div",{className:"badge badge-soft badge-ghost cursor-default me-2 tooltip","data-tip":n(a=>a.group_members),children:[e.jsx(b,{icon:h})," ",s.members.length]}),e.jsxs("div",{className:"badge badge-soft badge-ghost cursor-default me-2 tooltip","data-tip":n(a=>a.group_scenes),children:[e.jsx(b,{icon:j}),s.scenes.length]}),e.jsx(_,{item:[s,d],onClick:i,className:"btn btn-square btn-error btn-sm",title:n(a=>a.remove_from_group),modalDescription:n(a=>a.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:n(a=>a.cancel,{ns:"common"}),children:e.jsx(b,{icon:N})})]})]})},L=o=>o?.data?e.jsx(A,{...o.data}):null,T=l.memo(({groups:o,label:s,required:d,disabled:i,onChange:n})=>{const{t:a}=g("common"),u=l.useCallback(r=>{if(r){const m=Number.parseInt(r.value,10);n(o.find(p=>m===p.id))}},[o,n]),c=l.useMemo(()=>o.map(r=>({value:`${r.id}`,label:r.friendly_name})).sort((r,m)=>r.label.localeCompare(m.label)),[o]);return e.jsxs("fieldset",{className:"fieldset",children:[s&&e.jsxs("legend",{className:"fieldset-legend",children:[s,d?" *":""]}),e.jsx(M,{unstyled:!0,placeholder:a(r=>r.select_group),"aria-label":s??a(r=>r.select_group),options:c,isSearchable:!0,isDisabled:i,onChange:u,className:"min-w-64",classNames:C})]})}),$=l.memo(({sourceIdx:o,device:s,nonMemberGroups:d})=>{const{t:i}=g(["groups","zigbee"]),[n,a]=l.useState(""),[u,c]=l.useState(""),r=l.useMemo(()=>v(s),[s]),m=l.useCallback(t=>{c(t.id),a(r.values().next().value)},[r]),p=l.useCallback(async()=>await x(o,"bridge/request/group/members/add",{group:u.toString(),endpoint:n,device:s.ieee_address}),[o,u,s.ieee_address,n]);return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-semibold",children:i(t=>t.add_to_group)}),e.jsxs("div",{className:"flex flex-row flex-wrap mb-3 gap-3",children:[e.jsx(T,{label:i(t=>t.group,{ns:"zigbee"}),groups:d,onChange:m,required:!0}),e.jsx(y,{label:i(t=>t.endpoint,{ns:"zigbee"}),values:r,value:n,onChange:t=>a(t),required:!0})]}),e.jsx(w,{onClick:p,className:"btn btn-primary",disabled:n==null||u==null||n===""||u==="",children:i(t=>t.add_to_group)})]})});function H({sourceIdx:o,device:s}){const d=S(G(c=>c.groups[o])),i=k(),n=l.useCallback(async([c,r])=>await x(o,"bridge/request/group/members/remove",{device:s.ieee_address,endpoint:r,group:c.id.toString()}),[o,s.ieee_address]),[a,u]=l.useMemo(()=>{const c=[],r=[];for(const m of d){const p=m.members.filter(t=>t.ieee_address===s.ieee_address);if(p.length>0)for(const t of p)c.push({sourceIdx:o,group:m,endpoint:t.endpoint,removeFromGroup:n});else r.push(m)}return[c,r]},[o,d,s.ieee_address,n]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-row flex-wrap gap-4 mb-3 w-full",children:e.jsx("div",{className:"card card-border bg-base-200 border-base-300 rounded-box shadow-md flex-1",children:e.jsx("div",{className:"card-body p-4",children:e.jsx($,{sourceIdx:o,device:s,nonMemberGroups:u})})})}),e.jsx("div",{children:e.jsx(E,{useWindowScroll:!0,columnCount:i,data:a,ItemContent:L,className:"gap-3"},`membergroups-${a.length}`)})]})}export{H as default};
