import { FC, useRef } from 'react';

import { useSearchParams } from 'react-router-dom';

import { Comment } from 'src/types/comments';
import { CommentsSystem } from 'src/components/comments/CommentsSystem';

export type EventPostCommentsProps = {
  postId: number;
  commentCount: number;
  lastComments: Comment[];
  commentsEnabled?: boolean;
};

export const EventPostComments: FC<EventPostCommentsProps> = ({
  postId,
  commentCount,
  lastComments,
  commentsEnabled = true,
}) => {
  const commentToScrollToRef = useRef(null);
  const [searchParams] = useSearchParams();
  const parentIdParams = searchParams.get('parentId');

  return (
    <CommentsSystem
      context="events"
      postId={postId}
      commentCount={commentCount}
      lastComments={lastComments || []}
      commentToScrollToRef={commentToScrollToRef}
      commentsEnabled={commentsEnabled}
      EventsProps={{ parentIdParams }}
    />
  );
};

export default EventPostComments;
