"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // 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.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var mixcloud_exports = {};
__export(mixcloud_exports, {
  Mixcloud: () => Mixcloud
});
module.exports = __toCommonJS(mixcloud_exports);
var import_react = __toESM(require("react"));
var import_utils = require("../utils.js");
const SDK_URL = "https://widget.mixcloud.com/media/js/widgetApi.js";
const SDK_GLOBAL = "Mixcloud";
const MATCH_URL = /mixcloud\.com\/([^/]+\/[^/]+)/;
class Mixcloud extends import_react.Component {
  constructor() {
    super(...arguments);
    this.callPlayer = import_utils.callPlayer;
    this.duration = null;
    this.currentTime = null;
    this.secondsLoaded = null;
    this.mute = () => {
    };
    this.unmute = () => {
    };
    this.ref = (iframe) => {
      this.iframe = iframe;
    };
  }
  load(_url) {
    (0, import_utils.getSDK)(SDK_URL, SDK_GLOBAL).then((Mixcloud2) => {
      this.player = Mixcloud2.PlayerWidget(this.iframe);
      this.player.ready.then(() => {
        this.player.events.play.on(this.props.onPlay);
        this.player.events.pause.on(this.props.onPause);
        this.player.events.ended.on(this.props.onEnded);
        this.player.events.error.on(this.props.error);
        this.player.events.progress.on((seconds, duration) => {
          this.currentTime = seconds;
          this.duration = duration;
        });
        this.props.onReady();
      });
    }, this.props.onError);
  }
  play() {
    this.callPlayer("play");
  }
  pause() {
    this.callPlayer("pause");
  }
  stop() {
  }
  seekTo(seconds) {
    this.callPlayer("seek", seconds);
  }
  setVolume(_fraction) {
  }
  getDuration() {
    return this.duration;
  }
  getCurrentTime() {
    return this.currentTime;
  }
  getSecondsLoaded() {
    return null;
  }
  render() {
    const { url, config } = this.props;
    const id = url.match(MATCH_URL)[1];
    const style = {
      width: "100%",
      height: "100%"
    };
    const query = (0, import_utils.queryString)({
      ...config.mixcloud.options,
      feed: `/${id}/`
    });
    return (
      // oxlint-disable-next-line jsx-a11y/iframe-has-title
      /* @__PURE__ */ import_react.default.createElement(
        "iframe",
        {
          key: id,
          ref: this.ref,
          style,
          src: `https://www.mixcloud.com/widget/iframe/?${query}`,
          frameBorder: "0"
        }
      )
    );
  }
}
Mixcloud.displayName = "Mixcloud";
Mixcloud.canPlay = (url) => MATCH_URL.test(url);
Mixcloud.loopOnEnded = true;
//# sourceMappingURL=mixcloud.js.map
