"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 ai_actions_modal_exports = {};
__export(ai_actions_modal_exports, {
  AiActionsModal: () => AiActionsModal
});
module.exports = __toCommonJS(ai_actions_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_dropdown_modal = require("./../../_shared/dropdown-modal/dropdown-modal.js");
var import_list_item_select = require("./../../_shared/list-item-select/list-item-select.js");
var import_uncreachable = require("./../../_shared/uncreachable.js");
var import_data_hooks = require("../data-hooks.js");
var import_prompts = require("../prompts.js");
var import_types = require("../types.js");
const AiActionsModal = ({
  toggleAiContentModal,
  toggleAiImageModal,
  enableImageGeneration,
  config
}) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const { adapter } = (0, import_react.useContext)(import_ricos_context.EditorContext);
  const modalService = (0, import_react.useContext)(import_ricos_context.ModalServiceContext);
  const closeModal = import_react.default.useCallback(() => {
    modalService.closeModal(import_types.AI_ACTIONS_MODAL_ID);
  }, [modalService]);
  const [prompts] = import_react.default.useState(
    () => config.configurePrompts ? config.configurePrompts(import_prompts.defaultPromptsConfiguration) : import_prompts.defaultPromptsConfiguration
  );
  const openAiContentModal = import_react.default.useCallback(
    (initialPrompt) => {
      toggleAiContentModal(adapter.tiptapEditor, modalService, initialPrompt);
    },
    [adapter.tiptapEditor, modalService]
  );
  const openAiImageModal = import_react.default.useCallback(() => {
    toggleAiImageModal(adapter.tiptapEditor, modalService, true);
  }, [adapter.tiptapEditor, modalService]);
  const options = import_react.default.useMemo(() => {
    const writePromptItem = /* @__PURE__ */ import_react.default.createElement(
      import_list_item_select.ListItemSelect,
      {
        key: "AIPlugin_Action_WritePrompt",
        dataHook: "AIPlugin_Action_WritePrompt",
        prefix: /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.EditSmall, null),
        title: t("AIPlugin_Action_WritePrompt"),
        onSelect: () => openAiContentModal()
      }
    );
    const imageGenerationItems = enableImageGeneration ? [
      /* @__PURE__ */ import_react.default.createElement(
        import_design_system.ListItemSection,
        {
          key: "AIPlugin_Prompts_Section_Image",
          title: t("AIPlugin_Prompts_Section_Image")
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_list_item_select.ListItemSelect,
        {
          key: "AIPlugin_Action_GenerateImage",
          dataHook: "AIPlugin_Action_GenerateImage",
          prefix: /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.ImageSparklesSmall, null),
          title: t("AIPlugin_Action_GenerateImage"),
          onSelect: () => openAiImageModal()
        }
      )
    ] : [];
    const promptItems = prompts.floatingToolbarButtonPrompts.map((prompt) => {
      switch (prompt.type) {
        case "prompt": {
          const Icon = prompt.icon;
          return /* @__PURE__ */ import_react.default.createElement(
            import_list_item_select.ListItemSelect,
            {
              key: prompt.title,
              dataHook: prompt.title,
              prefix: Icon ? /* @__PURE__ */ import_react.default.createElement(Icon, null) : void 0,
              title: t(prompt.title),
              onSelect: () => openAiContentModal(prompt)
            }
          );
        }
        case "section": {
          return /* @__PURE__ */ import_react.default.createElement(import_design_system.ListItemSection, { key: prompt.title, title: t(prompt.title) });
        }
        default: {
          throw (0, import_uncreachable.unreachable)(prompt);
        }
      }
    });
    return [writePromptItem, ...imageGenerationItems, ...promptItems];
  }, [
    prompts.floatingToolbarButtonPrompts,
    openAiContentModal,
    openAiImageModal,
    t,
    enableImageGeneration
  ]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_dropdown_modal.DropdownModal,
    {
      dataHook: import_data_hooks.AI_MODAL_FLOATING_MENU_POPOVER,
      title: t("AIPlugin_Actions_Title"),
      onCloseButtonClick: closeModal,
      minWidth: 242,
      maxHeight: 242,
      options
    }
  );
};
//# sourceMappingURL=ai-actions-modal.js.map
