import{w as g,M as _,b as h,r,j as a,O as N,B as m,a as w,W as C,L as f,F as b,Q as k,R as F,x as S}from"./index-DtyjNqrf.js";import{I as u}from"./InputField-CYbmpJqW.js";import{T as G}from"./Table-BQc_g_eJ.js";import"./envs-DFlyG_dH.js";import"./DebouncedInput-DnWGzIEH.js";const R=g.create(t=>{const{name:i,onRename:o}=t,c=_(),{t:l}=h(["groups","common"]),[s,n]=r.useState(i);return r.useEffect(()=>{n(i)},[i]),a.jsx(N,{isOpen:c.visible,title:`${l("rename_group")} ${i}`,footer:a.jsxs(a.Fragment,{children:[a.jsx(m,{className:"btn btn-neutral",onClick:c.remove,children:l("common:cancel")}),a.jsx(m,{className:"btn btn-primary ms-1",onClick:async()=>{s&&(c.remove(),await o(i,s))},children:l("rename_group")})]}),children:a.jsx("div",{className:"flex flex-col gap-2",children:a.jsx(u,{name:"friendly_name",label:l("common:friendly_name"),onChange:d=>n(d.target.value),value:s,type:"text",required:!0})})})});function $(){const[t,i]=r.useState(""),[o,c]=r.useState(""),l=w(e=>e.groups),{sendMessage:s}=r.useContext(C),{t:n}=h(["groups","common"]),d=r.useCallback(async()=>{const e={friendly_name:t};o&&(e.id=o),await s("bridge/request/group/add",e)},[t,o,s]),p=r.useCallback(async(e,v)=>await s("bridge/request/group/rename",{from:e,to:v}),[s]),x=r.useCallback(async e=>await s("bridge/request/group/remove",{id:e}),[s]),j=r.useMemo(()=>t?!o||!l.find(e=>e.id.toString()===o):!1,[t,o,l]),y=r.useMemo(()=>[{id:"group_id",header:n("group_id"),accessorFn:e=>e.id,cell:({row:{original:e}})=>a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"avatar"}),a.jsxs("div",{className:"flex-grow flex flex-col",children:[a.jsx(f,{to:`/group/${e.id}/devices`,className:"link link-hover",children:e.id}),e.description&&a.jsx("div",{className:"max-w-xs text-xs opacity-50 truncate",title:e.description,children:e.description}),a.jsx("div",{className:"flex flex-row gap-1 mt-0.5",children:a.jsxs("span",{className:"badge badge-soft badge-sm badge-ghost cursor-default",children:[n("scenes"),": ",e.scenes?.length??0]})})]})]})},{id:"friendly_name",header:n("common:friendly_name"),accessorFn:e=>e.friendly_name,cell:({row:{original:e}})=>a.jsx(f,{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},{id:"actions",header:"",cell:({row:{original:e}})=>a.jsxs("div",{className:"join join-horizontal",children:[a.jsx(m,{className:"btn btn-square btn-outline btn-primary join-item",onClick:async()=>await g.show(R,{name:e.friendly_name,onRename:p}),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:x,className:"btn btn-square btn-outline btn-error join-item",modalDescription:n("common:dialog_confirmation_prompt"),modalCancelLabel:n("common:cancel"),children:a.jsx(b,{icon:S})})]}),enableSorting:!1,enableColumnFilter:!1}],[p,x,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(u,{type:"text",name:"friendly_name",label:n("common:friendly_name"),value:t,placeholder:n("friendly_name_placeholder"),onChange:e=>i(e.target.value),required:!0}),a.jsx(u,{type:"number",name:"group_id",label:n("group_id"),value:o,detail:n("common:optional"),min:0,max:255,onChange:e=>c(e.target.value)}),a.jsx(m,{onClick:d,className:"btn btn-primary self-center",disabled:!j,children:n("create_group")})]})})]}),a.jsx(G,{id:"all-groups",columns:y,data:l})]})}export{$ as default};
