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-6a654fd1.js";import{D as E,E as R,o as w,R as F,A as C}from"./RecallRemove-d7ec1c96.js";import{D as P}from"./DashboardDevice-42d2020b.js";import{D as A}from"./DashboardFeatureWrapper-da048f13.js";import"./index-3e75459d.js";import"./powerSourceTypeToTranslationKey-452dac81.js";import"./DeviceImage-8f8abcdd.js";import"./index-f13e0cb5.js";import"./isEqual-a00f752b.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};
