var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
import { D as DCFDialog } from "../chunks/chunk.dcf-dialog.js?v=6.1.1";
class UNLDialog extends DCFDialog {
  static {
    __name(this, "UNLDialog");
  }
  videos = [];
  iframes = [];
  constructor(dialog, options = {}) {
    super(dialog, options), this.videos = Array.from(this.dialogElement.getElementsByTagName("video")), Array.from(this.dialogElement.getElementsByTagName("iframe")).forEach((singleIframe) => {
      const source = singleIframe.getAttribute("src"), allowAttr = singleIframe.getAttribute("allow");
      if (allowAttr && allowAttr.includes("autoplay") && !source.includes("mediahub.unl.edu"))
        try {
          const url = new URL(singleIframe.getAttribute("src"));
          url.searchParams.has("autoplay") && (url.searchParams.delete("autoplay"), singleIframe.src = url.toString());
        } catch (error) {
          console.error(error);
        }
      this.iframes.push({
        source,
        allowAttr,
        iframeElement: singleIframe
      });
    }), window.UNL = window.UNL || {}, window.UNL.classes = window.UNL.classes || {}, window.UNL.classes[this.dialogElement.getAttribute("id")] = this, this.toggleButtons.forEach((singleButton) => {
      window.UNL.classes[singleButton.getAttribute("id")] = this, singleButton.dispatchEvent(new Event("UNLClassReady"));
    }), this.dialogElement.dispatchEvent(new Event("UNLClassReady"));
  }
  open(eventData = {}) {
    super.open(eventData), this.videos.length > 0 && this.videos.forEach((singleVideo) => {
      singleVideo.hasAttribute("data-autoplay") && singleVideo.play();
    }), this.iframes.length > 0 && this.iframes.forEach((iframeObj) => {
      if (iframeObj.allowAttr && iframeObj.allowAttr.includes("autoplay")) {
        const currentSource = iframeObj.iframeElement.getAttribute("src");
        if (currentSource.includes("mediahub.unl.edu"))
          iframeObj.iframeElement.contentWindow.postMessage("mh-play-video", "https://mediahub.unl.edu");
        else
          try {
            const url = new URL(currentSource);
            url.searchParams.set("autoplay", "1");
            const newSource = url.toString();
            currentSource !== newSource && (iframeObj.iframeElement.src = newSource);
          } catch (error) {
            console.error(error), iframeObj.iframeElement.src = iframeObj.source;
          }
      }
    });
  }
  close(eventData = {}) {
    if (super.close(eventData), this.videos.length > 0) {
      this.videos.forEach((singleVideo) => {
        singleVideo.pause(), singleVideo.load();
      });
      const playBtns = Array.from(this.dialogElement.getElementsByClassName("mejs-overlay-play"));
      playBtns.length > 0 && playBtns.forEach((singlePlayBtn) => {
        singlePlayBtn.style.display === "none" && (singlePlayBtn.style.display = "block");
      });
    }
    this.iframes.length > 0 && this.iframes.forEach((iframeObj) => {
      if (iframeObj.allowAttr && iframeObj.allowAttr.includes("autoplay")) {
        let currentSource = iframeObj.iframeElement.getAttribute("src");
        if (currentSource.includes("mediahub.unl.edu"))
          iframeObj.iframeElement.contentWindow.postMessage("mh-reset-video", "https://mediahub.unl.edu");
        else
          try {
            const url = new URL(currentSource);
            url.searchParams.has("autoplay") && (url.searchParams.delete("autoplay"), currentSource = url.toString()), iframeObj.iframeElement.src = currentSource;
          } catch (error) {
            console.error(error), iframeObj.iframeElement.src = iframeObj.source;
          }
      } else iframeObj.source.includes("mediahub.unl.edu") ? iframeObj.iframeElement.contentWindow.postMessage("mh-pause-video", "https://mediahub.unl.edu") : iframeObj.iframeElement.src = iframeObj.source;
    });
  }
}
export {
  UNLDialog as default
};
//# sourceMappingURL=component.dialog.js.map
