import { useState, useCallback, type CSSProperties, type ImgHTMLAttributes } from "react"; const FALLBACK_SRC = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Crect fill='%23222' width='80' height='80' rx='8'/%3E%3Cpath d='M28 52l8-12 6 8 12-16 10 20H28z' fill='%23444'/%3E%3Ccircle cx='32' cy='32' r='5' fill='%23444'/%3E%3C/svg%3E"; const baseStyle: CSSProperties = { transition: "opacity 0.3s ease", }; interface OptimizedImageProps extends ImgHTMLAttributes { fallbackSrc?: string; } export default function OptimizedImage({ src, alt = "", fallbackSrc = FALLBACK_SRC, style, onLoad, onError, ...rest }: OptimizedImageProps) { const [loaded, setLoaded] = useState(false); const [errored, setErrored] = useState(false); const handleLoad = useCallback( (e: React.SyntheticEvent) => { setLoaded(true); onLoad?.(e); }, [onLoad], ); const handleError = useCallback( (e: React.SyntheticEvent) => { if (!errored) { setErrored(true); (e.target as HTMLImageElement).src = fallbackSrc; } onError?.(e); }, [errored, fallbackSrc, onError], ); return ( {alt} ); }