import{w as h,E as v,b as j,r as o,j as a,M as N,B as d,a as w,W as C,L as g,F as b,G as k,I as F,x as S,J as G}from"./index-vDL8KyrI.js";import{I as p}from"./InputField-B5sOh_uD.js";import{T as E}from"./Table-DDSIa7cd.js";import"./DebouncedInput-DpBqTOhq.js";const R=h.create(i=>{const{name:t,onRename:r}=i,c=v(),{t:l}=j(["groups","common"]),[s,n]=o.useState(t);return o.useEffect(()=>{n(t)},[t]),a.jsx(N,{isOpen:c.visible,title:`${l("rename_group")} ${t}`,footer:a.jsxs(a.Fragment,{children:[a.jsx(d,{className:"btn btn-secondary",onClick:c.remove,children:l("common:cancel")}),a.jsx(d,{className:"btn btn-primary ms-1",onClick:async()=>{s&&(c.remove(),await r(t,s))},children:l("rename_group")})]}),children:a.jsx("div",{className:"flex flex-col gap-2",children:a.jsx(p,{name:"friendly_name",label:l("common:friendly_name"),onChange:u=>n(u.target.value),value:s,type:"text",required:!0})})})});function T(){const[i,t]=o.useState(""),[r,c]=o.useState(""),l=w(e=>e.groups),{sendMessage:s}=o.useContext(C),{t:n}=j(["groups","common"]),u=o.useCallback(async()=>{const e={friendly_name:i};r!==void 0&&(e.id=r),await s("bridge/request/group/add",e)},[i,r,s]),x=o.useCallback(async(e,m)=>await s("bridge/request/group/rename",{from:e,to:m}),[s]),f=o.useCallback(async e=>await s("bridge/request/group/remove",{id:e}),[s]),y=o.useMemo(()=>i?!r||!l.find(e=>e.id.toString()===r):!1,[i,r,l]),_=o.useMemo(()=>[{id:"group_id",header:n("group_id"),accessorFn:e=>e.id,cell:({row:{original:e}})=>{var m;return a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"avatar"}),a.jsxs("div",{className:"flex flex-col",children:[a.jsx(g,{to:`/group/${e.id}/devices`,className:"link link-hover",children:e.id}),e.description&&a.jsx("div",{className:"text-xs opacity-50",children:e.description}),a.jsx("div",{className:"flex flex-row gap-1 mt-2",children:a.jsxs("span",{className:"badge badge-soft badge-ghost cursor-default",children:[n("scenes"),": ",((m=e.scenes)==null?void 0:m.length)??0]})})]})]})}},{id:"friendly_name",header:n("common:friendly_name"),accessorFn:e=>e.friendly_name,cell:({row:{original:e}})=>a.jsx(g,{to:`/group/${e.id}/devices`,className:"link link-hover",children:e.friendly_name})},{id:"members",header:n("group_members"),accessorFn:e=>e.members.length??0,enableColumnFilter:!1},{header:"",id:"actions",cell:({row:{original:e}})=>a.jsxs("div",{className:"join join-vertical lg:join-horizontal",children:[a.jsx(d,{className:"btn btn-primary btn-sm join-item",onClick:async()=>await h.show(R,{name:e.friendly_name,onRename:x}),title:n("rename_group"),disabled:e.friendly_name==="default_bind_group",children:a.jsx(b,{icon:k})}),a.jsx(F,{title:n("remove_group"),item:e.id.toString(),onClick:f,className:"btn btn-error btn-sm join-item",modalDescription:n("common:dialog_confirmation_prompt"),modalCancelLabel:n("common:cancel"),children:a.jsx(b,{icon:S})})]}),enableSorting:!1,enableColumnFilter:!1}],[x,f,n]);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"collapse collapse-arrow bg-base-100 shadow mb-3",children:[a.jsx("input",{type:"checkbox"}),a.jsx("div",{className:"collapse-title text-lg font-semibold text-center",children:n("create_group")}),a.jsx("div",{className:"collapse-content",children:a.jsxs("div",{className:"flex flex-row flex-wrap justify-center gap-2",children:[a.jsx(p,{type:"text",name:"friendly_name",label:n("common:friendly_name"),value:i,placeholder:n("friendly_name_placeholder"),onChange:e=>t(e.target.value),required:!0}),a.jsx(p,{type:"number",name:"group_id",label:n("group_id"),value:r,detail:n("common:optional"),min:0,max:255,onChange:e=>c(e.target.value)}),a.jsx(d,{onClick:u,className:"btn btn-primary self-center",disabled:!y,children:n("create_group")})]})})]}),a.jsx(E,{id:"all-groups",columns:_,data:l,pageSizeStoreKey:G})]})}export{T as default};
