import { g as e } from "./alasql-f59e855e.js";
import t from "react";
import { u as r, p as o } from "./index-037d59a7.js";
function s(e2, t2) {
  for (var r2 = 0; r2 < t2.length; r2++) {
    const o2 = t2[r2];
    if ("string" != typeof o2 && !Array.isArray(o2)) {
      for (const t3 in o2)
        if ("default" !== t3 && !(t3 in e2)) {
          const r3 = Object.getOwnPropertyDescriptor(o2, t3);
          r3 && Object.defineProperty(e2, t3, r3.get ? r3 : { enumerable: true, get: () => o2[t3] });
        }
    }
  }
  return Object.freeze(Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }));
}
var i = Object.create, a = Object.defineProperty, n = Object.getOwnPropertyDescriptor, l = Object.getOwnPropertyNames, u = Object.getPrototypeOf, p = Object.prototype.hasOwnProperty, d = (e2, t2, r2, o2) => {
  if (t2 && "object" == typeof t2 || "function" == typeof t2)
    for (let s2 of l(t2))
      p.call(e2, s2) || s2 === r2 || a(e2, s2, { get: () => t2[s2], enumerable: !(o2 = n(t2, s2)) || o2.enumerable });
  return e2;
}, c = (e2, t2, r2) => (((e3, t3, r3) => {
  t3 in e3 ? a(e3, t3, { enumerable: true, configurable: true, writable: true, value: r3 }) : e3[t3] = r3;
})(e2, "symbol" != typeof t2 ? t2 + "" : t2, r2), r2), h = {};
((e2, t2) => {
  for (var r2 in t2)
    a(e2, r2, { get: t2[r2], enumerable: true });
})(h, { default: () => P });
var y, f = (y = h, d(a({}, "__esModule", { value: true }), y)), m = ((e2, t2, r2) => (r2 = null != e2 ? i(u(e2)) : {}, d(!t2 && e2 && e2.__esModule ? r2 : a(r2, "default", { value: e2, enumerable: true }), e2)))(t), b = r, g = o;
class P extends m.Component {
  constructor() {
    super(...arguments), c(this, "callPlayer", b.callPlayer), c(this, "duration", null), c(this, "currentTime", null), c(this, "fractionLoaded", null), c(this, "mute", () => {
      this.setVolume(0);
    }), c(this, "unmute", () => {
      null !== this.props.volume && this.setVolume(this.props.volume);
    }), c(this, "ref", (e2) => {
      this.iframe = e2;
    });
  }
  componentDidMount() {
    this.props.onMount && this.props.onMount(this);
  }
  load(e2, t2) {
    (0, b.getSDK)("https://w.soundcloud.com/player/api.js", "SC").then((r2) => {
      if (!this.iframe)
        return;
      const { PLAY: o2, PLAY_PROGRESS: s2, PAUSE: i2, FINISH: a2, ERROR: n2 } = r2.Widget.Events;
      t2 || (this.player = r2.Widget(this.iframe), this.player.bind(o2, this.props.onPlay), this.player.bind(i2, () => {
        this.duration - this.currentTime < 0.05 || this.props.onPause();
      }), this.player.bind(s2, (e3) => {
        this.currentTime = e3.currentPosition / 1e3, this.fractionLoaded = e3.loadedProgress;
      }), this.player.bind(a2, () => this.props.onEnded()), this.player.bind(n2, (e3) => this.props.onError(e3))), this.player.load(e2, { ...this.props.config.options, callback: () => {
        this.player.getDuration((e3) => {
          this.duration = e3 / 1e3, this.props.onReady();
        });
      } });
    });
  }
  play() {
    this.callPlayer("play");
  }
  pause() {
    this.callPlayer("pause");
  }
  stop() {
  }
  seekTo(e2, t2 = true) {
    this.callPlayer("seekTo", 1e3 * e2), t2 || this.pause();
  }
  setVolume(e2) {
    this.callPlayer("setVolume", 100 * e2);
  }
  getDuration() {
    return this.duration;
  }
  getCurrentTime() {
    return this.currentTime;
  }
  getSecondsLoaded() {
    return this.fractionLoaded * this.duration;
  }
  render() {
    const { display: e2 } = this.props, t2 = { width: "100%", height: "100%", display: e2 };
    return m.default.createElement("iframe", { ref: this.ref, src: `https://w.soundcloud.com/player/?url=${encodeURIComponent(this.props.url)}`, style: t2, frameBorder: 0, allow: "autoplay" });
  }
}
c(P, "displayName", "SoundCloud"), c(P, "canPlay", g.canPlay.soundcloud), c(P, "loopOnEnded", true);
const O = s({ __proto__: null, default: e(f) }, [f]);
export {
  O as S
};
