"use client"; import { Check, CircleAlert, RotateCcw } from "lucide-react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import type { CSSProperties, ReactNode } from "react"; import { useEffect, useRef } from "react"; import { IconSwap } from "@/components/agents/icon-swap"; import { EASE_IN_OUT, EASE_OUT, SPRING_PRESS } from "@/lib/ease"; import { useHoverCapable } from "@/lib/hooks/use-hover-capable"; import { useMessages } from "@/lib/i18n"; import { cn } from "@/lib/utils"; export type ImageGenerationStatus = | "queued" | "generating" | "refining" | "complete" | "error"; export interface ImageGenerationProps { /** The completed media. Pass an img, Next Image, canvas, video, or custom preview. */ children?: ReactNode; /** Generation stage. Sets the dither overlay, media blur and status line. Default: "generating" */ status?: ImageGenerationStatus; /** Accessible description. Defaults to a description derived from prompt. */ label?: string; /** The prompt, shown in quotes under the status line. */ prompt?: string; /** Badge in the top right corner. Default: "1024 × 1024" */ resolution?: string; /** CSS aspect ratio reserved before generated media is available. */ aspectRatio?: CSSProperties["aspectRatio"]; /** "compact" caps the width at 208px, "fluid" fills the container. Default: "compact" */ size?: "compact" | "fluid"; /** Lets the active dither cluster follow fine-pointer movement. */ interactive?: boolean; /** Replaces the built-in status line text for the current status. */ statusText?: string; /** Shows the status line under the media. Default: true */ showStatus?: boolean; /** Called from the retry button, which shows only when status is "error". */ onRetry?: () => void; /** Override any built-in string. `{status}` and `{prompt}` fill `labelWithPrompt`; `{prompt}` fills `quotedPrompt`. */ labels?: Partial; /** Classes merged onto the root element. */ className?: string; /** Classes merged onto the layer that holds the media. */ mediaClassName?: string; /** Classes merged onto the status line. */ statusClassName?: string; } /** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */ export const imageGenerationMessages = { queued: "Waiting to generate", generating: "Generating image", refining: "Refining details", complete: "Image ready", error: "Generation failed", labelWithPrompt: "{status}: {prompt}", quotedPrompt: "“{prompt}”", retry: "Try again", }; export type ImageGenerationMessages = typeof imageGenerationMessages; const MEDIA_STATE: Record< ImageGenerationStatus, { filter: string; opacity: number; scale: number } > = { queued: { filter: "blur(4px) saturate(0.75)", opacity: 0, scale: 1.02 }, generating: { filter: "blur(3px) saturate(0.85)", opacity: 0, scale: 1.015 }, refining: { filter: "blur(1.5px) saturate(0.95)", opacity: 0.62, scale: 1.005 }, complete: { filter: "blur(0px) saturate(1)", opacity: 1, scale: 1 }, error: { filter: "blur(2px) saturate(0.5)", opacity: 0.28, scale: 1 }, }; const OVERLAY_OPACITY: Record = { queued: 1, generating: 1, refining: 0.48, complete: 0, error: 0, }; const DOT_GAP = 10; const TWO_PI = Math.PI * 2; function DitherMark({ status, reduce, }: { status: ImageGenerationStatus; reduce: boolean; }) { if (status === "complete") { return