'use client';

import { Book } from './Book';
import { useRouter } from 'next/navigation';

type Props = {
  book: Book;
};

const DeleteButton: React.FC<Props> = ({ book }) => {
  const router = useRouter();

  async function handleDelete() {
    await fetch(`/api/books/${book.id}`, {
      method: 'DELETE',
    });
    router.push('/books');
  }

  return <button onClick={handleDelete}>löschen</button>;
};

export default DeleteButton;
