"use client"; import { BookCheck, Loader2 } from "lucide-react"; import { Button } from "./button"; import { useToast } from "./use-toast"; import { ClientOfflineBookService } from "@/lib/services/client-offlinebook.service"; import { useState } from "react"; import { useTranslation } from "react-i18next"; interface MarkAsReadButtonProps { bookId: string; pagesCount: number; isRead?: boolean; onSuccess?: () => void; className?: string; } export function MarkAsReadButton({ bookId, pagesCount, isRead = false, onSuccess, className, }: MarkAsReadButtonProps) { const { toast } = useToast(); const [isLoading, setIsLoading] = useState(false); const { t } = useTranslation(); const handleMarkAsRead = async (e: React.MouseEvent) => { e.stopPropagation(); // EmpĂȘcher la propagation au parent setIsLoading(true); try { ClientOfflineBookService.removeCurrentPageById(bookId); const response = await fetch(`/api/komga/books/${bookId}/read-progress`, { method: "PATCH", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ page: pagesCount, completed: true }), }); if (!response.ok) { throw new Error(t("books.actions.markAsRead.error.update")); } toast({ title: t("books.actions.markAsRead.success.title"), description: t("books.actions.markAsRead.success.description"), }); onSuccess?.(); } catch (error) { console.error("Erreur lors de la mise Ă  jour du progresseur de lecture:", error); toast({ title: t("books.actions.markAsRead.error.title"), description: t("books.actions.markAsRead.error.description"), variant: "destructive", }); } finally { setIsLoading(false); } }; return ( ); }