import {
  ArrowDownSmall,
  ArrowUpSmall,
  DuplicateSmall,
  ReplaceSmall,
  StatusCompleteSmall
} from "@wix/wix-ui-icons-common";
import React, { useContext } from "react";
import { EditorContext } from "./../../../ricos-context/index.js";
import {
  changeTonePrompts,
  makeLongerPrompt,
  makeShorterPrompt,
  rephrasePrompt
} from "../../prompts.js";
import { getPromptBiValue } from "../../utils/get-prompt-bi.js";
const useAiModalSelectors = ({
  selection,
  prompts,
  state,
  submitPrompt,
  closeModal,
  publishModalAction,
  contextualResultActions
}) => {
  const { adapter } = useContext(EditorContext);
  const textualPrompt = React.useMemo(() => {
    switch (state.type) {
      case "INITIAL": {
        return state.textualPrompt;
      }
      case "IN_PROGRESS": {
        return "";
      }
      case "RESULTS": {
        return state.textualPrompt;
      }
      default: {
        return "";
      }
    }
  }, [state]);
  const promptsList = React.useMemo(() => {
    switch (state.type) {
      case "INITIAL": {
        return prompts.selectionPrompts;
      }
      default: {
        return [];
      }
    }
  }, [state.type, selection, prompts]);
  const getResultActions = React.useCallback(
    (entry) => {
      const currentContent = entry.response;
      const copyAction = {
        name: "copy",
        type: "action",
        title: "AIPlugin_Action_Copy",
        icon: DuplicateSmall,
        onClick: () => {
          publishModalAction("copy");
          navigator.clipboard.writeText(currentContent.plainContent);
        }
      };
      const contextualSelectionActions = contextualResultActions ?? (selection ? [
        {
          name: "replace",
          type: "action",
          title: "AIPlugin_Action_Replace",
          icon: ReplaceSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "replace"
            });
            publishModalAction("replace");
            closeModal();
          }
        },
        {
          name: "insert-below",
          type: "action",
          title: "AIPlugin_Action_InsertBelow",
          icon: ArrowDownSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "after"
            });
            publishModalAction("insert-below");
            closeModal();
          }
        },
        {
          name: "insert-above",
          type: "action",
          title: "AIPlugin_Action_InsertAbove",
          icon: ArrowUpSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "before"
            });
            publishModalAction("insert-above");
            closeModal();
          }
        },
        copyAction
      ] : [
        {
          name: "insert",
          type: "action",
          title: "AIPlugin_Action_Insert",
          icon: StatusCompleteSmall,
          onClick: async () => {
            adapter.tiptapEditor.commands.insertAiGeneratedContent(currentContent, {
              position: "replace"
            });
            publishModalAction("replace");
            closeModal();
          }
        },
        {
          name: "rephrase",
          type: "action",
          title: rephrasePrompt.title,
          icon: rephrasePrompt.icon,
          onClick: () => {
            submitPrompt(rephrasePrompt, currentContent.htmlContent);
            publishModalAction("prompt", getPromptBiValue(rephrasePrompt));
          }
        },
        copyAction
      ]);
      const modifyActions = [
        { type: "section", title: "AIPlugin_Actions_Section_Modify" },
        {
          name: "rephrase",
          type: "action",
          title: rephrasePrompt.title,
          icon: rephrasePrompt.icon,
          onClick: () => {
            submitPrompt(rephrasePrompt, currentContent.htmlContent);
            publishModalAction("prompt", getPromptBiValue(rephrasePrompt));
          }
        },
        {
          name: "make-shorter",
          type: "action",
          title: makeShorterPrompt.title,
          icon: makeShorterPrompt.icon,
          onClick: () => {
            submitPrompt(makeShorterPrompt, currentContent.htmlContent);
            publishModalAction("prompt", getPromptBiValue(makeShorterPrompt));
          }
        },
        {
          name: "make-longer",
          type: "action",
          title: makeLongerPrompt.title,
          icon: makeLongerPrompt.icon,
          onClick: () => {
            submitPrompt(makeLongerPrompt, currentContent.htmlContent);
            publishModalAction(getPromptBiValue(makeLongerPrompt));
          }
        }
      ];
      const changeToneActions = [
        { type: "section", title: "AIPlugin_Actions_Section_ChangeTone" },
        ...changeTonePrompts.map((prompt) => ({
          name: "change-tone",
          type: "action",
          title: prompt.title,
          icon: prompt.icon,
          onClick: () => {
            submitPrompt(prompt, currentContent.htmlContent);
            publishModalAction("prompt", 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
  };
};
export {
  useAiModalSelectors
};
//# sourceMappingURL=use-ai-modal-selectors.js.map
