import { useAppDispatch, useAppSelector } from '../../app/hooks';
import { remove, selectAllBooks } from './booksSlice';

const List: React.FC = () => {
  const books = useAppSelector(selectAllBooks);
  const dispatch = useAppDispatch();

  return (
    <table>
      <thead>
        <tr>
          <td>Titel</td>
          <td>Autor</td>
          <td>ISBN</td>
          <th></th>
        </tr>
      </thead>
      <tbody>
        {books.map((book) => (
          <tr key={book.id}>
            <td>{book.title}</td>
            <td>{book.author}</td>
            <td>{book.isbn}</td>
            <td>
              <button onClick={() => dispatch(remove(book.id))}>
                Entfernen
              </button>
            </td>
          </tr>
        ))}
      </tbody>
    </table>
  );
};

export default List;
