import { Download, Loader2 } from "lucide-react"; import { useState } from "react"; import { useFileStore } from "@/stores/file-store"; function getToken(): string { return localStorage.getItem("stirling-token") || ""; } export function VectorizeSettings() { const { files, processing, error, setProcessing, setError, setProcessedUrl, setSizes, setJobId } = useFileStore(); const [colorMode, setColorMode] = useState<"bw" | "color">("bw"); const [threshold, setThreshold] = useState(128); const [detail, setDetail] = useState<"low" | "medium" | "high">("medium"); const [downloadUrl, setDownloadUrl] = useState(null); const [originalSize, setOriginalSize] = useState(null); const [processedSize, setProcessedSize] = useState(null); const handleProcess = async () => { if (files.length === 0) return; setProcessing(true); setError(null); setDownloadUrl(null); try { const formData = new FormData(); formData.append("file", files[0]); formData.append("settings", JSON.stringify({ colorMode, threshold, detail })); const res = await fetch("/api/v1/tools/vectorize", { method: "POST", headers: { Authorization: `Bearer ${getToken()}` }, body: formData, }); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `Failed: ${res.status}`); } const result = await res.json(); setJobId(result.jobId); setProcessedUrl(result.downloadUrl); setDownloadUrl(result.downloadUrl); setOriginalSize(result.originalSize); setProcessedSize(result.processedSize); setSizes(result.originalSize, result.processedSize); } catch (err) { setError(err instanceof Error ? err.message : "Vectorization failed"); } finally { setProcessing(false); } }; const hasFile = files.length > 0; return (

Color Mode

{threshold}
setThreshold(Number(e.target.value))} className="w-full mt-1" />
{error &&

{error}

} {originalSize != null && processedSize != null && (

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

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

)} {downloadUrl && ( Download SVG )}
); }