import{dm as e,dG as g,x as h,o as b,bH as j,bM as _,l as N,cT as C,dq as d,V as v,de as w,dx as x,B as S,dB as G,dF as k}from"./index-DjbVAZHL.js";import{u as E,g as M}from"./useColumnCount-BxxtEcEj.js";import{E as y}from"./EndpointPicker-ByksWRBx.js";import{a as T}from"./react-select.esm-189R5gw4.js";import"./envs-CRUy-_iG.js";import"./SelectField-XDAy-a1R.js";import"./defineProperty-CegpTSss.js";import"./extends-CF3RwP-h.js";import"./floating-ui.dom-CFVCCol6.js";const A=({sourceIdx:o,group:s,endpoint:l,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(h,{to:`/group/${o}/${s.id}/devices`,className:"link link-hover font-semibold",children:["#",s.id," - ",s.friendly_name,l?` (${n(a=>a.endpoint,{ns:"zigbee"})}: ${l})`:""]}),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:j})," ",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:_}),s.scenes.length]}),e.jsx(N,{item:[s,l],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:C})})]})]})},$=o=>o?.data?e.jsx(A,{...o.data}):null,q=d.memo(({groups:o,label:s,required:l,disabled:i,onChange:n})=>{const{t:a}=g("common"),u=d.useCallback(r=>{if(r){const m=Number.parseInt(r.value,10);n(o.find(p=>m===p.id))}},[o,n]),c=d.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,l?" *":""]}),e.jsx(T,{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:v})]})}),F=d.memo(({sourceIdx:o,device:s,nonMemberGroups:l})=>{const{t:i}=g(["groups","zigbee"]),[n,a]=d.useState(""),[u,c]=d.useState(""),r=d.useMemo(()=>w(s),[s]),m=d.useCallback(t=>{c(t.id);const f=r.values().next().value;a(f??"")},[r]),p=d.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(q,{label:i(t=>t.group,{ns:"zigbee"}),groups:l,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(S,{onClick:p,className:"btn btn-primary",disabled:n==null||u==null||n===""||u==="",children:i(t=>t.add_to_group)})]})});function U({sourceIdx:o,device:s}){const l=G(k(c=>c.groups[o])),i=E(),n=d.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]=d.useMemo(()=>{const c=[],r=[];for(const m of l){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,l,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(F,{sourceIdx:o,device:s,nonMemberGroups:u})})})}),e.jsx("div",{children:e.jsx(M,{useWindowScroll:!0,columnCount:i,data:a,ItemContent:$,className:"gap-3"},`membergroups-${a.length}`)})]})}export{U as default};
