"use strict";
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;
};
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const reactBinding = require("@contember/react-binding");
const react = require("react");
const parseUrl = require("../../../utils/parseUrl.cjs");
class VimeoEmbedHandler {
  constructor(options) {
    __publicField(this, "debugName", "Vimeo");
    __publicField(this, "discriminateBy");
    this.options = options;
    this.discriminateBy = options.discriminateBy;
  }
  staticRender() {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.SugaredField, { field: this.options.vimeoIdField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/embed/handlers/VimeoEmbedHandler.tsx",
      lineNumber: 17,
      columnNumber: 10
    }, this);
  }
  handleSource(source, url) {
    if (!url) {
      if (source.startsWith("vimeo.com")) {
        source = `www.${source}`;
      }
      if (source.startsWith("www.")) {
        source = `https://${source}`;
      }
      url = parseUrl.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__ */ jsxDevRuntime.jsxDEV(VimeoEmbedHandler.Renderer, { vimeoIdField: this.options.vimeoIdField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/embed/handlers/VimeoEmbedHandler.tsx",
      lineNumber: 49,
      columnNumber: 10
    }, this);
  }
  populateEmbedData({ entity, embedArtifacts }) {
    entity.getField(this.options.vimeoIdField).updateValue(embedArtifacts);
  }
}
((VimeoEmbedHandler2) => {
  VimeoEmbedHandler2.Renderer = react.memo(function VimeoRenderer(props) {
    const vimeoId = reactBinding.useField(props.vimeoIdField).value;
    if (vimeoId === null) {
      return null;
    }
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(
      "iframe",
      {
        width: "560",
        height: "315",
        src: `https://player.vimeo.com/video/${vimeoId}`,
        referrerPolicy: "no-referrer",
        allow: "autoplay; fullscreen",
        loading: "lazy",
        frameBorder: "0",
        allowFullScreen: true
      },
      void 0,
      false,
      {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/embed/handlers/VimeoEmbedHandler.tsx",
        lineNumber: 75,
        columnNumber: 4
      },
      this
    );
  });
})(VimeoEmbedHandler || (VimeoEmbedHandler = {}));
exports.VimeoEmbedHandler = VimeoEmbedHandler;
//# sourceMappingURL=VimeoEmbedHandler.cjs.map
