import{__extends}from"tslib";import{L as ListenerAbstract,a as SingleSubject}from"./listener-Cwtj-tmC.js";import{U as addEventListener,a as balBrowser,V as removeEventListener}from"./index-DGWPFpP6.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);addEventListener(this.el,"mouseenter",this.onMouseEnter,e.EventListenerOptions);addEventListener(this.el,"mouseleave",this.onMouseLeave,e.EventListenerOptions);addEventListener(this.el,"pointerdown",this.onPointerDown,e.EventListenerOptions);if(balBrowser.hasDocument){addEventListener(document,"pointerup",this.onPointerUp,e.EventListenerOptions)}};e.prototype.disconnect=function(){t.prototype.disconnect.call(this);if(this.el){removeEventListener(this.el,"mouseenter",this.onMouseEnter);removeEventListener(this.el,"mouseleave",this.onMouseLeave);removeEventListener(this.el,"pointerdown",this.onPointerDown);if(balBrowser.hasDocument){removeEventListener(document,"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 i=t.connectedCallback,s=t.disconnectedCallback;t.connectedCallback=function(){if(!this._balElementStateSubject){this._balElementStateSubject=new BalElementStateSubject;this._balElementStateSubject.attach(this)}return i&&i.call(this)};t.disconnectedCallback=function(){if(this._balElementStateSubject){this._balElementStateSubject.detach();this._balElementStateSubject=undefined}return s&&s.call(this)}}}export{BalElementStateListener as B,ListenToElementStates as L};