"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 insert_modal_exports = {};
__export(insert_modal_exports, {
  InsertModal: () => InsertModal
});
module.exports = __toCommonJS(insert_modal_exports);
var import_design_system = require("@wix/design-system");
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../ricos-context/index.js");
var import_v1 = require("./../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_bi_context_provider = require("./../../../_shared/bi-context-provider/bi-context-provider.js");
var import_contains_url = require("./../../../_shared/link/contains-url.js");
var import_use_node_attrs = require("./../../../_shared/use-node-attrs.js");
var import_consts = require("./../../consts.js");
var import_ui_components = require("./../../../ui-components/index.js");
var import_data_hooks = require("../../data-hooks.js");
var import_adsense_source_input = require("./adsense-source-input.js");
var import_html_source_input = require("./html-source-input.js");
const InsertModal = ({ nodeId, closeModal }) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const logBi = (0, import_bi_context_provider.useBiNext)({ pluginId: "html", modalId: import_consts.HTML_EDIT_MODAL_ID, nodeId });
  const { patchPmNodeAttrs, pmNodeAttrs } = (0, import_use_node_attrs.useNodeAttrs)(nodeId, "HTML");
  const [htmlNodeAttrs, setHtmlNodeAttrs] = (0, import_react.useState)(
    pmNodeAttrs
  );
  const inputRef = (0, import_react.useRef)(null);
  const isAdsense = htmlNodeAttrs?.isAdsense ?? htmlNodeAttrs?.source === import_v1.HTMLData_Source.ADSENSE;
  const HtmlComponent = isAdsense ? import_adsense_source_input.AdsenseSourceInput : import_html_source_input.HtmlSourceInput;
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { minHeight: 446 } }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.Panel, { closeButtonProps: { onClick: closeModal }, dataHook: import_data_hooks.EDIT_PANEL }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.PanelHeader, { title: t("HtmlPlugin_Edit_Modal_Title") }), /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { direction: "vertical", padding: "SP3" }, /* @__PURE__ */ import_react.default.createElement(
    HtmlComponent,
    {
      htmlNodeAttrs,
      onHtmlInputChange: (html) => {
        setHtmlNodeAttrs({ url: null, html });
      },
      onLinkInputChange: (url) => {
        setHtmlNodeAttrs({ url: url ?? null, html: null });
      },
      inputRef
    }
  )), /* @__PURE__ */ import_react.default.createElement(import_design_system.SidePanel.Footer, { showDivider: true }, /* @__PURE__ */ import_react.default.createElement(
    import_ui_components.FooterActions,
    {
      onCancel: closeModal,
      onSave: () => {
        if (htmlNodeAttrs?.url && !(0, import_contains_url.containsUrl)(htmlNodeAttrs.url)) {
          inputRef.current?.focus();
          return;
        }
        htmlNodeAttrs && patchPmNodeAttrs?.(htmlNodeAttrs);
        closeModal();
      },
      saveButtonLabel: t("HtmlEditPanel_Update"),
      dataHook: import_data_hooks.EDIT_PANEL_FOOTER_ACTIONS,
      logBi
    }
  ))));
};
//# sourceMappingURL=insert-modal.js.map
