import { fetchBooks, fetchAllSeries, BooksPageDto, SeriesPageDto, getBookCoverUrl } from "../../../lib/api"; import { getServerTranslations } from "../../../lib/i18n/server"; import { BooksGrid } from "../../components/BookCard"; import { OffsetPagination } from "../../components/ui"; import Image from "next/image"; import Link from "next/link"; export const dynamic = "force-dynamic"; export default async function AuthorDetailPage({ params, searchParams, }: { params: Promise<{ name: string }>; searchParams: Promise<{ [key: string]: string | string[] | undefined }>; }) { const { t } = await getServerTranslations(); const { name: encodedName } = await params; const authorName = decodeURIComponent(encodedName); const searchParamsAwaited = await searchParams; const page = typeof searchParamsAwaited.page === "string" ? parseInt(searchParamsAwaited.page) : 1; const limit = typeof searchParamsAwaited.limit === "string" ? parseInt(searchParamsAwaited.limit) : 20; // Fetch books by this author (server-side filtering via API) and series by this author const [booksPage, seriesPage] = await Promise.all([ fetchBooks(undefined, undefined, page, limit, undefined, undefined, authorName).catch( () => ({ items: [], total: 0, page: 1, limit }) as BooksPageDto ), fetchAllSeries(undefined, undefined, undefined, 1, 200, undefined, undefined, undefined, undefined, authorName).catch( () => ({ items: [], total: 0, page: 1, limit: 200 }) as SeriesPageDto ), ]); const totalPages = Math.ceil(booksPage.total / limit); const authorSeries = seriesPage.items; return ( <> {/* Breadcrumb */} {/* Author Header */}
{authorName.charAt(0).toUpperCase()}

{authorName}

{t("authors.bookCount", { count: String(booksPage.total), plural: booksPage.total !== 1 ? "s" : "" })} {authorSeries.length > 0 && ( {t("authors.seriesCount", { count: String(authorSeries.length), plural: authorSeries.length !== 1 ? "s" : "" })} )}
{/* Series Section */} {authorSeries.length > 0 && (

{t("authors.seriesBy", { name: authorName })}

{authorSeries.map((s) => (
{s.name}

{s.name}

{t("authors.bookCount", { count: String(s.book_count), plural: s.book_count !== 1 ? "s" : "" })}

))}
)} {/* Books Section */} {booksPage.items.length > 0 && (

{t("authors.booksBy", { name: authorName })}

)} {/* Empty State */} {booksPage.items.length === 0 && authorSeries.length === 0 && (

{t("authors.noResults")}

)} ); }