import { Download, ImageIcon, Package, User } from "lucide-react"; import { useState } from "react"; import { ProgressCard } from "@/components/common/progress-card"; import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useFileStore } from "@/stores/file-store"; type SubjectType = "people" | "products" | "general"; type Quality = "fast" | "balanced" | "best"; type BgModel = | "birefnet-general" | "birefnet-general-lite" | "birefnet-portrait" | "bria-rmbg" | "u2net"; const MODEL_MAP: Record> = { people: { fast: "u2net", balanced: "birefnet-portrait", best: "birefnet-portrait" }, products: { fast: "u2net", balanced: "bria-rmbg", best: "birefnet-general" }, general: { fast: "u2net", balanced: "birefnet-general-lite", best: "birefnet-general" }, }; const SUBJECT_OPTIONS: { value: SubjectType; label: string; icon: typeof User }[] = [ { value: "people", label: "People", icon: User }, { value: "products", label: "Products", icon: Package }, { value: "general", label: "General", icon: ImageIcon }, ]; const QUALITY_OPTIONS: { value: Quality; label: string; hint: string }[] = [ { value: "fast", label: "Fast", hint: "~2s" }, { value: "balanced", label: "Balanced", hint: "~15s" }, { value: "best", label: "Best", hint: "~60s" }, ]; const BG_PRESETS = [ { color: "", label: "Transparent", preview: "checkerboard" }, { color: "#FFFFFF", label: "White", preview: "#FFFFFF" }, { color: "#000000", label: "Black", preview: "#000000" }, { color: "#FF0000", label: "Red", preview: "#FF0000" }, { color: "#00FF00", label: "Green", preview: "#00FF00" }, { color: "#0000FF", label: "Blue", preview: "#0000FF" }, ]; export function RemoveBgSettings() { const { files } = useFileStore(); const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } = useToolProcessor("remove-background"); const [subject, setSubject] = useState("people"); const [quality, setQuality] = useState("balanced"); const [isPassport, setIsPassport] = useState(false); const [bgColor, setBgColor] = useState(""); const model = isPassport ? "birefnet-portrait" : MODEL_MAP[subject][quality]; const handleProcess = () => { const settings: Record = { model }; if (bgColor) settings.backgroundColor = bgColor; processFiles(files, settings); }; const hasFile = files.length > 0; return (
{/* Subject type */}
{SUBJECT_OPTIONS.map((opt) => { const Icon = opt.icon; return ( ); })}
{/* Passport checkbox - only for people */} {subject === "people" && ( )} {/* Quality */}
{QUALITY_OPTIONS.map((opt) => ( ))}
{/* Background color - intuitive preset buttons */}
{BG_PRESETS.map((preset) => ( ))}
{/* Custom color picker */}
setBgColor(e.target.value)} className="w-8 h-8 rounded border border-border cursor-pointer" /> setBgColor(e.target.value)} placeholder="Custom hex (#FF5500)" className="flex-1 px-2 py-1.5 rounded border border-border bg-background text-xs text-foreground" />
{/* Error */} {error &&

{error}

} {/* Size info */} {originalSize != null && processedSize != null && !processing && (

Original: {(originalSize / 1024).toFixed(1)} KB

Processed: {(processedSize / 1024).toFixed(1)} KB

)} {/* Process button */} {processing ? ( ) : ( )} {/* Download */} {downloadUrl && !processing && ( Download )}
); }