import { useState } from "react"; import { useFileStore } from "@/stores/file-store"; import { useToolProcessor } from "@/hooks/use-tool-processor"; import { Download } from "lucide-react"; import { ProgressCard } from "@/components/common/progress-card"; const ASPECT_PRESETS = [ { label: "1:1", w: 1, h: 1 }, { label: "4:3", w: 4, h: 3 }, { label: "16:9", w: 16, h: 9 }, { label: "2:3", w: 2, h: 3 }, { label: "4:5", w: 4, h: 5 }, ]; export function CropSettings() { const { files } = useFileStore(); const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } = useToolProcessor("crop"); const [left, setLeft] = useState("0"); const [top, setTop] = useState("0"); const [width, setWidth] = useState(""); const [height, setHeight] = useState(""); const applyAspect = (w: number, h: number) => { // If width is set, calculate height from aspect ratio const currentW = Number(width); if (currentW > 0) { setHeight(String(Math.round((currentW * h) / w))); } }; const handleProcess = () => { processFiles(files, { left: Number(left), top: Number(top), width: Number(width), height: Number(height), }); }; const hasFile = files.length > 0; const hasSize = Number(width) > 0 && Number(height) > 0; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (hasFile && hasSize && !processing) handleProcess(); }; return (
{/* Position */}
setLeft(e.target.value)} min={0} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setTop(e.target.value)} min={0} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{/* Size */}
setWidth(e.target.value)} min={1} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setHeight(e.target.value)} min={1} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{/* Aspect ratio presets */}
{ASPECT_PRESETS.map(({ label, w, h }) => ( ))}
{/* Error */} {error &&

{error}

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

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

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

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