interface Props {
  page: number
  perPage: number
  total: number
  onPageChange: (page: number) => void
}

export default function Pagination({ page, perPage, total, onPageChange }: Props) {
  const pageCount = Math.max(1, Math.ceil(total / Math.max(1, perPage)))
  if (pageCount <= 1) return null

  return (
    <nav className="pagination" aria-label="Pagination">
      <button
        type="button"
        disabled={page <= 1}
        onClick={() => onPageChange(page - 1)}
      >
        ← Précédent
      </button>
      <span className="pagination-info">
        Page {page} sur {pageCount}
      </span>
      <button
        type="button"
        disabled={page >= pageCount}
        onClick={() => onPageChange(page + 1)}
      >
        Suivant →
      </button>
    </nav>
  )
}
