import { getAllBooks } from './books.api';
import { useSuspenseQuery } from '@tanstack/react-query';

const BooksList: React.FC = () => {
  const { data: books } = useSuspenseQuery({
    queryKey: ['books'],
    queryFn: getAllBooks,
  });

  if (books.length === 0) {
    return <div>Keine Bücher gefunden</div>;
  } else {
    return (
      <table>
        <thead>
          <tr>
            <th>Titel</th>
            <th>Autor</th>
            <th>ISBN</th>
          </tr>
        </thead>
        <tbody>
          {books.map((book) => (
            <tr key={book.id}>
              <td>{book.title}</td>
              <td>{book.author}</td>
              <td>{book.isbn}</td>
            </tr>
          ))}
        </tbody>
      </table>
    );
  }
};

export default BooksList;
