// menu-plugin.ts
import { MenuItem } from "prosemirror-menu";
import { menuBar } from "prosemirror-menu";
import { toggleMark } from "prosemirror-commands";
import { Plugin, PluginKey } from "prosemirror-state";


const menuPluginKey = new PluginKey('menuPlugin')
// Modify the menuBar function to accept customSchema as a parameter
export function createMenuPlugin(customSchema: any) {
  const boldButton = new MenuItem({
    title: "Bold",
    run: toggleMark(customSchema.marks.bold),
    active: (state) => state.selection.$head.marks().some(mark => mark.type === customSchema.marks.bold),
  });

  const italicButton = new MenuItem({
    title: "Italic",
    run: toggleMark(customSchema.marks.italic),
    active: (state) => state.selection.$head.marks().some(mark => mark.type === customSchema.marks.italic),
  });

  const menuContent = [
    [boldButton, italicButton]  // Array of buttons or other menu items
  ];

  menuBar({
    content: menuContent,
    floating: true,
  });
  console.log('Creating menu plugin');

  return new Plugin({
    key: menuPluginKey
  })

}
