import { Download } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { ProgressCard } from "@/components/common/progress-card"; import { useToolProcessor } from "@/hooks/use-tool-processor"; import { useFileStore } from "@/stores/file-store"; const ASPECT_PRESETS = [ { label: "1:1 Square", w: 1080, h: 1080 }, { label: "16:9 Landscape", w: 1920, h: 1080 }, { label: "9:16 Portrait", w: 1080, h: 1920 }, { label: "4:3 Standard", w: 1440, h: 1080 }, { label: "3:2 Photo", w: 1620, h: 1080 }, { label: "Custom", w: 0, h: 0 }, ]; export interface SmartCropControlsProps { onChange?: (settings: Record) => void; } export function SmartCropControls({ onChange }: SmartCropControlsProps) { const [width, setWidth] = useState("1080"); const [height, setHeight] = useState("1080"); const [preset, setPreset] = useState("1:1 Square"); const onChangeRef = useRef(onChange); useEffect(() => { onChangeRef.current = onChange; }); useEffect(() => { onChangeRef.current?.({ width: Number(width), height: Number(height) }); }, [width, height]); const handlePreset = (label: string) => { setPreset(label); const p = ASPECT_PRESETS.find((a) => a.label === label); if (p && p.w > 0) { setWidth(String(p.w)); setHeight(String(p.h)); } }; return (
{/* Aspect ratio preset */}
{/* Width / Height */}
{ setWidth(e.target.value); setPreset("Custom"); }} 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); setPreset("Custom"); }} min={1} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{/* Info */}

Uses entropy-based attention detection to find the most interesting region of the image and crops to it.

); } export function SmartCropSettings() { const { files } = useFileStore(); const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } = useToolProcessor("smart-crop"); const [settings, setSettings] = useState>({}); const handleProcess = () => { const w = Number(settings.width); const h = Number(settings.height); if (w > 0 && h > 0) { processFiles(files, { width: w, height: h }); } }; const hasFile = files.length > 0; const canProcess = Number(settings.width) > 0 && Number(settings.height) > 0; return (
{/* Error */} {error &&

{error}

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

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

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

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