import{r as o,a as g,ae as C,b as j,W as _,j as e,B as D,I as w,F as k,x as y}from"./index-vDL8KyrI.js";import{g as M,R as F,A as N}from"./RecallRemove-DchDgS_I.js";import{D as R}from"./DevicePicker-CGedN3DH.js";import{E}from"./EndpointPicker-DOVgHugJ.js";import{D as A}from"./DashboardFeatureWrapper-CotxeSO1.js";import{D as G}from"./DeviceCard-C0AcffeR.js";import"./Feature-Dn8iv4tk.js";import"./DisplayValue-CvjefE6V.js";import"./_createCompounder-Bmfmbzn9.js";import"./capitalize-Cw1mPDhM.js";import"./InputField-B5sOh_uD.js";import"./SelectField-apZm61cq.js";import"./LastSeen-BB0rwxhg.js";import"./Lqi-C8sPb_IK.js";import"./PowerSource-DFW6CjuU.js";import"./snakeCase-B_0CeYWc.js";import"./DeviceImage-BpknBFw1.js";import"./index-C4Y7ujGQ.js";const I=o.memo(n=>{const[i,l]=o.useState(""),[a,m]=o.useState(""),{group:c}=n,d=g(s=>s.devices),u=o.useMemo(()=>C(d.find(s=>s.ieee_address===a)),[a,d]),{t:r}=j(["groups","zigbee"]),{sendMessage:p}=o.useContext(_),t=o.useCallback(s=>{m(s.ieee_address);const v=C(s);l(v.values().next().value)},[]);return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-semibold",children:r("add_to_group_header")}),e.jsxs("div",{className:"mb-3",children:[e.jsx(R,{label:r("zigbee:device"),value:a,devices:d,onChange:t}),e.jsx(E,{label:r("zigbee:endpoint"),values:u,value:i,onChange:s=>l(s)})]}),e.jsx(D,{onClick:async()=>await p("bridge/request/group/members/add",{group:c.id.toString(),endpoint:i,device:a}),className:"btn btn-primary",children:r("add_to_group")})]})}),W=o.memo(n=>{const{removeDeviceFromGroup:i,groupMember:l,device:a,deviceState:m,lastSeenConfig:c,setDeviceState:d,getDeviceState:u}=n,{endpoint:r}=l,{t:p}=j(["groups","common"]),t=o.useMemo(()=>{var x;const f=[];for(const S of((x=a.definition)==null?void 0:x.exposes)??[]){const h=M(S,m);if(h&&(f.push(h),f.length===10))break}return f},[a,m]),s=o.useCallback(async f=>await d(a.ieee_address,f),[a.ieee_address,d]),v=o.useCallback(async f=>await u(a.ieee_address,f),[a.ieee_address,u]),b=o.useCallback(async()=>await i(a.ieee_address,r),[a.ieee_address,r,i]);return e.jsx(G,{features:t,device:a,endpoint:r,deviceState:m,onChange:s,onRead:v,featureWrapperClass:A,lastSeenConfig:c,children:e.jsx(w,{onClick:b,className:"btn btn-square btn-error btn-sm",title:p("remove_from_group"),modalDescription:p("common:dialog_confirmation_prompt"),modalCancelLabel:p("common:cancel"),children:e.jsx(k,{icon:y})})})}),$=o.memo(n=>{const{group:i}=n,l=g(t=>t.devices),a=g(t=>t.deviceStates),m=g(t=>t.bridgeInfo.config.advanced.last_seen),{sendMessage:c}=o.useContext(_),d=o.useCallback(async(t,s)=>await c("bridge/request/group/members/remove",{device:t,endpoint:s,group:i.id.toString()}),[c,i.id]),u=o.useCallback(async(t,s)=>{await c(`${t}/set`,s)},[c]),r=o.useCallback(async(t,s)=>{await c(`${t}/get`,s)},[c]),p=o.useMemo(()=>{const t=[];for(const s of i.members){const v=l.find(b=>b.ieee_address===s.ieee_address);v&&t.push(e.jsx("ul",{className:"flex-auto basis-sm list rounded-box shadow-md",children:e.jsx(W,{removeDeviceFromGroup:d,device:v,groupMember:s,deviceState:a[v.friendly_name]??{},lastSeenConfig:m,setDeviceState:u,getDeviceState:r})},`${s.ieee_address}-${s.endpoint}`))}return t},[i,l,m,a,d,u,r]);return e.jsx("div",{className:"flex flex-row flex-wrap justify-between items-stretch gap-3",children:p})});function te({group:n}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-row flex-wrap justify-evenly gap-4 mb-3",children:[e.jsx("div",{className:"flex-1",children:e.jsx(I,{group:n})}),e.jsx("div",{className:"flex-1",children:e.jsx(F,{target:n,deviceState:{}})}),e.jsx("div",{className:"flex-1",children:e.jsx(N,{target:n,deviceState:{}})})]}),e.jsx($,{group:n})]})}export{te as default};
