import{_ as I,a as N,I as C,e as m,w as r,b as i,q as x,l as c,k as d,t as g,f,V as b,D as v,i as y,u as G,x as V,z as h,am as w}from"./index-DaawSADr.js";import{V as _}from"./VDataTable-BCkODPS0.js";import"./sort-Dnf7GxuH.js";import"./VTable-Cai5aYBf.js";const S={name:"Groups",mixins:[C],components:{},computed:{...N(V,["nodes"]),physicalNodes(){return this.nodes.filter(s=>!s.virtual)}},data(){return{search:"",groups:[],headers_groups:[{title:"Name",key:"name"},{title:"Nodes",key:"nodeIds"},{title:"Actions",key:"actions",sortable:!1}]}},methods:{exportGroups(){this.app.exportConfiguration(this.groups,"groups")},getNodeNames(s){return s.map(e=>{const l=this.nodes.find(u=>u.id===e);return l?l.name||`Node ${e}`:`Node ${e}`})},async refreshGroups(){const s=await this.app.apiRequest("_getGroups",[],{infoSnack:!1,errorSnack:!0});s.success&&(this.groups=s.result||[])},async editItem(s){const e=!!s,l=this.physicalNodes.filter(t=>!t.isControllerNode);let u=[{type:"text",label:"Group Name",required:!0,key:"name",hint:"Enter a descriptive name for this multicast group",default:e?s.name:""},{type:"list",label:"Nodes",required:!0,key:"nodeIds",multiple:!0,items:l.map(t=>{const n=t.manufacturer||"",p=t.productDescription||t.productLabel||"",k=n?`${n}${p?" "+p:""}`:p;return{title:k?`Node ${t.id} - ${k}`:t.name||`Node ${t.id}`,value:t.id}}),hint:"Select at least 2 nodes for the multicast group (controller excluded)",default:e?s.nodeIds:[],rules:[t=>!t||t.length<2?"Please select at least 2 nodes":!0]}],a=await this.app.confirm(e?"Edit Group":"Create Group","","info",{confirmText:e?"Update":"Create",width:500,inputs:u});if(!a||Object.keys(a).length===0)return;if(!a.name||!a.nodeIds||a.nodeIds.length<2){this.showSnackbar("Please provide a name and select at least 2 nodes","error");return}let o;if(e?o=await this.app.apiRequest("_updateGroup",[s.id,a.name,a.nodeIds]):o=await this.app.apiRequest("_createGroup",[a.name,a.nodeIds]),o.success&&o.result){const t=o.result,n=this.groups.findIndex(p=>p.id===t.id);n>=0?this.groups.splice(n,1,t):this.groups.push(t),this.showSnackbar(`Group ${e?"updated":"created"}`,"success")}},async deleteItem(s){if(await this.app.confirm("Attention",`Are you sure you want to delete group "${s.name}"? This will also remove the virtual node.`,"alert")&&(await this.app.apiRequest("_deleteGroup",[s.id])).success){const l=this.groups.findIndex(u=>u.id===s.id);l>=0&&this.groups.splice(l,1),this.showSnackbar("Group deleted","success")}}},mounted(){this.refreshGroups()}};function q(s,e,l,u,a,o){return h(),m(G,{fluid:"",class:"pa-4"},{default:r(()=>[i(_,{headers:a.headers_groups,items:a.groups,search:a.search,class:"elevation-1"},{top:r(()=>[i(f,{class:"pt-0"},{default:r(()=>[i(b,null,{default:r(()=>[i(f,{cols:"12",sm:"6"},{default:r(()=>[i(v,{modelValue:a.search,"onUpdate:modelValue":e[0]||(e[0]=t=>a.search=t),clearable:"",flat:"",variant:"outlined","hide-details":"","single-line":"",class:"ma-2",style:{"max-width":"300px","min-width":"250px"},"prepend-inner-icon":"search",label:"Search","append-icon":"refresh","onClick:append":o.refreshGroups},null,8,["modelValue","onClick:append"])]),_:1}),i(f,{cols:"12",sm:"6",class:"d-flex align-center justify-end"},{default:r(()=>[i(y,{color:"primary",onClick:e[1]||(e[1]=t=>o.editItem())},{default:r(()=>[i(c,{start:""},{default:r(()=>[...e[2]||(e[2]=[d("add",-1)])]),_:1}),e[3]||(e[3]=d(" Create Group ",-1))]),_:1}),i(y,{variant:"text",onClick:o.exportGroups},{default:r(()=>[e[5]||(e[5]=d(" Export ",-1)),i(c,{end:"",color:"primary"},{default:r(()=>[...e[4]||(e[4]=[d("file_download",-1)])]),_:1})]),_:1},8,["onClick"])]),_:1})]),_:1})]),_:1})]),"item.nodeIds":r(({item:t})=>[d(g(t.nodeIds.length)+" node(s): "+g(o.getNodeNames(t.nodeIds).join(", ")),1)]),"item.actions":r(({item:t})=>[x((h(),m(c,{size:"small",color:"success",class:"mr-2",onClick:n=>o.editItem(t)},{default:r(()=>[...e[6]||(e[6]=[d("edit",-1)])]),_:1},8,["onClick"])),[[w,"Edit","bottom"]]),x((h(),m(c,{size:"small",color:"error",onClick:n=>o.deleteItem(t)},{default:r(()=>[...e[7]||(e[7]=[d("delete",-1)])]),_:1},8,["onClick"])),[[w,"Delete","bottom"]])]),_:2},1032,["headers","items","search"])]),_:1})}const $=I(S,[["render",q]]);export{$ as default};
