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