import React, { createContext, useContext } from 'react';
import { RectCords } from 'folds';

type ForumMessageMenuContextValue = {
  openMenu: (anchor: RectCords) => void;
};

const ForumMessageMenuContext = createContext<ForumMessageMenuContextValue | null>(null);

export function ForumMessageMenuProvider({
  openMenu,
  children,
}: {
  openMenu: (anchor: RectCords) => void;
  children: React.ReactNode;
}) {
  return (
    <ForumMessageMenuContext.Provider value={{ openMenu }}>
      {children}
    </ForumMessageMenuContext.Provider>
  );
}

export function useForumMessageMenu() {
  return useContext(ForumMessageMenuContext);
}
