import j from "react";
var h, v;
function M() {
  if (v) return h;
  v = 1;
  var b = Object.create, s = Object.defineProperty, y = Object.getOwnPropertyDescriptor, w = Object.getOwnPropertyNames, P = Object.getPrototypeOf, O = Object.prototype.hasOwnProperty, x = (r, e, t) => e in r ? s(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, I = (r, e) => {
    for (var t in e)
      s(r, t, { get: e[t], enumerable: !0 });
  }, _ = (r, e, t, n) => {
    if (e && typeof e == "object" || typeof e == "function")
      for (let a of w(e))
        !O.call(r, a) && a !== t && s(r, a, { get: () => e[a], enumerable: !(n = y(e, a)) || n.enumerable });
    return r;
  }, E = (r, e, t) => (t = r != null ? b(P(r)) : {}, _(
    // 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 ? s(t, "default", { value: r, enumerable: !0 }) : t,
    r
  )), S = (r) => _(s({}, "__esModule", { value: !0 }), r), l = (r, e, t) => (x(r, typeof e != "symbol" ? e + "" : e, t), t), f = {};
  I(f, {
    default: () => C
  }), h = S(f);
  var i = E(j);
  const c = "64px", p = {};
  class C extends i.Component {
    constructor() {
      super(...arguments), l(this, "mounted", !1), l(this, "state", {
        image: null
      }), l(this, "handleKeyPress", (e) => {
        (e.key === "Enter" || e.key === " ") && this.props.onClick();
      });
    }
    componentDidMount() {
      this.mounted = !0, this.fetchImage(this.props);
    }
    componentDidUpdate(e) {
      const { url: t, light: n } = this.props;
      (e.url !== t || e.light !== n) && this.fetchImage(this.props);
    }
    componentWillUnmount() {
      this.mounted = !1;
    }
    fetchImage({ url: e, light: t, oEmbedUrl: n }) {
      if (!i.default.isValidElement(t)) {
        if (typeof t == "string") {
          this.setState({ image: t });
          return;
        }
        if (p[e]) {
          this.setState({ image: p[e] });
          return;
        }
        return this.setState({ image: null }), window.fetch(n.replace("{url}", e)).then((a) => a.json()).then((a) => {
          if (a.thumbnail_url && this.mounted) {
            const o = a.thumbnail_url.replace("height=100", "height=480").replace("-d_295x166", "-d_640");
            this.setState({ image: o }), p[e] = o;
          }
        });
      }
    }
    render() {
      const { light: e, onClick: t, playIcon: n, previewTabIndex: a, previewAriaLabel: o } = this.props, { image: m } = this.state, u = i.default.isValidElement(e), g = {
        display: "flex",
        alignItems: "center",
        justifyContent: "center"
      }, d = {
        preview: {
          width: "100%",
          height: "100%",
          backgroundImage: m && !u ? `url(${m})` : void 0,
          backgroundSize: "cover",
          backgroundPosition: "center",
          cursor: "pointer",
          ...g
        },
        shadow: {
          background: "radial-gradient(rgb(0, 0, 0, 0.3), rgba(0, 0, 0, 0) 60%)",
          borderRadius: c,
          width: c,
          height: c,
          position: u ? "absolute" : void 0,
          ...g
        },
        playIcon: {
          borderStyle: "solid",
          borderWidth: "16px 0 16px 26px",
          borderColor: "transparent transparent transparent white",
          marginLeft: "7px"
        }
      }, N = /* @__PURE__ */ i.default.createElement("div", { style: d.shadow, className: "react-player__shadow" }, /* @__PURE__ */ i.default.createElement("div", { style: d.playIcon, className: "react-player__play-icon" }));
      return /* @__PURE__ */ i.default.createElement(
        "div",
        {
          style: d.preview,
          className: "react-player__preview",
          onClick: t,
          tabIndex: a,
          onKeyPress: this.handleKeyPress,
          ...o ? { "aria-label": o } : {}
        },
        u ? e : null,
        n || N
      );
    }
  }
  return h;
}
export {
  M as __require
};
//# sourceMappingURL=Preview.js.map
