"use client"; import { ErrorMessage } from "@/lib/hooks/useDownloader/types"; import { cn } from "@/lib/utils"; import { Button, Card, CardContent, CardHeader, CardTitle, Progress } from "@/ui"; import { FileTextIcon, Loader2Icon, XCircleIcon } from "lucide-react"; import { useEffect, useState } from "react"; import { t } from "i18next"; interface PDFGenerationLoadingProps { className?: string; isInProgress: boolean; percentage: number; elapsed: number; cancel: () => void; error: ErrorMessage; } export const PDFGenerationLoading = ({ isInProgress, percentage, elapsed, cancel, error, className, }: PDFGenerationLoadingProps) => { const [estimatedTime, setEstimatedTime] = useState(10); useEffect(() => { if (isInProgress && percentage > 0) { const estimatedTotal = (elapsed / percentage) * 100; setEstimatedTime(Math.max(0, Math.round(estimatedTotal - elapsed))); } }, [isInProgress, percentage, elapsed]); if (!isInProgress && !error?.errorMessage) return null; return ( {error?.errorMessage ? t("quotes.pdf_generation.error") : t("quotes.pdf_generation.title")} {isInProgress && } {error?.errorMessage && } {error?.errorMessage ? (
{error?.errorMessage}
) : (

{t("quotes.pdf_generation.progress", { percentage })}

{t("quotes.pdf_generation.elapsed", { elapsed })}

{estimatedTime > 0 &&

{t("quotes.pdf_generation.remaining", { estimatedTime })}

}
)} ); };