
import React from "react";
import BookForm from "./BookForm";
import BookList from "./BookList";

export default function Home({
  books,
  authors,
  statuses,
  editingBook,
  onAdd,
  onEdit,
  onDelete,
  onCancel,
  setEditingBook,
  searchQuery,
  setSearchQuery,
  statusFilter,
  setStatusFilter
}) {
  return (
    <>
      <h1 className="mb-4">Книги</h1>
      <div className="mb-3" style={{ maxWidth: 350 }}>
        <input
          type="text"
          className="form-control mb-2"
          placeholder="Поиск по названию"
          value={searchQuery}
          onChange={e => setSearchQuery(e.target.value)}
        />
        <select
          className="form-select"
          value={statusFilter}
          onChange={e => setStatusFilter(e.target.value)}
        >
          <option value="">Все статусы</option>
          {statuses.map(s => (
            <option key={s.id} value={s.name}>{s.name}</option>
          ))}
        </select>
      </div>
      <BookForm
        authors={authors}
        statuses={statuses}
        onSubmit={editingBook ? onEdit : onAdd}
        editingBook={editingBook}
        onCancel={onCancel}
      />
      <BookList
        books={books}
        authors={authors}
        statuses={statuses}
        onEdit={setEditingBook}
        onDelete={onDelete}
      />
    </>
  );
}
