import { headers } from 'next/headers';
import { readFile } from 'node:fs/promises';

type Book = {
  id: number;
  title: string;
  author: string;
  isbn: string;
  rating: number;
};

async function getBooks(): Promise<Book[]> {
  const booksData = await readFile('./data.json', 'utf-8');
  return JSON.parse(booksData).books;
}

const BooksList: React.FC = async () => {
  console.log(headers());

  const books = await getBooks();

  return (
    <div>
      <h1>Bücherliste</h1>
      <ul>
        {books.map((book) => (
          <li key={book.id}>{book.title}</li>
        ))}
      </ul>
    </div>
  );
};

export default BooksList;
