(()=>{"use strict";const t=class{constructor(t){if(this.element=t,this.youtube=t.querySelector("#youtube"),this.selfHostedVideo=t.querySelector("#selfHostedVideo"),this.audio=t.querySelector("#audio"),this.vimeo=t.querySelector("#vimeo"),this.youtube){const t="true"===this.youtube.getAttribute("data-autoplay"),e="true"===this.youtube.getAttribute("data-mute"),i="true"===this.youtube.getAttribute("data-loop"),a=!!t||e;this.originalMuteState=e,this.mainPlayer=new Plyr(this.youtube,{autoplay:t,muted:a,loop:{active:i}}),this.configureYouTube()}else if(this.selfHostedVideo)this.mainPlayer=new Plyr(this.selfHostedVideo);else if(this.vimeo){const t="true"===this.vimeo.getAttribute("data-autoplay"),e="true"===this.vimeo.getAttribute("data-mute"),i="true"===this.vimeo.getAttribute("data-loop"),a=!!t||e;this.originalMuteState=e,this.mainPlayer=new Plyr(this.vimeo,{autoplay:t,muted:a,loop:{active:i}})}else this.audio&&(this.mainPlayer=new Plyr(this.audio));if(this.mainPlayer){const e=t.querySelector(".plyr");e&&this.insertPlayButton(e),this.mainPlayer.on("playing",()=>{this.hidePlayButton(),!this.originalMuteState&&this.mainPlayer.muted&&(this.mainPlayer.muted=!1)}),this.mainPlayer.on("pause",()=>this.showPlayButton()),this.mainPlayer.on("ended",()=>this.showPlayButton()),this.mainPlayer.on("ready",()=>{this.element.querySelectorAll(".plyr__control").forEach(t=>{t.addEventListener("click",()=>{!this.originalMuteState&&this.mainPlayer.muted&&(this.mainPlayer.muted=!1)})})})}}configureYouTube(){this.videoStartTime=this.parseTime(this.youtube.getAttribute("data-video-start-time")),this.videoEndTime=this.parseTime(this.youtube.getAttribute("data-video-end-time")),this.mainPlayer.on("ready",()=>{isNaN(this.videoStartTime)||(this.mainPlayer.currentTime=this.videoStartTime)}),this.mainPlayer.on("timeupdate",()=>{!isNaN(this.videoEndTime)&&this.mainPlayer.currentTime>=this.videoEndTime&&this.mainPlayer.pause()})}insertPlayButton(t){const e=document.createElement("div");e.className="ablocks-play-pause-button",t.appendChild(e),this.playButton=e,e.addEventListener("click",()=>{!this.originalMuteState&&this.mainPlayer.muted&&(this.mainPlayer.muted=!1),this.mainPlayer.togglePlay()})}hidePlayButton(){this.playButton?.classList.add("is-hidden")}showPlayButton(){this.playButton?.classList.remove("is-hidden")}parseTime(t){return t?t.split(":").reverse().reduce((t,e,i)=>t+parseFloat(e)*60**i,0):NaN}destroy(){this.mainPlayer?.destroy()}};document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(".ablocks-block--player").forEach(e=>{new t(e,!1)})})})();