import { g as e } from "./alasql-f59e855e.js";
import t from "react";
import { u as s, p as r } from "./index-c0cd585c.js";
function i(e2, t2) {
  for (var s2 = 0; s2 < t2.length; s2++) {
    const r2 = t2[s2];
    if ("string" != typeof r2 && !Array.isArray(r2)) {
      for (const t3 in r2)
        if ("default" !== t3 && !(t3 in e2)) {
          const s3 = Object.getOwnPropertyDescriptor(r2, t3);
          s3 && Object.defineProperty(e2, t3, s3.get ? s3 : { enumerable: true, get: () => r2[t3] });
        }
    }
  }
  return Object.freeze(Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }));
}
var n = Object.create, o = Object.defineProperty, a = Object.getOwnPropertyDescriptor, h = Object.getOwnPropertyNames, l = Object.getPrototypeOf, p = Object.prototype.hasOwnProperty, d = (e2, t2, s2, r2) => {
  if (t2 && "object" == typeof t2 || "function" == typeof t2)
    for (let i2 of h(t2))
      p.call(e2, i2) || i2 === s2 || o(e2, i2, { get: () => t2[i2], enumerable: !(r2 = a(t2, i2)) || r2.enumerable });
  return e2;
}, u = (e2, t2, s2) => (((e3, t3, s3) => {
  t3 in e3 ? o(e3, t3, { enumerable: true, configurable: true, writable: true, value: s3 }) : e3[t3] = s3;
})(e2, "symbol" != typeof t2 ? t2 + "" : t2, s2), s2), c = {};
((e2, t2) => {
  for (var s2 in t2)
    o(e2, s2, { get: t2[s2], enumerable: true });
})(c, { default: () => w });
var y, f = (y = c, d(o({}, "__esModule", { value: true }), y)), m = ((e2, t2, s2) => (s2 = null != e2 ? n(l(e2)) : {}, d(!t2 && e2 && e2.__esModule ? s2 : o(s2, "default", { value: e2, enumerable: true }), e2)))(t), v = s, E = r;
const P = "undefined" != typeof navigator, g = P && "MacIntel" === navigator.platform && navigator.maxTouchPoints > 1, b = P && (/iPad|iPhone|iPod/.test(navigator.userAgent) || g) && !window.MSStream, S = P && /^((?!chrome|android).)*safari/i.test(navigator.userAgent) && !window.MSStream, L = /www\.dropbox\.com\/.+/, O = /https:\/\/watch\.cloudflarestream\.com\/([a-z0-9]+)/;
class w extends m.Component {
  constructor() {
    super(...arguments), u(this, "onReady", (...e2) => this.props.onReady(...e2)), u(this, "onPlay", (...e2) => this.props.onPlay(...e2)), u(this, "onBuffer", (...e2) => this.props.onBuffer(...e2)), u(this, "onBufferEnd", (...e2) => this.props.onBufferEnd(...e2)), u(this, "onPause", (...e2) => this.props.onPause(...e2)), u(this, "onEnded", (...e2) => this.props.onEnded(...e2)), u(this, "onError", (...e2) => this.props.onError(...e2)), u(this, "onPlayBackRateChange", (e2) => this.props.onPlaybackRateChange(e2.target.playbackRate)), u(this, "onEnablePIP", (...e2) => this.props.onEnablePIP(...e2)), u(this, "onDisablePIP", (e2) => {
      const { onDisablePIP: t2, playing: s2 } = this.props;
      t2(e2), s2 && this.play();
    }), u(this, "onPresentationModeChange", (e2) => {
      if (this.player && (0, v.supportsWebKitPresentationMode)(this.player)) {
        const { webkitPresentationMode: t2 } = this.player;
        "picture-in-picture" === t2 ? this.onEnablePIP(e2) : "inline" === t2 && this.onDisablePIP(e2);
      }
    }), u(this, "onSeek", (e2) => {
      this.props.onSeek(e2.target.currentTime);
    }), u(this, "mute", () => {
      this.player.muted = true;
    }), u(this, "unmute", () => {
      this.player.muted = false;
    }), u(this, "renderSourceElement", (e2, t2) => "string" == typeof e2 ? m.default.createElement("source", { key: t2, src: e2 }) : m.default.createElement("source", { key: t2, ...e2 })), u(this, "renderTrack", (e2, t2) => m.default.createElement("track", { key: t2, ...e2 })), u(this, "ref", (e2) => {
      this.player && (this.prevPlayer = this.player), this.player = e2;
    });
  }
  componentDidMount() {
    this.props.onMount && this.props.onMount(this), this.addListeners(this.player);
    const e2 = this.getSource(this.props.url);
    e2 && (this.player.src = e2), (b || this.props.config.forceDisableHls) && this.player.load();
  }
  componentDidUpdate(e2) {
    this.shouldUseAudio(this.props) !== this.shouldUseAudio(e2) && (this.removeListeners(this.prevPlayer, e2.url), this.addListeners(this.player)), this.props.url === e2.url || (0, v.isMediaStream)(this.props.url) || this.props.url instanceof Array || (this.player.srcObject = null);
  }
  componentWillUnmount() {
    this.player.removeAttribute("src"), this.removeListeners(this.player), this.hls && this.hls.destroy();
  }
  addListeners(e2) {
    const { url: t2, playsinline: s2 } = this.props;
    e2.addEventListener("play", this.onPlay), e2.addEventListener("waiting", this.onBuffer), e2.addEventListener("playing", this.onBufferEnd), e2.addEventListener("pause", this.onPause), e2.addEventListener("seeked", this.onSeek), e2.addEventListener("ended", this.onEnded), e2.addEventListener("error", this.onError), e2.addEventListener("ratechange", this.onPlayBackRateChange), e2.addEventListener("enterpictureinpicture", this.onEnablePIP), e2.addEventListener("leavepictureinpicture", this.onDisablePIP), e2.addEventListener("webkitpresentationmodechanged", this.onPresentationModeChange), this.shouldUseHLS(t2) || e2.addEventListener("canplay", this.onReady), s2 && (e2.setAttribute("playsinline", ""), e2.setAttribute("webkit-playsinline", ""), e2.setAttribute("x5-playsinline", ""));
  }
  removeListeners(e2, t2) {
    e2.removeEventListener("canplay", this.onReady), e2.removeEventListener("play", this.onPlay), e2.removeEventListener("waiting", this.onBuffer), e2.removeEventListener("playing", this.onBufferEnd), e2.removeEventListener("pause", this.onPause), e2.removeEventListener("seeked", this.onSeek), e2.removeEventListener("ended", this.onEnded), e2.removeEventListener("error", this.onError), e2.removeEventListener("ratechange", this.onPlayBackRateChange), e2.removeEventListener("enterpictureinpicture", this.onEnablePIP), e2.removeEventListener("leavepictureinpicture", this.onDisablePIP), e2.removeEventListener("webkitpresentationmodechanged", this.onPresentationModeChange), this.shouldUseHLS(t2) || e2.removeEventListener("canplay", this.onReady);
  }
  shouldUseAudio(e2) {
    return !e2.config.forceVideo && (!e2.config.attributes.poster && (E.AUDIO_EXTENSIONS.test(e2.url) || e2.config.forceAudio));
  }
  shouldUseHLS(e2) {
    return !!(S && this.props.config.forceSafariHLS || this.props.config.forceHLS) || !b && !this.props.config.forceDisableHls && (E.HLS_EXTENSIONS.test(e2) || O.test(e2));
  }
  shouldUseDASH(e2) {
    return E.DASH_EXTENSIONS.test(e2) || this.props.config.forceDASH;
  }
  shouldUseFLV(e2) {
    return E.FLV_EXTENSIONS.test(e2) || this.props.config.forceFLV;
  }
  load(e2) {
    const { hlsVersion: t2, hlsOptions: s2, dashVersion: r2, flvVersion: i2 } = this.props.config;
    if (this.hls && this.hls.destroy(), this.dash && this.dash.reset(), this.shouldUseHLS(e2) && (0, v.getSDK)("https://cdn.jsdelivr.net/npm/hls.js@VERSION/dist/hls.min.js".replace("VERSION", t2), "Hls").then((t3) => {
      if (this.hls = new t3(s2), this.hls.on(t3.Events.MANIFEST_PARSED, () => {
        this.props.onReady();
      }), this.hls.on(t3.Events.ERROR, (e3, s3) => {
        this.props.onError(e3, s3, this.hls, t3);
      }), O.test(e2)) {
        const t4 = e2.match(O)[1];
        this.hls.loadSource("https://videodelivery.net/{id}/manifest/video.m3u8".replace("{id}", t4));
      } else
        this.hls.loadSource(e2);
      this.hls.attachMedia(this.player), this.props.onLoaded();
    }), this.shouldUseDASH(e2) && (0, v.getSDK)("https://cdnjs.cloudflare.com/ajax/libs/dashjs/VERSION/dash.all.min.js".replace("VERSION", r2), "dashjs").then((t3) => {
      this.dash = t3.MediaPlayer().create(), this.dash.initialize(this.player, e2, this.props.playing), this.dash.on("error", this.props.onError), parseInt(r2) < 3 ? this.dash.getDebug().setLogToBrowserConsole(false) : this.dash.updateSettings({ debug: { logLevel: t3.Debug.LOG_LEVEL_NONE } }), this.props.onLoaded();
    }), this.shouldUseFLV(e2) && (0, v.getSDK)("https://cdn.jsdelivr.net/npm/flv.js@VERSION/dist/flv.min.js".replace("VERSION", i2), "flvjs").then((t3) => {
      this.flv = t3.createPlayer({ type: "flv", url: e2 }), this.flv.attachMediaElement(this.player), this.flv.on(t3.Events.ERROR, (e3, s3) => {
        this.props.onError(e3, s3, this.flv, t3);
      }), this.flv.load(), this.props.onLoaded();
    }), e2 instanceof Array)
      this.player.load();
    else if ((0, v.isMediaStream)(e2))
      try {
        this.player.srcObject = e2;
      } catch (t3) {
        this.player.src = window.URL.createObjectURL(e2);
      }
  }
  play() {
    const e2 = this.player.play();
    e2 && e2.catch(this.props.onError);
  }
  pause() {
    this.player.pause();
  }
  stop() {
    this.player.removeAttribute("src"), this.dash && this.dash.reset();
  }
  seekTo(e2, t2 = true) {
    this.player.currentTime = e2, t2 || this.pause();
  }
  setVolume(e2) {
    this.player.volume = e2;
  }
  enablePIP() {
    this.player.requestPictureInPicture && document.pictureInPictureElement !== this.player ? this.player.requestPictureInPicture() : (0, v.supportsWebKitPresentationMode)(this.player) && "picture-in-picture" !== this.player.webkitPresentationMode && this.player.webkitSetPresentationMode("picture-in-picture");
  }
  disablePIP() {
    document.exitPictureInPicture && document.pictureInPictureElement === this.player ? document.exitPictureInPicture() : (0, v.supportsWebKitPresentationMode)(this.player) && "inline" !== this.player.webkitPresentationMode && this.player.webkitSetPresentationMode("inline");
  }
  setPlaybackRate(e2) {
    try {
      this.player.playbackRate = e2;
    } catch (e3) {
      this.props.onError(e3);
    }
  }
  getDuration() {
    if (!this.player)
      return null;
    const { duration: e2, seekable: t2 } = this.player;
    return e2 === 1 / 0 && t2.length > 0 ? t2.end(t2.length - 1) : e2;
  }
  getCurrentTime() {
    return this.player ? this.player.currentTime : null;
  }
  getSecondsLoaded() {
    if (!this.player)
      return null;
    const { buffered: e2 } = this.player;
    if (0 === e2.length)
      return 0;
    const t2 = e2.end(e2.length - 1), s2 = this.getDuration();
    return t2 > s2 ? s2 : t2;
  }
  getSource(e2) {
    const t2 = this.shouldUseHLS(e2), s2 = this.shouldUseDASH(e2), r2 = this.shouldUseFLV(e2);
    if (!(e2 instanceof Array || (0, v.isMediaStream)(e2) || t2 || s2 || r2))
      return L.test(e2) ? e2.replace("www.dropbox.com", "dl.dropboxusercontent.com") : e2;
  }
  render() {
    const { url: e2, playing: t2, loop: s2, controls: r2, muted: i2, config: n2, width: o2, height: a2 } = this.props, h2 = this.shouldUseAudio(this.props) ? "audio" : "video", l2 = { width: "auto" === o2 ? o2 : "100%", height: "auto" === a2 ? a2 : "100%" };
    return m.default.createElement(h2, { ref: this.ref, src: this.getSource(e2), style: l2, preload: "auto", autoPlay: t2 || void 0, controls: r2, muted: i2, loop: s2, ...n2.attributes }, e2 instanceof Array && e2.map(this.renderSourceElement), n2.tracks.map(this.renderTrack));
  }
}
u(w, "displayName", "FilePlayer"), u(w, "canPlay", E.canPlay.file);
const I = i({ __proto__: null, default: e(f) }, [f]);
export {
  I as F
};
