import A from "react";
import { __require as C } from "../utils.js";
import { __require as N } from "../patterns.js";
var c, m;
function B() {
  if (m) return c;
  m = 1;
  var f = Object.create, o = Object.defineProperty, P = Object.getOwnPropertyDescriptor, g = Object.getOwnPropertyNames, v = Object.getPrototypeOf, D = Object.prototype.hasOwnProperty, O = (t, e, r) => e in t ? o(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, M = (t, e) => {
    for (var r in e)
      o(t, r, { get: e[r], enumerable: !0 });
  }, h = (t, e, r, l) => {
    if (e && typeof e == "object" || typeof e == "function")
      for (let i of g(e))
        !D.call(t, i) && i !== r && o(t, i, { get: () => e[i], enumerable: !(l = P(e, i)) || l.enumerable });
    return t;
  }, b = (t, e, r) => (r = t != null ? f(v(t)) : {}, h(
    // If the importer is in node compatibility mode or this is not an ESM
    // file that has been converted to a CommonJS file using a Babel-
    // compatible transform (i.e. "__esModule" has not been set), then set
    // "default" to the CommonJS "module.exports" for node compatibility.
    !t || !t.__esModule ? o(r, "default", { value: t, enumerable: !0 }) : r,
    t
  )), w = (t) => h(o({}, "__esModule", { value: !0 }), t), a = (t, e, r) => (O(t, typeof e != "symbol" ? e + "" : e, r), r), y = {};
  M(y, {
    default: () => s
  }), c = w(y);
  var p = b(A), n = /* @__PURE__ */ C(), _ = /* @__PURE__ */ N();
  const S = "https://api.dmcdn.net/all.js", T = "DM", L = "dmAsyncInit";
  class s extends p.Component {
    constructor() {
      super(...arguments), a(this, "callPlayer", n.callPlayer), a(this, "onDurationChange", () => {
        const e = this.getDuration();
        this.props.onDuration(e);
      }), a(this, "mute", () => {
        this.callPlayer("setMuted", !0);
      }), a(this, "unmute", () => {
        this.callPlayer("setMuted", !1);
      }), a(this, "ref", (e) => {
        this.container = e;
      });
    }
    componentDidMount() {
      this.props.onMount && this.props.onMount(this);
    }
    load(e) {
      const { controls: r, config: l, onError: i, playing: q } = this.props, [, d] = e.match(_.MATCH_URL_DAILYMOTION);
      if (this.player) {
        this.player.load(d, {
          start: (0, n.parseStartTime)(e),
          autoplay: q
        });
        return;
      }
      (0, n.getSDK)(S, T, L, (u) => u.player).then((u) => {
        if (!this.container)
          return;
        const E = u.player;
        this.player = new E(this.container, {
          width: "100%",
          height: "100%",
          video: d,
          params: {
            controls: r,
            autoplay: this.props.playing,
            mute: this.props.muted,
            start: (0, n.parseStartTime)(e),
            origin: window.location.origin,
            ...l.params
          },
          events: {
            apiready: this.props.onReady,
            seeked: () => this.props.onSeek(this.player.currentTime),
            video_end: this.props.onEnded,
            durationchange: this.onDurationChange,
            pause: this.props.onPause,
            playing: this.props.onPlay,
            waiting: this.props.onBuffer,
            error: (j) => i(j)
          }
        });
      }, i);
    }
    play() {
      this.callPlayer("play");
    }
    pause() {
      this.callPlayer("pause");
    }
    stop() {
    }
    seekTo(e, r = !0) {
      this.callPlayer("seek", e), r || this.pause();
    }
    setVolume(e) {
      this.callPlayer("setVolume", e);
    }
    getDuration() {
      return this.player.duration || null;
    }
    getCurrentTime() {
      return this.player.currentTime;
    }
    getSecondsLoaded() {
      return this.player.bufferedTime;
    }
    render() {
      const { display: e } = this.props, r = {
        width: "100%",
        height: "100%",
        display: e
      };
      return /* @__PURE__ */ p.default.createElement("div", { style: r }, /* @__PURE__ */ p.default.createElement("div", { ref: this.ref }));
    }
  }
  return a(s, "displayName", "DailyMotion"), a(s, "canPlay", _.canPlay.dailymotion), a(s, "loopOnEnded", !0), c;
}
export {
  B as __require
};
//# sourceMappingURL=DailyMotion.js.map
