(()=>{"use strict";class e{constructor(e,t){this.options={random:!1,startSlide:0,mode:"auto",delay:5,activeClass:"active",controls:!1,labels:{play:"Play slideshow",pause:"Pause slideshow",next:"Next slide",previous:"Previous slide",controls:"Slideshow controls"},...t},this.element=e,this.slides=Array.from(this.element.children),this.currentTimeout=null,this.currentVideoEndHandler=null,this.isPaused=!0;const s=this.getSlideVideo(0);0===this.slides.length?console.info("No slides found."):1!==this.slides.length||"detect"===this.options.mode&&s?(this.options.random?this.currentSlide=Math.floor(Math.random()*this.slides.length):this.currentSlide=this.options.startSlide,this.options.controls&&this.createControls(),this.element.classList.add("initialized"),this.checkReducedMotion()?this.showSlide():this.play()):console.info("Only one slide found. Slideshow will not start.",this.options.mode,s)}showSlide(){this.clearScheduledTransitions(),this.slides.forEach((e,t)=>{e.classList.remove(this.options.activeClass),e.setAttribute("aria-hidden",t!==this.currentSlide?"true":"false")});const e=this.slides[this.currentSlide];e?(e.classList.add(this.options.activeClass),this.advance()):console.error("Current slide not found")}advance(){if(this.isPaused)return;const e=this.slides[this.currentSlide];switch(this.options.mode){case"auto":this.options.delay>0&&this.delayNextSlide(this.options.delay);break;case"detect":if(e.hasAttribute("data-duration")){const t=parseFloat(e.getAttribute("data-duration"));!isNaN(t)&&t>0&&this.delayNextSlide(t)}else this.detectVideo()}}clearScheduledTransitions(){if(this.currentTimeout&&(clearTimeout(this.currentTimeout),this.currentTimeout=null),this.currentVideoEndHandler){const e=this.slides[this.currentSlide],t=e?.querySelector("video");t&&t.removeEventListener("ended",this.currentVideoEndHandler),this.currentVideoEndHandler=null}}delayNextSlide(e){this.currentTimeout=window.setTimeout(()=>{this.showNextSlide()},1e3*e)}getSlideVideo(e=this.currentSlide){const t=this.slides[e];return t?t.querySelector("video"):null}detectVideo(){const e=this.getSlideVideo();e&&e.play().then(()=>{this.currentVideoEndHandler=()=>{this.showNextSlide()},e.addEventListener("ended",this.currentVideoEndHandler,{once:!0})}).catch(e=>{console.warn("Video autoplay failed:",e),this.options.delay>0&&this.delayNextSlide(this.options.delay)})}getNextSlide(){return this.currentSlide<this.slides.length-1?this.currentSlide+1:0}showNextSlide(){this.currentSlide=this.getNextSlide(),this.showSlide()}getPreviousSlide(){return this.currentSlide>0?this.currentSlide-1:this.slides.length-1}showPreviousSlide(){this.currentSlide=this.getPreviousSlide(),this.showSlide()}createControls(){const e=document.createElement("div");e.className="slideshow-controls",e.setAttribute("role","group"),e.setAttribute("aria-label",this.options.labels.controls);const t=document.createElement("div");t.className="controls-bar",e.appendChild(t);const s=document.createElement("button");s.type="button",s.className="slideshow-control-prev",s.setAttribute("aria-label",this.options.labels.previous),s.textContent="⏪︎",s.addEventListener("click",()=>this.showPreviousSlide());const i=document.createElement("button");i.type="button",i.className="slideshow-control-playpause",i.setAttribute("aria-label",this.options.labels.play),i.textContent="▶︎",i.addEventListener("click",()=>this.togglePlayPause()),this.playPauseButton=i;const o=document.createElement("button");o.type="button",o.className="slideshow-control-next",o.setAttribute("aria-label",this.options.labels.next),o.textContent="⏩︎",o.addEventListener("click",()=>this.showNextSlide()),t.appendChild(s),t.appendChild(i),t.appendChild(o),this.element.appendChild(e)}pause(){this.isPaused=!0,this.clearScheduledTransitions(),this.playPauseButton&&(this.playPauseButton.textContent="▶︎",this.playPauseButton.setAttribute("aria-label",this.options.labels.play))}play(){this.isPaused=!1,this.playPauseButton&&(this.playPauseButton.textContent="⏸︎",this.playPauseButton.setAttribute("aria-label",this.options.labels.pause)),this.showSlide()}togglePlayPause(){this.isPaused?this.play():this.pause()}checkReducedMotion(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}}((Drupal,t)=>{const s=async(e,t)=>{try{const s=await fetch(`/api/slide_set/changed/${e}`,{headers:{Accept:"application/vnd.api+json"}});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return(await s.json()).changed>t}catch(e){return console.error("Fehler beim Prüfen der Node-Änderungen:",e),!1}};Drupal.behaviors.slideshow={attach(i){for(const o of t("slideset",".slide-set",i))if(new e(o,{mode:"detect"}),o.dataset.id){const e=Math.floor(Date.now()/1e3);setInterval(async()=>{await s(o.dataset.id,e)&&window.location.reload()},6e4)}}}})(Drupal,once)})();
//# sourceMappingURL=slideshow.js.map