import{r as o,a as b,ah as h,b as C,W as j,j as e,B as S,R as D,F as w,x as k}from"./index-BeDhuS24.js";import{g as y,R as M,A as F}from"./RecallRemove-BT61_xFm.js";import{D as N}from"./DevicePicker-DIWryjuN.js";import{E as R}from"./EndpointPicker-Cni8eLro.js";import{D as E}from"./DashboardFeatureWrapper-QO-XFtKk.js";import{D as A}from"./DeviceCard-D2ifb9S1.js";import"./envs-DFlyG_dH.js";import"./Feature-B18PTY7Z.js";import"./DisplayValue-y4u-p3TF.js";import"./_createCompounder-HA4t3BbU.js";import"./InputField-E2g5qJCn.js";import"./SelectField-CgXiODUe.js";import"./LastSeen-Tt-X3bir.js";import"./format-LeabZw87.js";import"./Lqi-Bexjv2VI.js";import"./PowerSource-M8I2qqUm.js";import"./snakeCase-DF3cbatb.js";import"./DeviceImage-CGx5yo8m.js";import"./index-CIWfMo3U.js";const G=o.memo(n=>{const[i,l]=o.useState(""),[a,m]=o.useState(""),{group:c}=n,d=b(s=>s.devices),u=o.useMemo(()=>h(d.find(s=>s.ieee_address===a)),[a,d]),{t:r}=C(["groups","zigbee"]),{sendMessage:p}=o.useContext(j),t=o.useCallback(s=>{m(s.ieee_address);const v=h(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(N,{label:r("zigbee:device"),value:a,devices:d,onChange:t}),e.jsx(R,{label:r("zigbee:endpoint"),values:u,value:i,onChange:s=>l(s)})]}),e.jsx(S,{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")})]})}),I=o.memo(n=>{const{removeDeviceFromGroup:i,groupMember:l,device:a,deviceState:m,lastSeenConfig:c,setDeviceState:d,getDeviceState:u}=n,{endpoint:r}=l,{t:p}=C(["groups","common"]),t=o.useMemo(()=>{const g=[];for(const _ of a.definition?.exposes??[]){const x=y(_,m);if(x&&(g.push(x),g.length===10))break}return g},[a,m]),s=o.useCallback(async g=>await d(a.ieee_address,g),[a.ieee_address,d]),v=o.useCallback(async g=>await u(a.ieee_address,g),[a.ieee_address,u]),f=o.useCallback(async()=>await i(a.ieee_address,r),[a.ieee_address,r,i]);return e.jsx(A,{features:t,device:a,endpoint:r,deviceState:m,onChange:s,onRead:v,featureWrapperClass:E,lastSeenConfig:c,children:e.jsx(D,{onClick:f,className:"btn btn-square btn-outline btn-error btn-sm",title:p("remove_from_group"),modalDescription:p("common:dialog_confirmation_prompt"),modalCancelLabel:p("common:cancel"),children:e.jsx(w,{icon:k})})})}),W=o.memo(n=>{const{group:i}=n,l=b(t=>t.devices),a=b(t=>t.deviceStates),m=b(t=>t.bridgeInfo.config.advanced.last_seen),{sendMessage:c}=o.useContext(j),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(f=>f.ieee_address===s.ieee_address);v&&t.push(e.jsx("div",{className:"w-[23rem] card bg-base-200 rounded-box shadow-md",children:e.jsx(I,{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-center 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-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx(G,{group:n})}),e.jsx("div",{className:"flex-1",children:e.jsx(M,{target:n,deviceState:{}})}),e.jsx("div",{className:"flex-1",children:e.jsx(F,{target:n,deviceState:{}})})]}),e.jsx(W,{group:n})]})}export{te as default};
