import{r as j,o as D,u as f,j as e,B as b,p as N,c as y,a as G}from"./index-d7144f09.js";import{D as E,E as R,o as w,R as F,A as C}from"./RecallRemove-f55fbd1c.js";import{D as P}from"./DashboardDevice-d8606518.js";import{D as A}from"./DashboardFeatureWrapper-0c66c31d.js";import"./index-f85611b2.js";import"./powerSourceTypeToTranslationKey-452dac81.js";import"./DeviceImage-d3f7881d.js";import"./index-46206196.js";import"./isEqual-1554d10e.js";function k(n){const[c,i]=j.useState(""),[r,m]=j.useState(""),{addDeviceToGroup:v,group:d,devices:t}=n,l=t[r],o=D(l),{t:s}=f(["groups","zigbee"]),u=()=>{v(r,c,d.friendly_name)},g=a=>{const x=D(a);m(a.ieee_address),i(x[0])},p=a=>{i(a)};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:o,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,o=m[l]??{ieee_address:l,friendly_name:c("unknown_device")},s=v[o.friendly_name]??{},{setDeviceState:u,getDeviceState:g}=n;let p=[];return o.definition&&(p=(o.definition.exposes??[]).map(a=>w(a,s)).filter(a=>a!=null)),e.jsx(P,{feature:{features:p},device:o,endpoint:t,deviceState:s,onChange:(a,x)=>u(o.friendly_name,x),onRead:(a,x)=>g(o.friendly_name,x),featureWrapperClass:A,lastSeenType:d.config.advanced.last_seen,controls:e.jsx(b,{prompt:!0,onClick:()=>i(o.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,o=(s,u)=>i(s,u,c.friendly_name);return e.jsx("div",{className:"row",children:c.members.map(s=>e.jsx(I,{removeDeviceFromGroup:o,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:o,getDeviceState:s}=n,{addDeviceToGroup:u,removeDeviceFromGroup:g}=n,{sceneStore:p,sceneRemoveAll:a,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: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(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:o,getDeviceState:s})]})}const V=N(z),W=["groups","devices","deviceStates","bridgeInfo"],X=y(W,G)(V);export{X as ConnectedGroupPage};
