const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DialogAssociation-Y8bKHfLS.js","./index-Ms_1iFoB.js","./index-2j-kvxFz.css"])))=>i.map(i=>d[i]);
import{_ as d,I as l,m as u,u as r,a as p,av as f,aw as c,ar as g,n as h}from"./index-Ms_1iFoB.js";const m={components:{DialogAssociation:()=>d(()=>import("./DialogAssociation-Y8bKHfLS.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 t=this.nodes[this.nodesMap.get(e)];return t?t._name:"NodeID_"+e},getEndpointLabel(e,t){const o=this.nodes[this.nodesMap.get(e)];if(o&&t>=0){const s=o.endpoints.find(n=>n.index===t);if(s)return s.label}return t>=0?"Endpoint "+t:"No Endpoint"},async getAssociations(e=!1){let t=!1;e&&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",{confirmText:"Yes",cancelText:"No"}));const o=await this.app.apiRequest("getAssociations",[this.node.id,t]);o.success&&(this.associations=o.result,this.showSnackbar("Associations updated","success"))},async addAssociation(e){const t=isNaN(e.target)?e.target.id:parseInt(e.target),o=e.group,s={nodeId:t};o.multiChannel&&e.targetEndpoint>=0&&(s.endpoint=e.targetEndpoint);const n=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),o.value,[s]],i=await this.app.apiRequest("addAssociations",n);if(i.success){const a=i.result[0];a===c.OK?(this.showSnackbar("Association added","success"),this.getAssociations()):this.showSnackbar(`Error while adding association: ${g(c,a)}`,"error")}this.dialogAssociation=!1},async removeAssociation(e){const t=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),e.groupId,[{nodeId:e.nodeId,endpoint:e.targetEndpoint}]];(await this.app.apiRequest("removeAssociations",t)).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 A=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(s){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(s){return t.getAssociations(!0)}}},[t._v("Refresh")])]},proxy:!0},{key:"item.groupId",fn:function({item:s}){return[t._v(" "+t._s(t.node.groups.find(n=>n.value===s.groupId&&n.endpoint===s.endpoint).text)+" ")]}},{key:"item.nodeId",fn:function({item:s}){return[t._v(" "+t._s(t.getNodeName(s.nodeId))+" ")]}},{key:"item.endpoint",fn:function({item:s}){return[t._v(" "+t._s(s.endpoint>=0?t.getEndpointLabel(t.node.id,s.endpoint):"None")+" ")]}},{key:"item.targetEndpoint",fn:function({item:s}){return[t._v(" "+t._s(s.targetEndpoint>=0?t.getEndpointLabel(s.nodeId,s.targetEndpoint):"None")+" ")]}},{key:"item.actions",fn:function({item:s}){return[o("v-icon",{attrs:{small:"",color:"red"},on:{click:function(n){return t.removeAssociation(s)}}},[t._v("delete")])]}}],null,!0)})],1),o("DialogAssociation",{attrs:{node:t.node,associations:t.associations},on:{add:t.addAssociation,close:function(s){t.dialogAssociation=!1}},model:{value:t.dialogAssociation,callback:function(s){t.dialogAssociation=s},expression:"dialogAssociation"}})],1)},v=[],_=h(m,A,v,!1,null,null);const k=_.exports;export{k as default};
