import { useEffect, useRef, useState } from "react"; import { ProgressCard } from "@/components/common/progress-card"; import { useTranslation } from "@/contexts/i18n-context"; import { useToolProcessor } from "@/hooks/use-tool-processor"; import { format } from "@/lib/format"; import { useFileStore } from "@/stores/file-store"; export function CropVideoSettings() { const { t } = useTranslation(); const s = t.toolSettings["crop-video"]; const { files } = useFileStore(); const { processFiles, processAllFiles, processing, error, progress } = useToolProcessor("crop-video"); const [width, setWidth] = useState(""); const [height, setHeight] = useState(""); const [x, setX] = useState(0); const [y, setY] = useState(0); const hasFile = files.length > 0; const hasMultiple = files.length > 1; const dimsValid = width !== "" && height !== ""; const handleProcess = () => { const settings = { width, height, x, y }; if (hasMultiple) { processAllFiles(files, settings); } else { processFiles(files, settings); } }; return (
setWidth(e.target.value === "" ? "" : Number(e.target.value))} 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 === "" ? "" : Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setX(Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setY(Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{error &&

{error}

} {processing ? ( ) : ( )}
); } export interface CropVideoControlsProps { settings?: Record; onChange?: (settings: Record) => void; } export function CropVideoControls({ settings: initial, onChange }: CropVideoControlsProps) { const { t } = useTranslation(); const s = t.toolSettings["crop-video"]; const [width, setWidth] = useState(0); const [height, setHeight] = useState(0); const [x, setX] = useState(0); const [y, setY] = useState(0); const initializedRef = useRef(false); useEffect(() => { if (!initial || initializedRef.current) return; initializedRef.current = true; if (initial.width != null) setWidth(Number(initial.width)); if (initial.height != null) setHeight(Number(initial.height)); if (initial.x != null) setX(Number(initial.x)); if (initial.y != null) setY(Number(initial.y)); }, [initial]); const onChangeRef = useRef(onChange); useEffect(() => { onChangeRef.current = onChange; }); useEffect(() => { onChangeRef.current?.({ width, height, x, y }); }, [width, height, x, y]); return (
setWidth(Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setHeight(Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setX(Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
setY(Number(e.target.value))} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
); }