"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_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_bi_context_provider = require("./../../_shared/bi-context-provider/bi-context-provider.js");
var import_wix_rich_content_common = require("./../../wix-rich-content-common/index.js");
var import_ui_components = require("./../../ui-components/index.js");
var import_data_hooks = require("../data-hooks.js");
var import_types = require("../types.js");
var import_audio_embed = require("./audio-embed.js");
var import_audio_upload = require("./audio-upload.js");
const SourceOptionValue = {
  EMBED: "embed",
  UPLOAD: "upload"
};
const InsertModal = ({
  nodeId,
  componentData,
  embedType,
  modalId
}) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const modalService = (0, import_react.useContext)(import_ricos_context.ModalServiceContext) || {};
  const pluginsEvents = (0, import_react.useContext)(import_ricos_context.PluginsEventsContext);
  const logBi = (0, import_bi_context_provider.useBiNext)({ pluginId: "audio", modalId, nodeId });
  const [selectedSource, setSelectedSource] = (0, import_react.useState)(
    embedType || componentData?.audio?.src?.url ? "embed" : "upload"
  );
  const onSourceToggleClick = (_, value) => {
    selectedSource !== value && pluginsEvents.publishPluginPopoverTabSwitch?.({
      pluginId: import_types.AUDIO_TYPE,
      buttonName: import_wix_rich_content_common.MEDIA_POPOVERS_TABS_NAMES_BI[value.toLowerCase()]
    });
    setSelectedSource(value);
    logBi({ dataHook: import_data_hooks.INSERT_AUDIO_MODAL_SOURCE_TOGGLE, value });
  };
  const closeModal = () => modalService.closeModal(modalId);
  return /* @__PURE__ */ import_react.default.createElement(
    import_ui_components.Panel,
    {
      closeButtonProps: { onClick: closeModal },
      dataHook: import_data_hooks.INSERT_AUDIO_MODAL,
      height: "fit-content"
    },
    /* @__PURE__ */ import_react.default.createElement(import_ui_components.PanelHeader, { title: t("Audio_Modal_Header_Title") }),
    /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { direction: "vertical", padding: "SP3", gap: "SP3" }, /* @__PURE__ */ import_react.default.createElement(import_design_system.FormField, { label: t("Audio_Modal_Toggle_Source_Label") }, /* @__PURE__ */ import_react.default.createElement(
      import_design_system.SegmentedToggle,
      {
        defaultSelected: selectedSource,
        size: "small",
        onClick: onSourceToggleClick,
        dataHook: import_data_hooks.INSERT_AUDIO_MODAL_SOURCE_TOGGLE
      },
      /* @__PURE__ */ import_react.default.createElement(import_design_system.SegmentedToggle.Button, { value: SourceOptionValue.EMBED, prefixIcon: /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.LinkSmall, null) }, t("MediaModal_Tabs_Embed")),
      /* @__PURE__ */ import_react.default.createElement(
        import_design_system.SegmentedToggle.Button,
        {
          value: SourceOptionValue.UPLOAD,
          prefixIcon: /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.UploadExportSmall, null)
        },
        t("MediaModal_Tabs_Upload")
      )
    )), selectedSource === "embed" && /* @__PURE__ */ import_react.default.createElement(import_audio_embed.AudioEmbed, { componentData, closeModal, logBi }), selectedSource === "upload" && /* @__PURE__ */ import_react.default.createElement(import_audio_upload.AudioUpload, { nodeId, closeModal, logBi }))
  );
};
//# sourceMappingURL=insert-modal.js.map
