import "./ReviewsSection.scss";
import ReviewCard from "@/Entities/ReviewCard/ReviewCard";
import CreateReview from "@/Features/CreateReview/CreateReview";
import { newsReviewStore } from "./store";

interface INewsReviewsSectionProps {
  id: number | null | undefined;
  endpoint: string;
}

const ReviewsSection: React.FC<INewsReviewsSectionProps> = async ({
  id,
  endpoint,
}: INewsReviewsSectionProps) => {
  const list = await newsReviewStore.getReviews(endpoint, id);
  return (
    <div className="reviews-section">
      <CreateReview endpoint="news" id={id} />
      <div className="reviews-section__container">
        <h3>
          <span />
          Комментарии
        </h3>
        <div className="reviews-section__list">
          {list?.results.map((item) => (
            <ReviewCard key={item.id} item={item} />
          ))}
        </div>
      </div>
    </div>
  );
};

export default ReviewsSection;
