import { FC, createContext, useContext } from 'react';

export type MoreMenuContextValue = {
  closeMenu: () => void;
};

export const MoreMenuContext = createContext<MoreMenuContextValue>({
  closeMenu: () => null,
});

export type MoreMenuProviderProps = {
  closeMenu: () => void;
};

export const MoreMenuProvider: FC<
  React.PropsWithChildren<MoreMenuProviderProps>
> = props => {
  const { children, closeMenu } = props;

  return (
    <MoreMenuContext.Provider
      value={{
        closeMenu,
      }}
    >
      {children}
    </MoreMenuContext.Provider>
  );
};

export const useMoreMenu = () => useContext(MoreMenuContext);

export const ScrollToMessageConsumer = MoreMenuContext.Consumer;

export default MoreMenuContext;
