import { useState, createContext, useContext, useCallback, ReactNode } from "react"; import { X, ExternalLink } from "lucide-react"; import { useUITranslation } from '../../../i18n/index.js'; interface ImageLightboxContextValue { openImage: (src: string, alt?: string) => void; closeImage: () => void; } const ImageLightboxContext = createContext(null); export function useImageLightbox() { const ctx = useContext(ImageLightboxContext); if (!ctx) { // Return a fallback that opens in new tab if no provider return { openImage: (src: string) => window.open(src, "_blank"), closeImage: () => {}, }; } return ctx; } interface ImageLightboxProviderProps { children: ReactNode; } export function ImageLightboxProvider({ children }: ImageLightboxProviderProps) { const [image, setImage] = useState<{ src: string; alt?: string } | null>(null); const openImage = useCallback((src: string, alt?: string) => { setImage({ src, alt }); }, []); const closeImage = useCallback(() => { setImage(null); }, []); const { t } = useUITranslation(); return ( {children} {image && (
{image.alt {/* Close button */} {/* Open in new tab button */} e.stopPropagation()} title={t('agent.openInNewTab')} >
)}
); } // Clickable image component that opens in lightbox interface LightboxImageProps { src: string; alt?: string; className?: string; } export function LightboxImage({ src, alt, className }: LightboxImageProps) { const { openImage } = useImageLightbox(); return ( {alt} { e.stopPropagation(); openImage(src, alt); }} /> ); }