import{r as m,N as p,e as u,j as e,M as h,f as g,h as x,k as b,B as i,w as j,c as N,a as G,u as f,L as d}from"./index-42f456b7.js";import{T as y}from"./ReactTableCom-7debd434.js";import"./persist-df9114c1.js";const v=t=>{const[r,s]=m.useState(t);return[r,o=>s({...r,[o.currentTarget.name]:o.currentTarget.value})]},w=p.create(t=>{const{name:r,onRename:s}=t,a=u(),[o,l]=v({friendlyName:r}),n=async()=>{await s(r,o.friendlyName),a.remove()};return e.jsxs(h,{isOpen:a.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:l,type:"text",className:"form-control",value:o.friendlyName})]})}),e.jsxs(b,{children:[e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:a.remove,children:"Close"}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Save changes"})]})]})});function C(t){const{t:r}=f(["groups"]),{groups:s,removeGroup:a,renameGroup:o}=t,l=[{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(i,{className:"btn btn-primary",onClick:()=>p.show(w,{name:n.friendly_name,onRename:o}),title:r("rename_group"),children:e.jsx("i",{className:"fa fa-edit"})}),e.jsx(i,{prompt:!0,title:r("remove_group"),item:n.friendly_name,onClick:a,className:"btn btn-danger",children:e.jsx("i",{className:"fa fa-trash"})})]})}];return e.jsx("div",{className:"card",children:e.jsx(y,{id:"groups",columns:l,data:s})})}class _ extends m.Component{constructor(){super(...arguments),this.state={newGroupName:"",newGroupId:void 0},this.changeHandler=r=>{const{name:s,value:a}=r.target;this.setState({[s]:a})},this.onGroupCreateSubmit=()=>{const{newGroupName:r,newGroupId:s}=this.state,{createGroup:a}=this.props;a(r,s)},this.renameGroup=(r,s)=>{const{renameGroup:a}=this.props;a(r,s)}}renderGroupCreationForm(){const{t:r}=this.props,{newGroupName:s,newGroupId:a}=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:s,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:a===void 0?"":a,type:"number",name:"newGroupId",className:"form-control",id:"newGroupId",placeholder:r("new_group_id_placeholder")}),e.jsx(i,{onClick:this.onGroupCreateSubmit,className:"btn btn-primary form-control",children:r("create_group")})]})})})}render(){const{groups:r,removeGroup:s,renameGroup:a}=this.props;return e.jsxs(e.Fragment,{children:[this.renderGroupCreationForm(),e.jsx(C,{groups:r,removeGroup:s,renameGroup:a})]})}}const I=["groups","devices","deviceStates","bridgeInfo"],M=j("groups")(N(I,G)(_));export{M as ConnectedGroupsPage,_ as GroupsPage};
