import w from "react";
import { __require as L } from "../utils.js";
import { __require as q } from "../patterns.js";
var p, _;
function B() {
  if (_) return p;
  _ = 1;
  var b = Object.create, i = Object.defineProperty, P = Object.getOwnPropertyDescriptor, m = Object.getOwnPropertyNames, v = Object.getPrototypeOf, g = Object.prototype.hasOwnProperty, O = (r, e, t) => e in r ? i(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, D = (r, e) => {
    for (var t in e)
      i(r, t, { get: e[t], enumerable: !0 });
  }, u = (r, e, t, a) => {
    if (e && typeof e == "object" || typeof e == "function")
      for (let s of m(e))
        !g.call(r, s) && s !== t && i(r, s, { get: () => e[s], enumerable: !(a = P(e, s)) || a.enumerable });
    return r;
  }, E = (r, e, t) => (t = r != null ? b(v(r)) : {}, u(
    // 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.
    !r || !r.__esModule ? i(t, "default", { value: r, enumerable: !0 }) : t,
    r
  )), I = (r) => u(i({}, "__esModule", { value: !0 }), r), o = (r, e, t) => (O(r, typeof e != "symbol" ? e + "" : e, t), t), c = {};
  D(c, {
    default: () => n
  }), p = I(c);
  var h = E(w), l = /* @__PURE__ */ L(), S = /* @__PURE__ */ q();
  const y = "https://connect.facebook.net/en_US/sdk.js", f = "FB", d = "fbAsyncInit", k = "facebook-player-";
  class n extends h.Component {
    constructor() {
      super(...arguments), o(this, "callPlayer", l.callPlayer), o(this, "playerID", this.props.config.playerId || `${k}${(0, l.randomString)()}`), o(this, "mute", () => {
        this.callPlayer("mute");
      }), o(this, "unmute", () => {
        this.callPlayer("unmute");
      });
    }
    componentDidMount() {
      this.props.onMount && this.props.onMount(this);
    }
    load(e, t) {
      if (t) {
        (0, l.getSDK)(y, f, d).then((a) => a.XFBML.parse());
        return;
      }
      (0, l.getSDK)(y, f, d).then((a) => {
        a.init({
          appId: this.props.config.appId,
          xfbml: !0,
          version: this.props.config.version
        }), a.Event.subscribe("xfbml.render", (s) => {
          this.props.onLoaded();
        }), a.Event.subscribe("xfbml.ready", (s) => {
          s.type === "video" && s.id === this.playerID && (this.player = s.instance, this.player.subscribe("startedPlaying", this.props.onPlay), this.player.subscribe("paused", this.props.onPause), this.player.subscribe("finishedPlaying", this.props.onEnded), this.player.subscribe("startedBuffering", this.props.onBuffer), this.player.subscribe("finishedBuffering", this.props.onBufferEnd), this.player.subscribe("error", this.props.onError), this.props.muted ? this.callPlayer("mute") : this.callPlayer("unmute"), this.props.onReady(), document.getElementById(this.playerID).querySelector("iframe").style.visibility = "visible");
        });
      });
    }
    play() {
      this.callPlayer("play");
    }
    pause() {
      this.callPlayer("pause");
    }
    stop() {
    }
    seekTo(e, t = !0) {
      this.callPlayer("seek", e), t || this.pause();
    }
    setVolume(e) {
      this.callPlayer("setVolume", e);
    }
    getDuration() {
      return this.callPlayer("getDuration");
    }
    getCurrentTime() {
      return this.callPlayer("getCurrentPosition");
    }
    getSecondsLoaded() {
      return null;
    }
    render() {
      const { attributes: e } = this.props.config, t = {
        width: "100%",
        height: "100%"
      };
      return /* @__PURE__ */ h.default.createElement(
        "div",
        {
          style: t,
          id: this.playerID,
          className: "fb-video",
          "data-href": this.props.url,
          "data-autoplay": this.props.playing ? "true" : "false",
          "data-allowfullscreen": "true",
          "data-controls": this.props.controls ? "true" : "false",
          ...e
        }
      );
    }
  }
  return o(n, "displayName", "Facebook"), o(n, "canPlay", S.canPlay.facebook), o(n, "loopOnEnded", !0), p;
}
export {
  B as __require
};
//# sourceMappingURL=Facebook.js.map
