import type { Book } from './Book';

type Props = {
  books: Book[];
  error: string | null;
};

const BooksList: React.FC<Props> = ({ books, error }) => {
  if (error) {
    return <div>{error}</div>;
  } else 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;
