import { Download, Loader2 } from "lucide-react"; import { useState } from "react"; function getToken(): string { return localStorage.getItem("stirling-token") || ""; } export function QrGenerateSettings() { const [text, setText] = useState(""); const [size, setSize] = useState(400); const [errorCorrection, setErrorCorrection] = useState<"L" | "M" | "Q" | "H">("M"); const [foreground, setForeground] = useState("#000000"); const [background, setBackground] = useState("#FFFFFF"); const [processing, setProcessing] = useState(false); const [error, setError] = useState(null); const [downloadUrl, setDownloadUrl] = useState(null); const [previewUrl, setPreviewUrl] = useState(null); const handleGenerate = async () => { if (!text) return; setProcessing(true); setError(null); setDownloadUrl(null); setPreviewUrl(null); try { const res = await fetch("/api/v1/tools/qr-generate", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${getToken()}`, }, body: JSON.stringify({ text, size, errorCorrection, foreground, background }), }); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `Generation failed: ${res.status}`); } const result = await res.json(); setDownloadUrl(result.downloadUrl); setPreviewUrl(result.downloadUrl); } catch (err) { setError(err instanceof Error ? err.message : "Generation failed"); } finally { setProcessing(false); } }; return (