import{N as m,e as p,h as u,j as e,M as h,k as g,m as x,n as b,r as j,B as l,w as N,c as G,a as y,u as f,L as d}from"./index-d7144f09.js";import{T as w}from"./ReactTableCom-3efca1fa.js";import"./persist-6220a907.js";const _=m.create(o=>{const{name:r,onRename:a}=o,s=p(),[t,i]=u({friendlyName:r}),n=async()=>{await a(r,t.friendlyName),s.remove()};return e.jsxs(h,{isOpen:s.visible,children:[e.jsxs(g,{children:[e.jsx("h3",{children:"Rename group"}),e.jsx("small",{children:r})]}),e.jsx(x,{children:e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Friendly name"}),e.jsx("input",{name:"friendlyName",onChange:i,type:"text",className:"form-control",value:t.friendlyName})]})}),e.jsxs(b,{children:[e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:s.remove,children:"Close"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Save changes"})]})]})});function v(o){const{t:r}=f(["groups"]),{groups:a,removeGroup:s,renameGroup:t}=o,i=[{id:"group_id",Header:r("group_id"),accessor:n=>n.id,Cell:({row:{original:n}})=>e.jsx(d,{to:`/group/${n.id}`,children:n.id})},{id:"friendly_name",Header:r("group_name"),accessor:n=>n.friendly_name,Cell:({row:{original:n}})=>e.jsx(d,{to:`/group/${n.id}`,children:n.friendly_name})},{id:"members",Header:r("group_members"),accessor:n=>n.members.length??0},{id:"scenes",Header:r("group_scenes"),accessor:n=>{var c;return((c=n.scenes)==null?void 0:c.length)??0}},{Header:"",id:"actions",Cell:({row:{original:n}})=>e.jsxs("div",{className:"btn-group float-right btn-group-sm",role:"group",children:[e.jsx(l,{className:"btn btn-primary",onClick:()=>m.show(_,{name:n.friendly_name,onRename:t}),title:r("rename_group"),children:e.jsx("i",{className:"fa fa-edit"})}),e.jsx(l,{prompt:!0,title:r("remove_group"),item:n.friendly_name,onClick:s,className:"btn btn-danger",children:e.jsx("i",{className:"fa fa-trash"})})]})}];return e.jsx("div",{className:"card",children:e.jsx(w,{id:"groups",columns:i,data:a})})}class C extends j.Component{constructor(){super(...arguments),this.state={newGroupName:"",newGroupId:void 0},this.changeHandler=r=>{const{name:a,value:s}=r.target;this.setState({[a]:s})},this.onGroupCreateSubmit=()=>{const{newGroupName:r,newGroupId:a}=this.state,{createGroup:s}=this.props;s(r,a)},this.renameGroup=(r,a)=>{const{renameGroup:s}=this.props;s(r,a)}}renderGroupCreationForm(){const{t:r}=this.props,{newGroupName:a,newGroupId:s}=this.state;return e.jsx("div",{className:"card",children:e.jsx("div",{className:"card-body",children:e.jsxs("div",{className:"input-group",children:[e.jsx("label",{htmlFor:"newGroupName",className:"sr-only",children:r("new_group_name")}),e.jsx("input",{onChange:this.changeHandler,value:a,required:!0,type:"text",name:"newGroupName",className:"form-control",id:"newGroupName",placeholder:r("new_group_name_placeholder")}),e.jsx("label",{htmlFor:"newGroupName",className:"sr-only",children:r("new_group_id")}),e.jsx("input",{onChange:this.changeHandler,value:s===void 0?"":s,type:"number",name:"newGroupId",className:"form-control",id:"newGroupId",placeholder:r("new_group_id_placeholder")}),e.jsx(l,{onClick:this.onGroupCreateSubmit,className:"btn btn-primary form-control",children:r("create_group")})]})})})}render(){const{groups:r,removeGroup:a,renameGroup:s}=this.props;return e.jsxs(e.Fragment,{children:[this.renderGroupCreationForm(),e.jsx(v,{groups:r,removeGroup:a,renameGroup:s})]})}}const F=["groups","devices","deviceStates","bridgeInfo"],M=N("groups")(G(F,y)(C));export{M as ConnectedGroupsPage,C as GroupsPage};
