class o{constructor(e){var t;this.container=e,this.parentBlock=e.closest(".fp-media-block"),this.mediaId=(t=this.parentBlock)==null?void 0:t.dataset.mediaId,this.sections=e.querySelectorAll(".fp-timed-content"),this.player=null,this.activeSection=null,this._listeners=[],this.sections.length!==0&&(this.sectionData=Array.from(this.sections).map(i=>({el:i,start:parseFloat(i.dataset.start)||0,end:parseFloat(i.dataset.end)||1/0})),this.findPlayer())}findPlayer(){var t;let e=(t=this.parentBlock)==null?void 0:t.querySelector(".fluent-player");if(!e&&this.mediaId){const i=`.fluent-player .fluent-player-container[data-media-id="${this.mediaId}"]`,s=document.querySelector(i);s&&(e=s.closest(".fluent-player"))}e&&(this.player=e.querySelector("media-player"),this.player&&this.bindEvents())}bindEvents(){let e=0;const t=300,i=()=>{const l=Date.now();l-e<t||(e=l,this.updateVisibility(this.player.currentTime))},s=()=>{this.updateVisibility(this.player.currentTime)},a=()=>{this.hideAll()};this.player.addEventListener("time-update",i),this.player.addEventListener("seeked",s),this.player.addEventListener("ended",a),this._listeners=[["time-update",i],["seeked",s],["ended",a]]}updateVisibility(e){let t=null;for(const i of this.sectionData)if(e>=i.start&&e<i.end){t=i;break}t&&t.el!==this.activeSection?(this.activeSection&&this.activeSection.classList.remove("fp-tc-visible"),t.el.classList.add("fp-tc-visible"),this.activeSection=t.el):!t&&this.activeSection&&(this.activeSection.classList.remove("fp-tc-visible"),this.activeSection=null)}hideAll(){this.sections.forEach(e=>{e.classList.remove("fp-tc-visible")}),this.activeSection=null}destroy(){this.player&&this._listeners&&this._listeners.forEach(([e,t])=>{this.player.removeEventListener(e,t)}),this._listeners=[]}}function n(){document.querySelectorAll(".fp-timed-content-container").forEach(e=>{e._fpTimedContent||(e._fpTimedContent=new o(e))})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",n):n();document.addEventListener("FComMediaReady",n);document.addEventListener("InitSingleFluentPlayer",n);const d="";export{d as t};
