import { Download } from "lucide-react"; 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 interface TextOverlayControlsProps { settings?: Record; onChange?: (settings: Record) => void; } export function TextOverlayControls({ settings: initialSettings, onChange, }: TextOverlayControlsProps) { const { t } = useTranslation(); const ts = t.toolSettings["text-overlay"]; const [text, setText] = useState(ts.defaultText); const [fontSize, setFontSize] = useState(48); const [color, setColor] = useState("#FFFFFF"); const [position, setPosition] = useState<"top" | "center" | "bottom">("bottom"); const [backgroundBox, setBackgroundBox] = useState(false); const [backgroundColor, setBackgroundColor] = useState("#000000"); const [shadow, setShadow] = useState(true); const initializedRef = useRef(false); useEffect(() => { if (!initialSettings || initializedRef.current) return; initializedRef.current = true; if (initialSettings.text != null) setText(String(initialSettings.text)); if (initialSettings.fontSize != null) setFontSize(Number(initialSettings.fontSize)); if (initialSettings.color != null) setColor(String(initialSettings.color)); if (initialSettings.position != null) setPosition(initialSettings.position as "top" | "center" | "bottom"); if (initialSettings.backgroundBox != null) setBackgroundBox(Boolean(initialSettings.backgroundBox)); if (initialSettings.backgroundColor != null) setBackgroundColor(String(initialSettings.backgroundColor)); if (initialSettings.shadow != null) setShadow(Boolean(initialSettings.shadow)); }, [initialSettings]); const onChangeRef = useRef(onChange); useEffect(() => { onChangeRef.current = onChange; }); useEffect(() => { onChangeRef.current?.({ text, fontSize, color, position, backgroundBox, backgroundColor, shadow, }); }, [text, fontSize, color, position, backgroundBox, backgroundColor, shadow]); return (
setText(e.target.value)} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{fontSize}px
setFontSize(Number(e.target.value))} className="w-full mt-1" />
setColor(e.target.value)} className="w-full mt-0.5 h-8 rounded border border-border" />
{backgroundBox && (
setBackgroundColor(e.target.value)} className="w-full mt-0.5 h-8 rounded border border-border" />
)}
); } export function TextOverlaySettings() { const { t } = useTranslation(); const ts = t.toolSettings["text-overlay"]; const { files } = useFileStore(); const { processFiles, processAllFiles, processing, error, downloadUrl, originalSize, processedSize, progress, } = useToolProcessor("text-overlay"); const [settings, setSettings] = useState>({}); const handleProcess = () => { if (files.length > 1) { processAllFiles(files, settings); } else { processFiles(files, settings); } }; const hasFile = files.length > 0; return (
{error &&

{error}

} {originalSize != null && processedSize != null && (

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

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

)} {processing ? ( ) : ( )} {downloadUrl && ( {ts.download} )}
); }