import type { Editor } from "@tiptap/react";

export interface SlashCommandItem {
  label: string;
  icon: string;
  description: string;
  /** If true, the action reads onSubpageCreate from editor.storage.slashCommands */
  isSubpage?: boolean;
  action: (editor: Editor) => void;
}

export const slashCommandItems: SlashCommandItem[] = [
  {
    label: "Heading 1",
    icon: "H1",
    description: "Large heading",
    action: (editor) =>
      editor.chain().focus().toggleHeading({ level: 1 }).run(),
  },
  {
    label: "Heading 2",
    icon: "H2",
    description: "Medium heading",
    action: (editor) =>
      editor.chain().focus().toggleHeading({ level: 2 }).run(),
  },
  {
    label: "Heading 3",
    icon: "H3",
    description: "Small heading",
    action: (editor) =>
      editor.chain().focus().toggleHeading({ level: 3 }).run(),
  },
  {
    label: "Bullet List",
    icon: "UL",
    description: "Unordered list",
    action: (editor) => editor.chain().focus().toggleBulletList().run(),
  },
  {
    label: "Numbered List",
    icon: "OL",
    description: "Ordered list",
    action: (editor) => editor.chain().focus().toggleOrderedList().run(),
  },
  {
    label: "Inline Code",
    icon: "`c`",
    description: "Inline code (Cmd+E)",
    action: (editor) => editor.chain().focus().toggleCode().run(),
  },
  {
    label: "Code Block",
    icon: "<>",
    description: "Code snippet",
    action: (editor) => editor.chain().focus().toggleCodeBlock().run(),
  },
  {
    label: "Quote",
    icon: "\"",
    description: "Block quote",
    action: (editor) => editor.chain().focus().toggleBlockquote().run(),
  },
  {
    label: "Divider",
    icon: "---",
    description: "Horizontal rule",
    action: (editor) => editor.chain().focus().setHorizontalRule().run(),
  },
  {
    label: "Table",
    icon: "T#",
    description: "Insert a table",
    action: (editor) =>
      editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
  },
  {
    label: "Subpage",
    icon: "\uD83D\uDCC4",
    description: "Create a linked subpage",
    isSubpage: true,
    action: (editor) => {
      const callback = editor.storage.slashCommands
        ?.onSubpageCreate as
        | ((editor: Editor) => void)
        | undefined;
      if (callback) {
        callback(editor);
      }
    },
  },
];
