import{r as j,m as D,u as f,j as e,B as b,n as N,c as y,a as G}from"./index-a77bd902.js";import{D as E,E as R,o as w,R as F,A as C}from"./RecallRemove-c6183301.js";import{D as P}from"./DashboardDevice-c02266db.js";import{D as A}from"./DashboardFeatureWrapper-fc8d0f26.js";import"./index-6ddbc65b.js";import"./powerSourceTypeToTranslationKey-452dac81.js";import"./DeviceImage-3bec68ff.js";import"./index-f7288b4b.js";import"./isEqual-997da78b.js";function k(n){const[c,i]=j.useState(""),[r,m]=j.useState(""),{addDeviceToGroup:v,group:d,devices:t}=n,l=t[r],a=D(l),{t:s}=f(["groups","zigbee"]),u=()=>{v(r,c,d.friendly_name)},g=o=>{const x=D(o);m(o.ieee_address),i(x[0])},p=o=>{i(o)};return e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:s("add_to_group_header")}),e.jsxs("div",{className:"mb-3",children:[e.jsx(E,{label:s("zigbee:device"),value:r,devices:t,onChange:g}),e.jsx(R,{label:s("zigbee:endpoint"),values:a,value:c,onChange:p})]}),e.jsx("div",{className:"d-flex",children:e.jsx("div",{className:"ms-auto",children:e.jsx(b,{type:"button",onClick:u,className:"btn btn-primary",children:s("add_to_group")})})})]})}function I(n){const{t:c}=f("devicePage"),{removeDeviceFromGroup:i,groupAddress:r,devices:m,deviceStates:v,bridgeInfo:d}=n,{endpoint:t,ieee_address:l}=r,a=m[l]??{ieee_address:l,friendly_name:c("unknown_device")},s=v[a.friendly_name]??{},{setDeviceState:u,getDeviceState:g}=n;let p=[];return a.definition&&(p=(a.definition.exposes??[]).map(o=>w(o,s)).filter(o=>o!=null)),e.jsx(P,{feature:{features:p},device:a,endpoint:t,deviceState:s,onChange:(o,x)=>u(a.friendly_name,x),onRead:(o,x)=>g(a.friendly_name,x),featureWrapperClass:A,lastSeenType:d.config.advanced.last_seen,controls:e.jsx(b,{prompt:!0,onClick:()=>i(a.friendly_name,t),className:"btn btn-danger btn-sm float-right",children:e.jsx("i",{className:"fa fa-trash"})})})}function T(n){const{group:c,removeDeviceFromGroup:i,devices:r,deviceStates:m,bridgeInfo:v}=n,{setStateValue:d,setDeviceState:t,getDeviceState:l}=n,a=(s,u)=>i(s,u,c.friendly_name);return e.jsx("div",{className:"row",children:c.members.map(s=>e.jsx(I,{removeDeviceFromGroup:a,devices:r,groupAddress:s,deviceStates:m,bridgeInfo:v,setStateValue:d,setDeviceState:t,getDeviceState:l},`${s.ieee_address}-${s.endpoint}`))})}function z(n){const{devices:c,deviceStates:i,bridgeInfo:r,groups:m}=n,{match:v}=n,d=parseInt(v.params.groupId,10),t=m.find(h=>h.id===d)||{id:d,friendly_name:"Unknown group",members:[],scenes:[]},{setStateValue:l,setDeviceState:a,getDeviceState:s}=n,{addDeviceToGroup:u,removeDeviceFromGroup:g}=n,{sceneStore:p,sceneRemoveAll:o,sceneRecall:x,sceneRemove:S}=n,{t:_}=f(["groups"]);return e.jsxs("div",{children:[e.jsxs("h5",{children:[_("group_name"),": ",t.friendly_name," (#",t.id,")"]}),e.jsxs("div",{className:"row",children:[e.jsx("div",{className:"col-12 col-sm-4 col-xxl-4 d-flex",children:e.jsx("div",{className:"card w-100",children:e.jsx("div",{className:"card-body",children:e.jsx("div",{className:"form-group",children:e.jsx(k,{addDeviceToGroup:u,devices:c,group:t})})})})}),e.jsx("div",{className:"col-12 col-sm-4 col-xxl-4 d-flex",children:e.jsx("div",{className:"card w-100",children:e.jsx("div",{className:"card-body",children:e.jsx("div",{className:"form-group",children:e.jsx(F,{target:t,sceneStore:p,sceneRecall:x,sceneRemove:S,sceneRemoveAll:o,deviceState:{}})})})})}),e.jsx("div",{className:"col-12 col-sm-4 col-xxl-4 d-flex",children:e.jsx("div",{className:"card w-100",children:e.jsx("div",{className:"card-body",children:e.jsx("div",{className:"form-group",children:e.jsx(C,{sceneStore:p,target:t,deviceState:{},setDeviceState:(h,B)=>Promise.resolve()})})})})})]}),e.jsx(T,{group:t,devices:c,deviceStates:i,bridgeInfo:r,removeDeviceFromGroup:g,setStateValue:l,setDeviceState:a,getDeviceState:s})]})}const V=N(z),W=["groups","devices","deviceStates","bridgeInfo"],X=y(W,G)(V);export{X as ConnectedGroupPage};
