import NewsCard from "@/Entities/NewsCard/NewsCard";
import "./NewsList.scss";
import { newsStore } from "./store";

const NewsList = async () => {
  const data = await newsStore.getNews();

  if (newsStore.error) {
    return <div className="news-list">{newsStore.error}</div>;
  }

  return (
    <ul className="news-list">
      {data?.results.map((card) => (
        <li key={card.id}>
          <NewsCard
            id={card.id}
            image={card.image}
            title={card.title}
            description={card.description}
            date={card.created_at}
          />
        </li>
      ))}
    </ul>
  );
};

export default NewsList;
