import Link from "next/link";
import { buttonClass } from "./button";

export const PAGE_SIZE = 20;

export function Pagination({
  page,
  total,
  pageSize = PAGE_SIZE,
  buildHref,
}: {
  page: number;
  total: number;
  pageSize?: number;
  buildHref: (page: number) => string;
}) {
  const pages = Math.max(1, Math.ceil(total / pageSize));
  if (pages <= 1) return null;
  return (
    <nav aria-label="Pagination" className="flex items-center justify-between border-t border-border px-4 py-3 text-sm">
      <span className="text-muted-foreground">
        Page {page} of {pages} · {total} results
      </span>
      <div className="flex gap-2">
        {page > 1 ? (
          <Link href={buildHref(page - 1)} className={buttonClass("secondary")}>
            Previous
          </Link>
        ) : null}
        {page < pages ? (
          <Link href={buildHref(page + 1)} className={buttonClass("secondary")}>
            Next
          </Link>
        ) : null}
      </div>
    </nav>
  );
}
