import Link from "next/link"; import { Card, CardHeader, CardTitle, CardDescription, CardContent, StatBox } from "@/app/components/ui"; import type { MetadataBatchReportDto, MetadataBatchResultDto, MetadataRefreshReportDto } from "@/lib/api"; import type { TranslateFunction } from "@/lib/i18n/dictionaries"; export function MetadataBatchReportCard({ report, t }: { report: MetadataBatchReportDto; t: TranslateFunction }) { return ( {t("jobDetail.batchReport")} {t("jobDetail.seriesAnalyzed", { count: String(report.total_series) })}
0 ? "error" : "default"} />
); } export function MetadataBatchResultsCard({ results, libraryId, t }: { results: MetadataBatchResultDto[]; libraryId: string | null; t: TranslateFunction; }) { if (results.length === 0) return null; return ( {t("jobDetail.resultsBySeries")} {t("jobDetail.seriesProcessed", { count: String(results.length) })} {results.map((r) => (
{libraryId ? ( {r.series_name} ) : ( {r.series_name} )} {r.status === "auto_matched" ? t("jobDetail.autoMatched") : r.status === "already_linked" ? t("jobDetail.alreadyLinked") : r.status === "no_results" ? t("jobDetail.noResults") : r.status === "too_many_results" ? t("jobDetail.tooManyResults") : r.status === "low_confidence" ? t("jobDetail.lowConfidence") : r.status === "error" ? t("common.error") : r.status}
{r.provider_used && ( {r.provider_used}{r.fallback_used ? ` ${t("metadata.fallbackUsed")}` : ""} )} {r.candidates_count > 0 && ( {r.candidates_count} {t("jobDetail.candidates", { plural: r.candidates_count > 1 ? "s" : "" })} )} {r.best_confidence != null && ( {Math.round(r.best_confidence * 100)}% {t("jobDetail.confidence")} )}
{r.best_candidate_json && (

{t("jobDetail.match", { title: (r.best_candidate_json as { title?: string }).title || r.best_candidate_json.toString() })}

)} {r.error_message && (

{r.error_message}

)}
))}
); } export function MetadataRefreshReportCard({ report, t }: { report: MetadataRefreshReportDto; t: TranslateFunction }) { return ( {t("jobDetail.refreshReport")} {t("jobDetail.refreshReportDesc", { count: String(report.total_links) })}
} /> 0 ? "error" : "default"} />
); } export function MetadataRefreshChangesCard({ report, libraryId, t }: { report: MetadataRefreshReportDto; libraryId: string | null; t: TranslateFunction; }) { if (report.changes.length === 0) return null; return ( {t("jobDetail.refreshChanges")} {t("jobDetail.refreshChangesDesc", { count: String(report.changes.length) })} {report.changes.map((r, idx) => (
{libraryId ? ( {r.series_name} ) : ( {r.series_name} )}
{r.provider} {r.status === "updated" ? t("jobDetail.refreshed") : r.status === "error" ? t("common.error") : t("jobDetail.unchanged")}
{r.error && (

{r.error}

)} {r.series_changes.length > 0 && (
{t("metadata.seriesLabel")}
{r.series_changes.map((c, ci) => (
{t(`field.${c.field}` as never) || c.field} {c.old != null ? (Array.isArray(c.old) ? (c.old as string[]).join(", ") : String(c.old)) : "—"} {c.new != null ? (Array.isArray(c.new) ? (c.new as string[]).join(", ") : String(c.new)) : "—"}
))}
)} {r.book_changes.length > 0 && (
{t("metadata.booksLabel")} ({r.book_changes.length})
{r.book_changes.map((b, bi) => (
{b.volume != null && T.{b.volume}} {b.title}
{b.changes.map((c, ci) => (
{t(`field.${c.field}` as never) || c.field} {c.old != null ? (Array.isArray(c.old) ? (c.old as string[]).join(", ") : String(c.old).substring(0, 60)) : "—"} {c.new != null ? (Array.isArray(c.new) ? (c.new as string[]).join(", ") : String(c.new).substring(0, 60)) : "—"}
))}
))}
)}
))}
); }