import M from "react";
import { __require as T } from "../utils.js";
import { __require as j } from "../patterns.js";
var l, _;
function U() {
  if (_) return l;
  _ = 1;
  var m = Object.create, a = Object.defineProperty, f = Object.getOwnPropertyDescriptor, y = Object.getOwnPropertyNames, P = Object.getPrototypeOf, v = Object.prototype.hasOwnProperty, b = (t, e, r) => e in t ? a(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, g = (t, e) => {
    for (var r in e)
      a(t, r, { get: e[r], enumerable: !0 });
  }, p = (t, e, r, n) => {
    if (e && typeof e == "object" || typeof e == "function")
      for (let i of y(e))
        !v.call(t, i) && i !== r && a(t, i, { get: () => e[i], enumerable: !(n = f(e, i)) || n.enumerable });
    return t;
  }, O = (t, e, r) => (r = t != null ? m(P(t)) : {}, p(
    // 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 ? a(r, "default", { value: t, enumerable: !0 }) : r,
    t
  )), S = (t) => p(a({}, "__esModule", { value: !0 }), t), o = (t, e, r) => (b(t, typeof e != "symbol" ? e + "" : e, r), r), d = {};
  g(d, {
    default: () => u
  }), l = S(d);
  var h = O(M), c = /* @__PURE__ */ T(), w = /* @__PURE__ */ j();
  const C = "https://w.soundcloud.com/player/api.js", R = "SC";
  class u extends h.Component {
    constructor() {
      super(...arguments), o(this, "callPlayer", c.callPlayer), o(this, "duration", null), o(this, "currentTime", null), o(this, "fractionLoaded", null), o(this, "mute", () => {
        this.setVolume(0);
      }), o(this, "unmute", () => {
        this.props.volume !== null && this.setVolume(this.props.volume);
      }), o(this, "ref", (e) => {
        this.iframe = e;
      });
    }
    componentDidMount() {
      this.props.onMount && this.props.onMount(this);
    }
    load(e, r) {
      (0, c.getSDK)(C, R).then((n) => {
        if (!this.iframe)
          return;
        const { PLAY: i, PLAY_PROGRESS: E, PAUSE: L, FINISH: D, ERROR: q } = n.Widget.Events;
        r || (this.player = n.Widget(this.iframe), this.player.bind(i, this.props.onPlay), this.player.bind(L, () => {
          this.duration - this.currentTime < 0.05 || this.props.onPause();
        }), this.player.bind(E, (s) => {
          this.currentTime = s.currentPosition / 1e3, this.fractionLoaded = s.loadedProgress;
        }), this.player.bind(D, () => this.props.onEnded()), this.player.bind(q, (s) => this.props.onError(s))), this.player.load(e, {
          ...this.props.config.options,
          callback: () => {
            this.player.getDuration((s) => {
              this.duration = s / 1e3, this.props.onReady();
            });
          }
        });
      });
    }
    play() {
      this.callPlayer("play");
    }
    pause() {
      this.callPlayer("pause");
    }
    stop() {
    }
    seekTo(e, r = !0) {
      this.callPlayer("seekTo", e * 1e3), r || this.pause();
    }
    setVolume(e) {
      this.callPlayer("setVolume", e * 100);
    }
    getDuration() {
      return this.duration;
    }
    getCurrentTime() {
      return this.currentTime;
    }
    getSecondsLoaded() {
      return this.fractionLoaded * this.duration;
    }
    render() {
      const { display: e } = this.props, r = {
        width: "100%",
        height: "100%",
        display: e
      };
      return /* @__PURE__ */ h.default.createElement(
        "iframe",
        {
          ref: this.ref,
          src: `https://w.soundcloud.com/player/?url=${encodeURIComponent(this.props.url)}`,
          style: r,
          frameBorder: 0,
          allow: "autoplay"
        }
      );
    }
  }
  return o(u, "displayName", "SoundCloud"), o(u, "canPlay", w.canPlay.soundcloud), o(u, "loopOnEnded", !0), l;
}
export {
  U as __require
};
//# sourceMappingURL=SoundCloud.js.map
