"use client"; import { CoverClient } from "./cover-client"; import { ProgressBar } from "./progress-bar"; import type { BookCoverProps } from "./cover-utils"; import { getImageUrl } from "./cover-utils"; import { useImageUrl } from "@/hooks/useImageUrl"; import { ClientOfflineBookService } from "@/lib/services/client-offlinebook.service"; import { MarkAsReadButton } from "./mark-as-read-button"; import { MarkAsUnreadButton } from "./mark-as-unread-button"; import { BookOfflineButton } from "./book-offline-button"; import { useTranslate } from "@/hooks/useTranslate"; import type { KomgaBook } from "@/types/komga"; import { formatDate } from "@/lib/utils"; import { useBookOfflineStatus } from "@/hooks/useBookOfflineStatus"; import { WifiOff } from "lucide-react"; // Fonction utilitaire pour obtenir les informations de statut de lecture const getReadingStatusInfo = (book: KomgaBook, t: (key: string, options?: any) => string) => { if (!book.readProgress) { return { label: t("books.status.unread"), className: "bg-yellow-500/10 text-yellow-500", }; } if (book.readProgress.completed) { const readDate = book.readProgress.readDate ? formatDate(book.readProgress.readDate) : null; return { label: readDate ? t("books.status.readDate", { date: readDate }) : t("books.status.read"), className: "bg-green-500/10 text-green-500", }; } const currentPage = ClientOfflineBookService.getCurrentPage(book); if (currentPage > 0) { return { label: t("books.status.progress", { current: currentPage, total: book.media.pagesCount, }), className: "bg-blue-500/10 text-blue-500", }; } return { label: t("books.status.unread"), className: "bg-yellow-500/10 text-yellow-500", }; }; export function BookCover({ book, alt, className, showProgressUi = true, onSuccess, showControls = true, showOverlay = true, overlayVariant = "default", }: BookCoverProps) { const { t } = useTranslate(); const { isAccessible } = useBookOfflineStatus(book.id); const baseUrl = getImageUrl("book", book.id); const imageUrl = useImageUrl(baseUrl); const isCompleted = book.readProgress?.completed || false; const currentPage = ClientOfflineBookService.getCurrentPage(book); const totalPages = book.media.pagesCount; const showProgress = showProgressUi && currentPage && totalPages && currentPage > 0 && !isCompleted; const statusInfo = getReadingStatusInfo(book, t); const isRead = book.readProgress?.completed || false; const hasReadProgress = book.readProgress !== null || currentPage > 0; // Détermine si le livre doit être grisé (non accessible hors ligne) const isUnavailable = !isAccessible; const handleMarkAsRead = () => { onSuccess?.(book, "read"); }; const handleMarkAsUnread = () => { onSuccess?.(book, "unread"); }; return ( <>
{book.metadata.title || (book.metadata.number ? t("navigation.volume", { number: book.metadata.number }) : "")}
{t("books.status.progress", { current: currentPage, total: book.media.pagesCount, })}