import { Download, Loader2, X } from "lucide-react"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { useScopedT } from "@/contexts/I18nContext"; import type { ExportProgress } from "@/lib/exporter"; interface ExportDialogProps { isOpen: boolean; onClose: () => void; progress: ExportProgress | null; isExporting: boolean; error: string | null; onCancel?: () => void; exportFormat?: "mp4" | "gif"; exportedFilePath?: string; onShowInFolder?: () => void; } export function ExportDialog({ isOpen, onClose, progress, isExporting, error, onCancel, exportFormat = "mp4", exportedFilePath, onShowInFolder, }: ExportDialogProps) { const t = useScopedT("dialogs"); const [showSuccess, setShowSuccess] = useState(false); // Reset showSuccess when a new export starts or dialog reopens useEffect(() => { if (isExporting) { setShowSuccess(false); } }, [isExporting]); // Reset showSuccess when dialog opens fresh useEffect(() => { if (isOpen && !isExporting && !progress) { setShowSuccess(false); } }, [isOpen, isExporting, progress]); useEffect(() => { if (!isExporting && progress && progress.percentage >= 100 && !error) { setShowSuccess(true); const timer = setTimeout(() => { setShowSuccess(false); onClose(); }, 2000); return () => clearTimeout(timer); } }, [isExporting, progress, error, onClose]); if (!isOpen) return null; const formatLabel = exportFormat === "gif" ? "GIF" : "Video"; // Determine if we're in the compiling phase (frames done but still exporting) const isCompiling = isExporting && progress && progress.percentage >= 100 && exportFormat === "gif"; const isFinalizing = progress?.phase === "finalizing"; const renderProgress = progress?.renderProgress; // Get status message based on phase const getStatusMessage = () => { if (error) return t("export.tryAgain"); if (isCompiling || isFinalizing) { if (exportFormat === "mp4") { return t("export.finalizingVideo"); } if (renderProgress !== undefined && renderProgress > 0) { return t("export.compilingGifProgress", { progress: String(renderProgress) }); } return t("export.compilingGifWait"); } return t("export.takeMoment"); }; // Get title based on phase const getTitle = () => { if (error) return t("export.failed"); if (isFinalizing && exportFormat === "mp4") return t("export.finalizingVideoTitle"); if (isCompiling || isFinalizing) return t("export.compilingGif"); return t("export.exportingFormat", { format: formatLabel }); }; return ( <>
{error}
{t("export.savedSuccessfully", { format: formatLabel })}