import { Download, ImageIcon, Upload } from "lucide-react"; import { type ReactNode, useRef, useState } from "react"; import { ProgressCard } from "@/components/common/progress-card"; import { useTranslation } from "@/contexts/i18n-context"; import { useToolProcessor } from "@/hooks/use-tool-processor"; import { format } from "@/lib/format"; import { useFileStore } from "@/stores/file-store"; type Quality = "fast" | "balanced" | "best"; type OutputFormat = "webp" | "apng" | "gif"; type BackgroundType = "transparent" | "color" | "gradient" | "blur" | "image"; // Animation multiplies per-frame cost, so default to the fast model. const QUALITY_MODEL: Record = { fast: "u2net", balanced: "birefnet-general-lite", best: "birefnet-general", }; function SectionLabel({ children }: { children: ReactNode }) { return

{children}

; } function OptionRow({ options, value, onChange, }: { options: { value: T; label: string }[]; value: T; onChange: (v: T) => void; }) { return (
{options.map((o) => ( ))}
); } export function RemoveGifBackgroundSettings() { const { t } = useTranslation(); const s = t.toolSettings["remove-gif-background"]; const { files } = useFileStore(); const { processFiles, processAllFiles, processing, error, downloadUrl, progress } = useToolProcessor("remove-gif-background"); const [quality, setQuality] = useState("fast"); const [outputFormat, setOutputFormat] = useState("webp"); const [backgroundType, setBackgroundType] = useState("transparent"); const [backgroundColor, setBackgroundColor] = useState("#ffffff"); const [gradientColor1, setGradientColor1] = useState("#4f46e5"); const [gradientColor2, setGradientColor2] = useState("#ec4899"); const [gradientAngle, setGradientAngle] = useState(90); const [blurIntensity, setBlurIntensity] = useState(30); const [shadowEnabled, setShadowEnabled] = useState(false); const [shadowOpacity, setShadowOpacity] = useState(50); const [edgeRefine, setEdgeRefine] = useState(0); const [decontaminate, setDecontaminate] = useState(false); const [bgFile, setBgFile] = useState(null); const bgInputRef = useRef(null); const hasFile = files.length > 0; const needsBgImage = backgroundType === "image" && !bgFile; const handleProcess = () => { const settings: Record = { model: QUALITY_MODEL[quality], outputFormat, backgroundType, edgeRefine, decontaminate, }; if (backgroundType === "color") settings.backgroundColor = backgroundColor; if (backgroundType === "gradient") { settings.gradientColor1 = gradientColor1; settings.gradientColor2 = gradientColor2; settings.gradientAngle = gradientAngle; } if (backgroundType === "blur") settings.blurIntensity = blurIntensity; if (backgroundType === "image" && bgFile) settings._bgImageFile = bgFile; if (shadowEnabled) { settings.shadowEnabled = true; settings.shadowOpacity = shadowOpacity; } if (files.length > 1) processAllFiles(files, settings); else processFiles(files, settings); }; return (
{s.quality} value={quality} onChange={setQuality} options={[ { value: "fast", label: s.qualityFast }, { value: "balanced", label: s.qualityBalanced }, { value: "best", label: s.qualityBest }, ]} />

{s.qualityNote}

{s.outputFormat} value={outputFormat} onChange={setOutputFormat} options={[ { value: "webp", label: s.formatWebp }, { value: "apng", label: s.formatApng }, { value: "gif", label: s.formatGif }, ]} />

{outputFormat === "gif" ? s.gifCaveat : s.formatWebpHint}

{s.background} value={backgroundType} onChange={setBackgroundType} options={[ { value: "transparent", label: s.bgTransparent }, { value: "color", label: s.bgColor }, { value: "gradient", label: s.bgGradient }, { value: "blur", label: s.bgBlur }, { value: "image", label: s.bgImage }, ]} /> {backgroundType === "color" && ( )} {backgroundType === "gradient" && (
)} {backgroundType === "blur" && ( )} {backgroundType === "image" && (
setBgFile(e.target.files?.[0] ?? null)} />
)}
{shadowEnabled && ( )}
{s.advanced}

{s.frameNote}

{error &&

{error}

} {processing ? ( ) : ( )} {downloadUrl && !processing && files.length <= 1 && ( {s.download} )}
); }