import { Dropdown, DropdownSmall } from "@wix/wix-ui-icons-common";
import { TIPTAP_COLLAPSIBLE_LIST_TYPE } from "./../ricos-content/index.js";
import { findNodeClosestToSelection } from "./../ricos-plugins/index.js";
import {
  Node_Type,
  RicosPluginToolbarNames,
  createShortcut,
  quickActionsModalSections
} from "./../ricos-types/index.js";
import {
  collapsibleItemBodyConverter,
  collapsibleItemConverter,
  collapsibleItemTitleConverter,
  collapsibleListConverter
} from "./collapsible-list-converters.js";
import { DEFAULTS } from "./defaults.js";
import { getAddButtons } from "./get-add-buttons.js";
import { getToolbarButtons } from "./get-toolbar-buttons.js";
import { defaultCollapsibleList } from "./tiptap/defaults.js";
import { handleCollapsibleBackspace } from "./tiptap/keyboard-shortcuts.js";
import { tiptapExtensions } from "./tiptap/tiptap.js";
import { COLLAPSIBLE_LIST_TYPE } from "./types.js";
const pluginCollapsibleList = (config) => {
  const pluginConfig = {
    type: "collapsibleList",
    ...DEFAULTS.config,
    ...config
  };
  return {
    config: pluginConfig,
    type: COLLAPSIBLE_LIST_TYPE,
    pmMarkConverters: [],
    pmNodeConverters: [
      collapsibleListConverter,
      collapsibleItemConverter,
      collapsibleItemTitleConverter,
      collapsibleItemBodyConverter
    ],
    tiptapExtensions,
    getAddButtons,
    toolbar: {
      names: [RicosPluginToolbarNames.COLLAPSIBLE_LIST],
      getButtons: getToolbarButtons,
      isVisible: (selection, { adapter: { tiptapEditor } }) => {
        const isVisibleInSelection = "node" in selection && selection.node?.type.name === TIPTAP_COLLAPSIBLE_LIST_TYPE;
        if (isVisibleInSelection) {
          return true;
        }
        if ("node" in selection) {
          return false;
        }
        return findNodeClosestToSelection(tiptapEditor, TIPTAP_COLLAPSIBLE_LIST_TYPE) !== null;
      },
      resolveReferenceElement: (tiptapEditor) => {
        return findNodeClosestToSelection(tiptapEditor, TIPTAP_COLLAPSIBLE_LIST_TYPE)?.element ?? null;
      }
    },
    shortcuts: [
      createShortcut({
        name: "CollapsibleListBackspace",
        description: void 0,
        group: "ShortcutsSheet_Section_Formatting",
        keys: {
          macOs: "Backspace",
          windows: "Backspace"
        },
        enabled: true,
        showInShortcutSheet: false,
        command: ({ editor, event }) => handleCollapsibleBackspace(editor, event)
      }),
      createShortcut({
        name: "CollapsibleListMetaBackspace",
        description: void 0,
        group: "ShortcutsSheet_Section_Formatting",
        keys: {
          macOs: "Meta+Backspace",
          windows: "Ctrl+Backspace"
        },
        enabled: true,
        showInShortcutSheet: false,
        command: ({ editor, event }) => handleCollapsibleBackspace(editor, event)
      }),
      createShortcut({
        name: "MoveToNextElementTab",
        description: "ShortcutsSheet_CollapsibleList_MoveToNextElement",
        group: "ShortcutsSheet_Section_CollapsibleList",
        keys: {
          macOs: "Tab",
          windows: "Tab"
        },
        enabled: false,
        showInShortcutSheet: true,
        command: () => "continue"
      }),
      createShortcut({
        name: "MoveToNextElementEnter",
        description: "ShortcutsSheet_CollapsibleList_MoveToNextElement",
        group: "ShortcutsSheet_Section_CollapsibleList",
        keys: {
          macOs: "Enter",
          windows: "Enter"
        },
        enabled: false,
        showInShortcutSheet: true,
        command: () => "continue"
      }),
      createShortcut({
        name: "SelectEntireList",
        description: "ShortcutsSheet_CollapsibleList_SelectTheEntireList",
        group: "ShortcutsSheet_Section_CollapsibleList",
        keys: {
          macOs: "Meta+A",
          windows: "Ctrl+A"
        },
        enabled: false,
        showInShortcutSheet: true,
        command: () => "continue"
      })
    ],
    getQuickActions: ({ pluginServices }) => [
      {
        id: Node_Type.COLLAPSIBLE_LIST,
        title: "QuickActionsPlugin_ActionTitle_ExpandableList",
        icon: pluginServices?.context.isMobile ? Dropdown : DropdownSmall,
        section: quickActionsModalSections.FormatLayout,
        tags: ["collapsible list", "accordion", "toggle list", "hidden content"],
        command: ({ publicCommands }) => {
          publicCommands.insertBlockWithBlankLines(COLLAPSIBLE_LIST_TYPE, defaultCollapsibleList, {
            updateSelection: "text"
          });
        }
      }
    ]
  };
};
export {
  pluginCollapsibleList
};
//# sourceMappingURL=editor.js.map

import { injectCss } from "./viewer-styles-inject.js";
injectCss();
