var __decorate=this&&this.__decorate||function(e,t,s,l){var i,o=arguments.length,c=o<3?t:null===l?l=Object.getOwnPropertyDescriptor(t,s):l;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,s,l);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(c=(o<3?i(c):o>3?i(t,s,c):i(t,s))||c);return o>3&&c&&Object.defineProperty(t,s,c),c};import{LitElement as e}from"lit";import{property as t}from"lit/decorators.js";import{input as s}from"./flow-editor";import{i18next as l,translate as i}from"@openremote/or-translate";export class SelectableElement extends i(l)(e){constructor(){super(...arguments),this.isSelected=!1,this.onSelected=e=>{e===this&&(this.isSelected=!0)},this.onDeselected=e=>{e===this&&(this.isSelected=!1)},this.handleSelection=e=>{1===e.buttons?(s.handleSelection(this),e.stopPropagation()):2===e.buttons&&s.handleSelection(this,!0)}}get selected(){return this.isSelected}get handle(){return this.selectableHandle}disconnectedCallback(){super.disconnectedCallback(),this.selected&&s.selected.splice(s.selected.indexOf(this),1),this.isSelected=!1,s.removeListener("selected",this.onSelected),s.removeListener("deselected",this.onDeselected),s.selectables.splice(s.selectables.indexOf(this),1)}setHandle(e){this.selectableHandle&&this.selectableHandle.removeEventListener("mousedown",this.handleSelection),e.addEventListener("mousedown",this.handleSelection),this.selectableHandle=e}firstUpdated(){this.setHandle(this),s.selectables.push(this),s.addListener("selected",this.onSelected),s.addListener("deselected",this.onDeselected)}}__decorate([t({type:Boolean})],SelectableElement.prototype,"isSelected",void 0),__decorate([t({attribute:!1})],SelectableElement.prototype,"selectableHandle",void 0);