"use client"; import { FaDownload, FaTimes } from "react-icons/fa"; import { LuCheckCheck, LuCog, LuRefreshCw } from "react-icons/lu"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import type { AppUpdateInfo, AppUpdateProgress } from "@/types"; interface AppUpdateToastProps { updateInfo: AppUpdateInfo; onUpdate: (updateInfo: AppUpdateInfo) => Promise; onDismiss: () => void; isUpdating?: boolean; updateProgress?: AppUpdateProgress | null; } function getStageIcon(stage?: string, isUpdating?: boolean) { if (!isUpdating) { return ; } switch (stage) { case "downloading": return ; case "extracting": return ( ); case "installing": return ( ); case "completed": return ; default: return ( ); } } function getStageDisplayName(stage?: string) { switch (stage) { case "downloading": return "Downloading"; case "extracting": return "Extracting"; case "installing": return "Installing"; case "completed": return "Completed"; default: return "Updating"; } } export function AppUpdateToast({ updateInfo, onUpdate, onDismiss, isUpdating = false, updateProgress, }: AppUpdateToastProps) { const handleUpdateClick = async () => { await onUpdate(updateInfo); }; const showProgress = isUpdating && updateProgress?.stage === "downloading" && updateProgress.percentage !== undefined; return (
{getStageIcon(updateProgress?.stage, isUpdating)}
{isUpdating ? `${getStageDisplayName(updateProgress?.stage)} Donut Browser Update` : "Donut Browser Update Available"} {updateInfo.is_nightly ? "Nightly" : "Stable"}
{isUpdating ? ( updateProgress?.message || "Updating..." ) : ( <> Update from {updateInfo.current_version} to{" "} {updateInfo.new_version} )}
{!isUpdating && ( )}
{/* Download progress */} {showProgress && updateProgress && (

{updateProgress.percentage?.toFixed(1)}% {updateProgress.speed && ` • ${updateProgress.speed} MB/s`} {updateProgress.eta && ` • ${updateProgress.eta} remaining`}

)} {/* Other stage progress (without percentage) */} {isUpdating && updateProgress && updateProgress.stage !== "downloading" && (

{updateProgress.message}

{updateProgress.stage === "extracting" && (

Preparing update files...

)} {updateProgress.stage === "installing" && (

Installing new version...

)} {updateProgress.stage === "completed" && (

Update completed! Restarting application...

)}
)} {!isUpdating && (
)}
); }