"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 parseIframeSrc = require("../../../utils/parseIframeSrc.cjs");
const parseUrl = require("../../../utils/parseUrl.cjs");
class GoogleFormEmbedHandler {
  constructor(options) {
    __publicField(this, "debugName", "GoogleForm");
    __publicField(this, "discriminateBy");
    this.options = options;
    this.discriminateBy = options.discriminateBy;
  }
  staticRender() {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.SugaredField, { field: this.options.googleFormIdField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/embed/handlers/GoogleFormEmbedHandler.tsx",
      lineNumber: 16,
      columnNumber: 10
    }, this);
  }
  handleSource(source, url) {
    if (!url) {
      source = parseIframeSrc.parseIframeSrc(source) ?? source;
      if (source.startsWith("docs.google.com")) {
        source = `https://${source}`;
      }
      url = parseUrl.parseUrl(source);
      if (!url) {
        return void 0;
      }
    }
    if (!url.host.endsWith("docs.google.com")) {
      return void 0;
    }
    const matches = url.pathname.match(/^\/forms\/d(\/e)?\/([^\/]+).*$/);
    if (!matches) {
      return void 0;
    }
    if (matches[1] === void 0) {
      alert(
        this.options.nonEmbedLinkWarning ?? "Detected a Google Form but the link supplied cannot be reliably embedded.\n\nIf you wish to embed the form, please return to Google Forms and use the 'Send' button in the top right corner to get a correct link."
      );
      return void 0;
    }
    return matches[2];
  }
  renderEmbed() {
    if (this.options.render) {
      return this.options.render();
    }
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(GoogleFormEmbedHandler.Renderer, { googleFormIdField: this.options.googleFormIdField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/embed/handlers/GoogleFormEmbedHandler.tsx",
      lineNumber: 56,
      columnNumber: 10
    }, this);
  }
  populateEmbedData({ entity, embedArtifacts }) {
    entity.getField(this.options.googleFormIdField).updateValue(embedArtifacts);
  }
}
((GoogleFormEmbedHandler2) => {
  GoogleFormEmbedHandler2.Renderer = react.memo(function GoogleFormRenderer(props) {
    const googleFormId = reactBinding.useField(props.googleFormIdField).value;
    if (googleFormId === null) {
      return null;
    }
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(
      "iframe",
      {
        src: `https://docs.google.com/forms/d/e/${googleFormId}/viewform?embedded=true`,
        width: "640",
        height: "640",
        frameBorder: "0",
        loading: "lazy",
        allowFullScreen: true
      },
      void 0,
      false,
      {
        fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/blockEditor/embed/handlers/GoogleFormEmbedHandler.tsx",
        lineNumber: 83,
        columnNumber: 4
      },
      this
    );
  });
})(GoogleFormEmbedHandler || (GoogleFormEmbedHandler = {}));
exports.GoogleFormEmbedHandler = GoogleFormEmbedHandler;
//# sourceMappingURL=GoogleFormEmbedHandler.cjs.map
