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

export type PostContextValue = {
  groupId: number | undefined;
  eventId: number | undefined;
};

const PostContext = createContext<PostContextValue>({
  groupId: undefined,
  eventId: undefined,
});

type PostProvider = PostContextValue;

export const PostProvider: FC<
  React.PropsWithChildren<PostProvider>
> = props => {
  const { children, groupId, eventId } = props;

  return (
    <PostContext.Provider value={{ groupId, eventId }}>
      {children}
    </PostContext.Provider>
  );
};

export const usePost = () => useContext(PostContext);

export const PostConsumer = PostContext.Consumer;

export default PostContext;
