import { useTranslation } from "react-i18n-lite"; import { readingStatusKey } from "@/locales"; import styles from "../../pages/Library.module.css"; const LIBRARY_STATUS_COLORS: Record = { want_to_read: { bg: "#dbeafe", text: "#1d4ed8" }, reading: { bg: "#dcfce7", text: "#16a34a" }, finished: { bg: "#f3e8ff", text: "#9333ea" }, dnf: { bg: "#fef3c7", text: "#b45309" }, }; interface LibraryBookCardData { id: number; title: string; author: string; genre: string; format: string; cover_image: string | null; reading_status: string; progressPercent: number | null; } function badgeLabel( book: LibraryBookCardData, t: (key: string, params?: Record) => string, ): string { if (book.reading_status === "reading" && book.progressPercent != null && book.progressPercent > 0) { return t("library.readingStatus.readingWithProgress", { percent: String(book.progressPercent), }); } return t(readingStatusKey(book.reading_status)); } interface LibraryBookCardProps { book: LibraryBookCardData; isMobile: boolean; onOpen: () => void; onContextMenu: (e: React.MouseEvent) => void; } export function LibraryBookCard({ book, isMobile, onOpen, onContextMenu, }: LibraryBookCardProps) { const { t } = useTranslation(); const sc = LIBRARY_STATUS_COLORS[book.reading_status] ?? { bg: "#f3f4f6", text: "#6b7280" }; const showProgressBar = book.reading_status === "reading" && book.progressPercent != null && book.progressPercent > 0; return (
{book.cover_image ? ( {book.title} ) : ( 📖 )} {showProgressBar && (
)} {!isMobile && ( {badgeLabel(book, t)} )}

{book.title}

{book.author || t("common.unknownAuthor")}

{isMobile && ( {badgeLabel(book, t)} )}
{book.genre && ( {book.genre} )}
); }