import{__extends}from"tslib";import{L as ListenerAbstract,a as SingleSubject}from"./listener-8c6f024a.js";import{b as balBrowser}from"./browser-216e7b03.js";var BalElementStateListener=function(t){__extends(e,t);function e(){var n=t.apply(this,arguments)||this;n.state=e.DefaultState;n.onMouseEnter=function(){n.updateState({hovered:true})};n.onMouseLeave=function(){n.updateState({hovered:false})};n.onPointerDown=function(){n.updateState({pressed:true})};n.onPointerUp=function(){n.updateState({pressed:false})};return n}e.prototype.connect=function(n){t.prototype.connect.call(this,n);n.addEventListener("mouseenter",this.onMouseEnter,e.EventListenerOptions);n.addEventListener("mouseleave",this.onMouseLeave,e.EventListenerOptions);n.addEventListener("pointerdown",this.onPointerDown,e.EventListenerOptions);if(balBrowser.hasDocument){document.addEventListener("pointerup",this.onPointerUp,e.EventListenerOptions)}};e.prototype.disconnect=function(){t.prototype.disconnect.call(this);if(this.el){this.el.removeEventListener("mouseenter",this.onMouseEnter);this.el.removeEventListener("mouseleave",this.onMouseLeave);this.el.removeEventListener("pointerdown",this.onPointerDown);if(balBrowser.hasDocument){document.removeEventListener("pointerup",this.onPointerUp)}}};e.prototype.updateState=function(t){this.state=Object.assign(Object.assign({},this.state),t);this.notify(this.state)};return e}(ListenerAbstract);BalElementStateListener.EventListenerOptions={passive:true};BalElementStateListener.DefaultState={hovered:false,pressed:false};var BalElementStateSubject=function(t){__extends(e,t);function e(){var e=t.call(this,(function(t,e){if(e){t.elementStateListener(e)}}))||this;e.listener=new BalElementStateListener;return e}e.prototype.attach=function(e){var n=this;t.prototype.attach.call(this,e);this.listener.connect(e.el);this.listener.add((function(e){return t.prototype.notify.call(n,e)}))};e.prototype.detach=function(){t.prototype.detach.call(this);this.listener.disconnect()};return e}(SingleSubject);function ListenToElementStates(){return function(t,e,n){var s=t.connectedCallback,i=t.disconnectedCallback;t.connectedCallback=function(){this._balElementStateSubject=new BalElementStateSubject;this._balElementStateSubject.attach(this);return s&&s.call(this)};t.disconnectedCallback=function(){this._balElementStateSubject.detach();return i&&i.call(this)}}}export{BalElementStateListener as B,ListenToElementStates as L};