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-DtyjNqrf.js";import{g as y,R as M,A as F}from"./RecallRemove-C7or_UUw.js";import{D as N}from"./DevicePicker-_CY2TskL.js";import{E as R}from"./EndpointPicker-Bik90BnT.js";import{D as E}from"./DashboardFeatureWrapper-CWbT-TyR.js";import{D as A}from"./DeviceCard-Bz1iBm0H.js";import"./envs-DFlyG_dH.js";import"./Feature-VsMzzVJz.js";import"./DisplayValue-B5Rw3jLu.js";import"./_createCompounder-CbLsIfEE.js";import"./capitalize-C89IAw35.js";import"./InputField-CYbmpJqW.js";import"./SelectField-DfdnxD7O.js";import"./LastSeen-CvhRQlEh.js";import"./format-6Yb6jWnA.js";import"./Lqi-CoNVuBvb.js";import"./PowerSource-DgFKG_xU.js";import"./snakeCase-DmoQhYQA.js";import"./DeviceImage-D-FjKeE6.js";import"./index-Q3KOJDn9.js";const G=o.memo(n=>{const[i,l]=o.useState(""),[a,m]=o.useState(""),{group:c}=n,d=b(s=>s.devices),p=o.useMemo(()=>h(d.find(s=>s.ieee_address===a)),[a,d]),{t:r}=C(["groups","zigbee"]),{sendMessage:u}=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:p,value:i,onChange:s=>l(s)})]}),e.jsx(S,{onClick:async()=>await u("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:p}=n,{endpoint:r}=l,{t:u}=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 p(a.ieee_address,g),[a.ieee_address,p]),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:u("remove_from_group"),modalDescription:u("common:dialog_confirmation_prompt"),modalCancelLabel:u("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]),p=o.useCallback(async(t,s)=>{await c(`${t}/set`,s)},[c]),r=o.useCallback(async(t,s)=>{await c(`${t}/get`,s)},[c]),u=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:p,getDeviceState:r})},`${s.ieee_address}-${s.endpoint}`))}return t},[i,l,m,a,d,p,r]);return e.jsx("div",{className:"flex flex-row flex-wrap justify-center gap-3",children:u})});function ae({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{ae as default};
