const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DialogAssociation-CgU7GryV.js","./index-DaawSADr.js","./index-BJG3nE28.css"])))=>i.map(i=>d[i]);
import{_ as v,e7 as y,a as k,I as w,d as N,s as b,e as m,z as A,w as t,b as d,V as I,h as E,O as x,k as r,t as c,H as f,l as V,i as g,u as C,e8 as h,dD as R,az as _,x as D,y as L}from"./index-DaawSADr.js";import{V as S}from"./VDataTable-BCkODPS0.js";import"./sort-Dnf7GxuH.js";import"./VTable-Cai5aYBf.js";const T={components:{DialogAssociation:N(()=>L(()=>import("./DialogAssociation-CgU7GryV.js"),__vite__mapDeps([0,1,2]),import.meta.url))},mixins:[w],props:{node:Object},data(){return{associations:[],dialogAssociation:!1,headers:[{title:"Endpoint",key:"endpoint"},{title:"Group",key:"groupName"},{title:"Group ID",key:"groupId"},{title:"Node",key:"nodeId"},{title:"Target Endpoint",key:"targetEndpoint"},{title:"Actions",key:"actions",sortable:!1}]}},computed:{...k(D,["nodes","nodesMap"]),isLongRange(){return this.node?.protocol===_.ZWaveLongRange},showAssociationWarning(){return this.isLongRange},associationWarningMessage(){return"This Z-Wave Long Range node only supports lifeline associations. Non-lifeline associations may not function correctly."}},mounted(){this.getAssociations()},methods:{getAssociationAddress:y,getNodeName(e){const s=this.nodes[this.nodesMap.get(e)];return s?s._name:"NodeID_"+e},getEndpointLabel(e,s){const i=this.nodes[this.nodesMap.get(e)];if(i&&s>=0){const l=i.endpoints.find(n=>n.index===s);if(l)return l.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",{confirmText:"Yes",cancelText:"No"}));const i=await this.app.apiRequest("getAssociations",[this.node.id,s]);i.success&&(this.associations=i.result,this.showSnackbar("Associations updated","success"))},async addAssociation(e,s=!1){const i=isNaN(e.target)?e.target.id:parseInt(e.target),l=e.group,n={nodeId:i};l.multiChannel&&e.targetEndpoint>=0&&(n.endpoint=e.targetEndpoint);const a=[this.getAssociationAddress({nodeId:this.node.id,endpoint:e.endpoint}),l.value,[n],s?{force:!0}:void 0],p=await this.app.apiRequest("addAssociations",a);if(p.success){const o=p.result[0];o===h.OK||s?(this.showSnackbar("Association added","success"),this.getAssociations()):this.showSnackbar(`Error while adding association: ${R(h,o)}`,"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())}}},M={class:"d-flex"};function W(e,s,i,l,n,a){const p=b("DialogAssociation");return A(),m(C,{"grid-list-md":""},{default:t(()=>[d(I,{justify:"center",class:"pa-5"},{default:t(()=>[a.showAssociationWarning?(A(),m(x,{key:0,type:"warning",variant:"tonal",class:"mb-4",closable:""},{title:t(()=>[...s[4]||(s[4]=[f("strong",null,"Limited Association Support",-1)])]),default:t(()=>[r(" "+c(a.associationWarningMessage),1)]),_:1})):E("",!0),d(S,{headers:n.headers,items:n.associations,"item-key":"id",class:"elevation-1"},{top:t(()=>[f("div",M,[d(g,{variant:"text",color:"success",onClick:s[0]||(s[0]=o=>n.dialogAssociation=!0),class:"mb-2"},{default:t(()=>[...s[5]||(s[5]=[r("Add",-1)])]),_:1}),d(g,{variant:"text",color:"error",onClick:a.removeAllAssociations,class:"mb-2"},{default:t(()=>[...s[6]||(s[6]=[r("Remove All",-1)])]),_:1},8,["onClick"]),d(g,{variant:"text",color:"primary",onClick:s[1]||(s[1]=o=>a.getAssociations(!0)),class:"mb-2"},{default:t(()=>[...s[7]||(s[7]=[r("Refresh",-1)])]),_:1})])]),"item.groupName":t(({item:o})=>[r(c(i.node.groups.find(u=>u.value===o.groupId&&u.endpoint===o.endpoint).title),1)]),"item.nodeId":t(({item:o})=>[r(c(a.getNodeName(o.nodeId)),1)]),"item.endpoint":t(({item:o})=>[r(c(o.endpoint>=0?a.getEndpointLabel(i.node.id,o.endpoint):"None"),1)]),"item.targetEndpoint":t(({item:o})=>[r(c(o.targetEndpoint>=0?a.getEndpointLabel(o.nodeId,o.targetEndpoint):"None"),1)]),"item.actions":t(({item:o})=>[d(V,{size:"small",color:"error",onClick:u=>a.removeAssociation(o)},{default:t(()=>[...s[8]||(s[8]=[r("delete",-1)])]),_:1},8,["onClick"])]),_:2},1032,["headers","items"])]),_:1}),d(p,{onAdd:a.addAssociation,onClose:s[2]||(s[2]=o=>n.dialogAssociation=!1),modelValue:n.dialogAssociation,"onUpdate:modelValue":s[3]||(s[3]=o=>n.dialogAssociation=o),node:i.node,associations:n.associations},null,8,["onAdd","modelValue","node","associations"])]),_:1})}const G=v(T,[["render",W]]);export{G as default};
