import { Loader2 } from "lucide-react"; import { useState } from "react"; import { formatHeaders } from "@/lib/api"; import { useFileStore } from "@/stores/file-store"; interface ImageInfoData { filename: string; fileSize: number; width: number; height: number; format: string; channels: number; hasAlpha: boolean; colorSpace: string; density: number | null; isProgressive: boolean; orientation: number | null; hasProfile: boolean; hasExif: boolean; hasIcc: boolean; hasXmp: boolean; bitDepth: string | null; pages: number; histogram: Array<{ channel: string; min: number; max: number; mean: number; stdev: number; }>; } export function InfoSettings() { const { files, processing, error, setProcessing, setError } = useFileStore(); const [info, setInfo] = useState(null); const handleProcess = async () => { if (files.length === 0) return; setProcessing(true); setError(null); setInfo(null); try { const formData = new FormData(); formData.append("file", files[0]); const res = await fetch("/api/v1/tools/info", { method: "POST", headers: formatHeaders(), body: formData, }); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `Failed: ${res.status}`); } const data: ImageInfoData = await res.json(); setInfo(data); } catch (err) { setError(err instanceof Error ? err.message : "Failed to read info"); } finally { setProcessing(false); } }; const hasFile = files.length > 0; const channelColors: Record = { red: "bg-red-500", green: "bg-green-500", blue: "bg-blue-500", alpha: "bg-gray-500", }; return (
{error &&

{error}

} {info && (
Dimensions
{info.width} x {info.height}
Format
{info.format}
File Size
{(info.fileSize / 1024).toFixed(1)} KB
Channels
{info.channels}
Color Space
{info.colorSpace}
Alpha
{info.hasAlpha ? "Yes" : "No"}
DPI
{info.density ?? "N/A"}
Progressive
{info.isProgressive ? "Yes" : "No"}
ICC Profile
{info.hasIcc ? "Yes" : "No"}
EXIF Data
{info.hasExif ? "Yes" : "No"}
XMP Data
{info.hasXmp ? "Yes" : "No"}
Pages
{info.pages}
{/* Histogram */}

Channel Stats

{info.histogram.map((ch) => (
{ch.channel}
min:{ch.min} max:{ch.max} mean:{ch.mean}
))}
)}
); }