"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 use_ai_modal_selectors_exports = {};
__export(use_ai_modal_selectors_exports, {
  useAiModalSelectors: () => useAiModalSelectors
});
module.exports = __toCommonJS(use_ai_modal_selectors_exports);
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_prompts = require("../../prompts.js");
var import_get_prompt_bi = require("../../utils/get-prompt-bi.js");
const useAiModalSelectors = ({
  selection,
  prompts,
  state,
  submitPrompt,
  closeModal,
  publishModalAction,
  contextualResultActions
}) => {
  const { adapter } = (0, import_react.useContext)(import_ricos_context.EditorContext);
  const textualPrompt = import_react.default.useMemo(() => {
    switch (state.type) {
      case "INITIAL": {
        return state.textualPrompt;
      }
      case "IN_PROGRESS": {
        return "";
      }
      case "RESULTS": {
        return state.textualPrompt;
      }
      default: {
        return "";
      }
    }
  }, [state]);
  const promptsList = import_react.default.useMemo(() => {
    switch (state.type) {
      case "INITIAL": {
        return prompts.selectionPrompts;
      }
      default: {
        return [];
      }
    }
  }, [state.type, selection, prompts]);
  const getResultActions = import_react.default.useCallback(
    (entry) => {
      const currentContent = entry.response;
      const copyAction = {
        name: "copy",
        type: "action",
        title: "AIPlugin_Action_Copy",
        icon: import_wix_ui_icons_common.DuplicateSmall,
        onClick: () => {
          publishModalAction("copy");
          navigator.clipboard.writeText(currentContent.plainContent);
        }
      };
      const contextualSelectionActions = contextualResultActions ?? (selection ? [
        {
          name: "replace",
          type: "action",
          title: "AIPlugin_Action_Replace",
          icon: import_wix_ui_icons_common.ReplaceSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "replace"
            });
            publishModalAction("replace");
            closeModal();
          }
        },
        {
          name: "insert-below",
          type: "action",
          title: "AIPlugin_Action_InsertBelow",
          icon: import_wix_ui_icons_common.ArrowDownSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "after"
            });
            publishModalAction("insert-below");
            closeModal();
          }
        },
        {
          name: "insert-above",
          type: "action",
          title: "AIPlugin_Action_InsertAbove",
          icon: import_wix_ui_icons_common.ArrowUpSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "before"
            });
            publishModalAction("insert-above");
            closeModal();
          }
        },
        copyAction
      ] : [
        {
          name: "insert",
          type: "action",
          title: "AIPlugin_Action_Insert",
          icon: import_wix_ui_icons_common.StatusCompleteSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "replace"
            });
            publishModalAction("replace");
            closeModal();
          }
        },
        {
          name: "rephrase",
          type: "action",
          title: import_prompts.rephrasePrompt.title,
          icon: import_prompts.rephrasePrompt.icon,
          onClick: () => {
            submitPrompt(import_prompts.rephrasePrompt, currentContent.htmlContent);
            publishModalAction("prompt", (0, import_get_prompt_bi.getPromptBiValue)(import_prompts.rephrasePrompt));
          }
        },
        copyAction
      ]);
      const modifyActions = [
        { type: "section", title: "AIPlugin_Actions_Section_Modify" },
        {
          name: "rephrase",
          type: "action",
          title: import_prompts.rephrasePrompt.title,
          icon: import_prompts.rephrasePrompt.icon,
          onClick: () => {
            submitPrompt(import_prompts.rephrasePrompt, currentContent.htmlContent);
            publishModalAction("prompt", (0, import_get_prompt_bi.getPromptBiValue)(import_prompts.rephrasePrompt));
          }
        },
        {
          name: "make-shorter",
          type: "action",
          title: import_prompts.makeShorterPrompt.title,
          icon: import_prompts.makeShorterPrompt.icon,
          onClick: () => {
            submitPrompt(import_prompts.makeShorterPrompt, currentContent.htmlContent);
            publishModalAction("prompt", (0, import_get_prompt_bi.getPromptBiValue)(import_prompts.makeShorterPrompt));
          }
        },
        {
          name: "make-longer",
          type: "action",
          title: import_prompts.makeLongerPrompt.title,
          icon: import_prompts.makeLongerPrompt.icon,
          onClick: () => {
            submitPrompt(import_prompts.makeLongerPrompt, currentContent.htmlContent);
            publishModalAction((0, import_get_prompt_bi.getPromptBiValue)(import_prompts.makeLongerPrompt));
          }
        }
      ];
      const changeToneActions = [
        { type: "section", title: "AIPlugin_Actions_Section_ChangeTone" },
        ...import_prompts.changeTonePrompts.map((prompt) => ({
          name: "change-tone",
          type: "action",
          title: prompt.title,
          icon: prompt.icon,
          onClick: () => {
            submitPrompt(prompt, currentContent.htmlContent);
            publishModalAction("prompt", (0, import_get_prompt_bi.getPromptBiValue)(prompt));
          }
        }))
      ];
      const actions = [...contextualSelectionActions, ...modifyActions, ...changeToneActions];
      return typeof entry.requestPrompt !== "string" && entry.requestPrompt.sortResultActionsFn ? actions.sort(entry.requestPrompt.sortResultActionsFn) : actions;
    },
    [selection, adapter, contextualResultActions]
  );
  return {
    textualPrompt,
    promptsList,
    getResultActions
  };
};
//# sourceMappingURL=use-ai-modal-selectors.js.map
