const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DialogAssociation-D0AW8Y0N.js","./index-CpYaRATg.js","./index-BsI52nnX.css"])))=>i.map(i=>d[i]);
import{_ as c,I as l,m as u,u as r,a as p,as as f,at as d,ao as g,n as h}from"./index-CpYaRATg.js";const A={components:{DialogAssociation:()=>c(()=>import("./DialogAssociation-D0AW8Y0N.js"),__vite__mapDeps([0,1,2]),import.meta.url)},mixins:[l],props:{node:Object},data(){return{associations:[],dialogAssociation:!1,headers:[{text:"Endpoint",value:"endpoint"},{text:"Group",value:"groupId"},{text:"Node",value:"nodeId"},{text:"Target Endpoint",value:"targetEndpoint"},{text:"Actions",value:"actions",sortable:!1}]}},computed:{...u(r,["nodes","nodesMap"])},mounted(){this.getAssociations()},methods:{...p(r,["showSnackbar"]),getAssociationAddress:f,getNodeName(e){const s=this.nodes[this.nodesMap.get(e)];return s?s._name:"NodeID_"+e},getEndpointLabel(e,s){const o=this.nodes[this.nodesMap.get(e)];if(o&&s>=0){const t=o.endpoints.find(n=>n.index===s);if(t)return t.label}return s>=0?"Endpoint "+s:"No Endpoint"},async getAssociations(e=!1){let s=!1;e&&this.node.status!=="Dead"&&(s=await this.app.confirm("Info",`Do you want to force query associations?${this.node.status==="Alive"?"":" This node is Asleep, so you should wake it up first."}`,"info"));const o=await this.app.apiRequest("getAssociations",[this.node.id,s]);o.success&&(this.associations=o.result,this.showSnackbar("Associations updated","success"))},async addAssociation(e){const s=isNaN(e.target)?e.target.id:parseInt(e.target),o=e.group,t={nodeId:s};o.multiChannel&&e.targetEndpoint>=0&&(t.endpoint=e.targetEndpoint);const n=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),o.value,[t]],i=await this.app.apiRequest("addAssociations",n);if(i.success){const a=i.result[0];a===d.OK?(this.showSnackbar("Association added","success"),this.getAssociations()):this.showSnackbar(`Error while adding association: ${g(d,a)}`,"error")}this.dialogAssociation=!1},async removeAssociation(e){const s=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),e.groupId,[{nodeId:e.nodeId,endpoint:e.targetEndpoint}]];(await this.app.apiRequest("removeAssociations",s)).success&&(this.showSnackbar("Association removed","success"),this.getAssociations())},async removeAllAssociations(){const e=[this.node.id];if(!await this.app.confirm("Attention","Are you sure you want to remove all associations from this node? This will also remove lifeline association if it exists.","alert"))return;(await this.app.apiRequest("removeAllAssociations",e)).success&&(this.showSnackbar("Association removed","success"),this.getAssociations())}}};var m=function(){var s=this,o=s._self._c;return o("v-container",{attrs:{"grid-list-md":""}},[o("v-row",{staticClass:"pa-5",attrs:{justify:"center"}},[o("v-data-table",{staticClass:"elevation-1",attrs:{headers:s.headers,items:s.associations,"item-key":"id"},scopedSlots:s._u([{key:"top",fn:function(){return[o("v-btn",{staticClass:"mb-2",attrs:{text:"",color:"green"},on:{click:function(t){s.dialogAssociation=!0}}},[s._v("Add")]),o("v-btn",{staticClass:"mb-2",attrs:{text:"",color:"red"},on:{click:s.removeAllAssociations}},[s._v("Remove All")]),o("v-btn",{staticClass:"mb-2",attrs:{text:"",color:"primary"},on:{click:function(t){return s.getAssociations(!0)}}},[s._v("Refresh")])]},proxy:!0},{key:"item.groupId",fn:function({item:t}){return[s._v(" "+s._s(s.node.groups.find(n=>n.value===t.groupId&&n.endpoint===t.endpoint).text)+" ")]}},{key:"item.nodeId",fn:function({item:t}){return[s._v(" "+s._s(s.getNodeName(t.nodeId))+" ")]}},{key:"item.endpoint",fn:function({item:t}){return[s._v(" "+s._s(t.endpoint>=0?s.getEndpointLabel(s.node.id,t.endpoint):"None")+" ")]}},{key:"item.targetEndpoint",fn:function({item:t}){return[s._v(" "+s._s(t.targetEndpoint>=0?s.getEndpointLabel(t.nodeId,t.targetEndpoint):"None")+" ")]}},{key:"item.actions",fn:function({item:t}){return[o("v-icon",{attrs:{small:"",color:"red"},on:{click:function(n){return s.removeAssociation(t)}}},[s._v("delete")])]}}],null,!0)})],1),o("DialogAssociation",{attrs:{node:s.node,associations:s.associations},on:{add:s.addAssociation,close:function(t){s.dialogAssociation=!1}},model:{value:s.dialogAssociation,callback:function(t){s.dialogAssociation=t},expression:"dialogAssociation"}})],1)},v=[],_=h(A,m,v,!1,null,null);const k=_.exports;export{k as default};
