import { useEffect, useState } from "react"; import { LoaderCircle } from "lucide-react"; import { formatDuration } from "@/lib/image-utils"; import { cn } from "@/lib/utils"; type PendingImageProps = { className?: string; label?: string; compact?: boolean }; export function ImageGenerationPending({ className, label = "正在生成图片", compact = false }: PendingImageProps) { const [startedAt] = useState(() => Date.now()); const [elapsed, setElapsed] = useState(0); useEffect(() => { const update = () => setElapsed(Math.max(0, Date.now() - startedAt)); const clock = window.setInterval(update, 1000); const onVisible = () => { if (!document.hidden) update(); }; document.addEventListener("visibilitychange", onVisible); return () => { window.clearInterval(clock); document.removeEventListener("visibilitychange", onVisible); }; }, [startedAt]); return (
); }