var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
import { createElement, memo } from "react";
import { SugaredField, useField } from "@contember/binding";
import { parseUrl } from "../../../utils/parseUrl.js";
class VimeoEmbedHandler {
  constructor(options) {
    __publicField(this, "debugName", "Vimeo");
    __publicField(this, "discriminateBy");
    this.options = options;
    this.discriminateBy = options.discriminateBy;
  }
  staticRender() {
    return /* @__PURE__ */ createElement(SugaredField, {
      field: this.options.vimeoIdField
    });
  }
  handleSource(source, url) {
    if (!url) {
      if (source.startsWith("vimeo.com")) {
        source = `www.${source}`;
      }
      if (source.startsWith("www.")) {
        source = `https://${source}`;
      }
      url = parseUrl(source);
      if (!url) {
        return void 0;
      }
    }
    if (!url.host.endsWith("vimeo.com")) {
      return void 0;
    }
    const matches = url.pathname.substr(1).match(/^(\d+)/);
    if (matches === null) {
      return void 0;
    }
    return matches[1];
  }
  renderEmbed() {
    if (this.options.render) {
      return this.options.render();
    }
    return /* @__PURE__ */ createElement(VimeoEmbedHandler.Renderer, {
      vimeoIdField: this.options.vimeoIdField
    });
  }
  populateEmbedData({ entity, embedArtifacts }) {
    entity.getField(this.options.vimeoIdField).updateValue(embedArtifacts);
  }
}
((VimeoEmbedHandler2) => {
  VimeoEmbedHandler2.Renderer = memo(function VimeoRenderer(props) {
    const vimeoId = useField(props.vimeoIdField).value;
    if (vimeoId === null) {
      return null;
    }
    return /* @__PURE__ */ createElement("iframe", {
      width: "560",
      height: "315",
      src: `https://player.vimeo.com/video/${vimeoId}`,
      referrerPolicy: "no-referrer",
      allow: "autoplay; fullscreen",
      loading: "lazy",
      frameBorder: "0",
      allowFullScreen: true
    });
  });
})(VimeoEmbedHandler || (VimeoEmbedHandler = {}));
export { VimeoEmbedHandler };
//# sourceMappingURL=VimeoEmbedHandler.js.map
