import{_ as r,I as d,m as c,u as a,a as l,n as u}from"./index-009d300e.js";const p={components:{DialogAssociation:()=>r(()=>import("./DialogAssociation-2c2de1ff.js"),["./DialogAssociation-2c2de1ff.js","./index-009d300e.js","./index-fe507b7b.css"],import.meta.url)},mixins:[d],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:{...c(a,["nodes","nodesMap"])},mounted(){this.getAssociations()},methods:{...l(a,["showSnackbar"]),getAssociationAddress(s){return{nodeId:s.nodeId,endpoint:s.endpoint===null?void 0:s.endpoint}},getNodeName(s){const t=this.nodes[this.nodesMap.get(s)];return t?t._name:"NodeID_"+s},getEndpointLabel(s,t){const o=this.nodes[this.nodesMap.get(s)];if(o&&t>=0){const e=o.endpoints.find(n=>n.index===t);if(e)return e.label}return t>=0?"Endpoint "+t:"No Endpoint"},async getAssociations(s=!1){let t=!1;s&&this.node.status!=="Dead"&&(t=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,t]);o.success&&(this.associations=o.result,this.showSnackbar("Associations updated","success"))},async addAssociation(s){const t=isNaN(s.target)?s.target.id:parseInt(s.target),o=s.group,e={nodeId:t};o.multiChannel&&s.targetEndpoint>=0&&(e.endpoint=s.targetEndpoint);const n=[this.getAssociationAddress({nodeId:this.node.id,endpoint:s.endpoint}),o.value,[e]],i=await this.app.apiRequest("addAssociations",n);i.success&&(i.result?(this.showSnackbar("Association added","success"),this.getAssociations()):this.showSnackbar("Error while adding association","error")),this.dialogAssociation=!1},async removeAssociation(s){const t=[this.getAssociationAddress({nodeId:this.node.id,endpoint:s.endpoint}),s.groupId,[{nodeId:s.nodeId,endpoint:s.targetEndpoint}]];(await this.app.apiRequest("removeAssociations",t)).success&&(this.showSnackbar("Association removed","success"),this.getAssociations())},async removeAllAssociations(){const s=[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",s)).success&&(this.showSnackbar("Association removed","success"),this.getAssociations())}}};var f=function(){var t=this,o=t._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:t.headers,items:t.associations,"item-key":"id"},scopedSlots:t._u([{key:"top",fn:function(){return[o("v-btn",{staticClass:"mb-2",attrs:{text:"",color:"green"},on:{click:function(e){t.dialogAssociation=!0}}},[t._v("Add")]),o("v-btn",{staticClass:"mb-2",attrs:{text:"",color:"red"},on:{click:t.removeAllAssociations}},[t._v("Remove All")]),o("v-btn",{staticClass:"mb-2",attrs:{text:"",color:"primary"},on:{click:function(e){return t.getAssociations(!0)}}},[t._v("Refresh")])]},proxy:!0},{key:"item.groupId",fn:function({item:e}){return[t._v(" "+t._s(t.node.groups.find(n=>n.value===e.groupId&&n.endpoint===e.endpoint).text)+" ")]}},{key:"item.nodeId",fn:function({item:e}){return[t._v(" "+t._s(t.getNodeName(e.nodeId))+" ")]}},{key:"item.endpoint",fn:function({item:e}){return[t._v(" "+t._s(e.endpoint>=0?t.getEndpointLabel(t.node.id,e.endpoint):"None")+" ")]}},{key:"item.targetEndpoint",fn:function({item:e}){return[t._v(" "+t._s(e.targetEndpoint>=0?t.getEndpointLabel(e.nodeId,e.targetEndpoint):"None")+" ")]}},{key:"item.actions",fn:function({item:e}){return[o("v-icon",{attrs:{small:"",color:"red"},on:{click:function(n){return t.removeAssociation(e)}}},[t._v("delete")])]}}],null,!0)})],1),o("DialogAssociation",{attrs:{node:t.node,associations:t.associations},on:{add:t.addAssociation,close:function(e){t.dialogAssociation=!1}},model:{value:t.dialogAssociation,callback:function(e){t.dialogAssociation=e},expression:"dialogAssociation"}})],1)},g=[],A=u(p,f,g,!1,null,null,null,null);const h=A.exports;export{h as default};
