import { Image as ImageIcon, Trash2 } from 'lucide-react'; import TextInputArea from '@/components/TextInputArea'; import { useLazyTranslation } from '@/utils/useLazyTranslation'; import CopyButton from '@/components/CopyButton'; import DecodeResultPaper from '@/components/DecodeResultPaper'; import { Button } from '@/components/ui/button'; import { downloadBlob, formatFileSize } from '@/utils/base64Converter'; import { useStorageState } from '@/utils/useStorageState'; import type { Base64ConvertDirection } from '@/types/storage'; import SwitchButtonGroup from '@/components/SwitchButtonGroup'; import { useBase64Converter } from './useBase64Converter'; // 💡 引入共享核心 import { cn } from '@/lib/utils'; const isValidDirection = (val: unknown): val is Base64ConvertDirection => val === 'encode' || val === 'decode'; export default function ImageMode() { const { t } = useLazyTranslation('base64Converter'); const [direction, setDirection] = useStorageState( 'base64Converter/imageMode/direction', 'encode', isValidDirection, ); // 消费完全托管的核心 Hook,消灭本地多余状态机 const { result, info, isLoading, isDragging, setIsDragging, fileInputRef, encodeError, decodeInput, setDecodeInput, decoded, decodeError, decodedFileName, setCustomFileName, resetAll, safeFileSelect, } = useBase64Converter({ mode: 'image' }); const handleDirectionChange = (next: Base64ConvertDirection) => { if (!next || next === direction) return; resetAll(); setDirection(next); }; const handleDownload = () => { if (decoded) downloadBlob(decoded.blob, decodedFileName); }; return (