import React from "react";

import { getAllBooks, SimpleBook } from "../lib/books";

export default function Home(props: Props) {
  return (
    <ol>
      {props.books.map((book, idx) => {
        return (
          <li key={`${idx}_${book.isbn}`}>
            {book.title}; {book.authors}; {book.isbn}
          </li>
        );
      })}
    </ol>
  );
}

interface Props {
  books: SimpleBook[];
}

export async function getServerSideProps() {
  return {
    props: {
      books: await getAllBooks(),
    },
  };
}
