import { createContext, useContext } from 'react';
import type { Book } from './Book';

type BooksContextType = [Book[], React.Dispatch<React.SetStateAction<Book[]>>];

export const BooksContext = createContext<BooksContextType | null>(null);

export function useBooksContext(): BooksContextType {
  const booksContext = useContext(BooksContext);
  if (booksContext === null) {
    throw new Error('useBooksContext must be used within a BooksProvider');
  }
  return booksContext;
}
