/**
 * Copyright 2019 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
import{UABroker as e}from"./lib/UserActionBroker.js";class UserAction extends HTMLElement{static get tag(){return"user-action"}constructor(){super(),this.tag=UserAction.tag,this.fired=!1,this.track="visibility",this.eventname="user-engagement",this.every=!1,this.demo=!1,this.visiblelimit=.5}get every(){return this.getAttribute("every")}set every(e){e&&this.setAttribute("every",e)}get demo(){return this.getAttribute("demo")}set demo(e){e&&this.setAttribute("demo",e)}connectedCallback(){this.__ready=!0}static get observedAttributes(){return["track","eventname","every","demo"]}attributeChangedCallback(e,t,i){if("track"===e&&i)if("visibility"===i)this.observer=new IntersectionObserver(this.handleIntersectionCallback.bind(this),{rootMargin:"0px",threshold:[0,.25,.5,.75,1]}),this.observer.observe(this);else this.addEventListener(i,this.userActionEvent.bind(this))}handleIntersectionCallback(e){for(let t of e)Number(t.intersectionRatio).toFixed(2)>=this.visiblelimit&&this.__ready&&this.userActionEvent({detail:"visible"})}userActionEvent(t){this._haxstate||this.fired&&!this.every||!e.valid(this.track)?e.valid(this.track)||console.warn(this.track+" was not valid"):(e.fire(this.eventname,this.track,t,this,this.demo),this.fired=!0)}static get haxProperties(){return new URL(`./lib/${this.tag}.haxProperties.json`,import.meta.url).href}haxHooks(){return{editModeChanged:"haxeditModeChanged",activeElementChanged:"haxactiveElementChanged",gizmoRegistration:"haxgizmoRegistration"}}haxgizmoRegistration(e){globalThis.dispatchEvent(new CustomEvent("i18n-manager-register-element",{detail:{namespace:"user-action.haxProperties",localesPath:new URL("./locales/user-action.haxProperties.es.json",import.meta.url).href+"/../",locales:["es"]}}))}haxactiveElementChanged(e,t){t&&(this._haxstate=t)}haxeditModeChanged(e){this._haxstate=e}}customElements.define(UserAction.tag,UserAction);export{UserAction};