import { fetchAuthors, AuthorsPageDto } from "../../lib/api"; import { getServerTranslations } from "../../lib/i18n/server"; import { LiveSearchForm } from "../components/LiveSearchForm"; import { Card, CardContent, OffsetPagination } from "../components/ui"; import Link from "next/link"; export const dynamic = "force-dynamic"; export default async function AuthorsPage({ searchParams, }: { searchParams: Promise<{ [key: string]: string | string[] | undefined }>; }) { const { t } = await getServerTranslations(); const searchParamsAwaited = await searchParams; const searchQuery = typeof searchParamsAwaited.q === "string" ? searchParamsAwaited.q : ""; const sort = typeof searchParamsAwaited.sort === "string" ? searchParamsAwaited.sort : undefined; const page = typeof searchParamsAwaited.page === "string" ? parseInt(searchParamsAwaited.page) : 1; const limit = typeof searchParamsAwaited.limit === "string" ? parseInt(searchParamsAwaited.limit) : 20; const authorsPage = await fetchAuthors( searchQuery || undefined, page, limit, sort, ).catch(() => ({ items: [], total: 0, page: 1, limit }) as AuthorsPageDto); const totalPages = Math.ceil(authorsPage.total / limit); const hasFilters = searchQuery || sort; const sortOptions = [ { value: "", label: t("authors.sortName") }, { value: "books", label: t("authors.sortBooks") }, ]; return ( <>

{t("authors.title")}

{/* Results count */}

{authorsPage.total} {t("authors.title").toLowerCase()} {searchQuery && <> {t("authors.matchingQuery")} "{searchQuery}"}

{/* Authors List */} {authorsPage.items.length > 0 ? ( <>
{authorsPage.items.map((author) => (
{author.name.charAt(0).toUpperCase()}

{author.name}

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

{hasFilters ? t("authors.noResults") : t("authors.noAuthors")}

)} ); }