'use client'; import Image from 'next/image'; import { useState } from 'react'; interface OptimizedImageProps { src: string; alt: string; width?: number; height?: number; className?: string; priority?: boolean; fill?: boolean; sizes?: string; quality?: number; style?: React.CSSProperties; objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down'; loading?: 'lazy' | 'eager'; } /** * OptimizedImage Component * * An enterprise-grade optimized image component that provides: * - Automatic lazy loading * - Responsive images with srcset * - WebP/AVIF format support * - Blur placeholder while loading * - Error handling with fallback * - Performance optimization * * @example * */ export default function OptimizedImage({ src, alt, width, height, className = '', priority = false, fill = false, sizes, quality = 85, style, objectFit = 'cover', loading, }: OptimizedImageProps) { const [imgSrc, setImgSrc] = useState(src); const [isLoading, setIsLoading] = useState(true); const [hasError, setHasError] = useState(false); // Fallback image for errors const fallbackImage = '/images/placeholder.png'; // Handle image load const handleLoad = () => { setIsLoading(false); }; // Handle image error const handleError = () => { setHasError(true); setIsLoading(false); if (imgSrc !== fallbackImage) { setImgSrc(fallbackImage); } }; // SEO-friendly alt text validation const seoAlt = alt || 'GNX Soft - Enterprise Software Solutions'; // Validate alt text for SEO if (process.env.NODE_ENV === 'development' && !alt) { console.warn( `OptimizedImage: Missing alt text for image "${src}". Alt text is crucial for SEO and accessibility.` ); } // Common image props const imageProps = { src: imgSrc, alt: seoAlt, className: `${className} ${isLoading ? 'image-loading' : 'image-loaded'}`, onLoad: handleLoad, onError: handleError, quality, loading: loading || (priority ? 'eager' : 'lazy'), style: { ...style, objectFit: objectFit as any, }, }; // Use fill layout for responsive images if (fill) { return (
); } // Standard layout with explicit dimensions return (
); } /** * Usage Examples: * * 1. Hero Image (Priority Loading): * * * 2. Service Card Image (Lazy Loading): * * * 3. Background Image (Fill): * * * 4. Logo (High Priority): * */