import { useState } from 'react'; import { AlertCircle, X } from 'lucide-react'; import { AttachmentPreviewItem } from './AttachmentPreviewItem'; import { ImageLightbox } from './ImageLightbox'; import type { AttachmentPayload } from '@shared/types'; interface AttachmentPreviewListProps { attachments: AttachmentPayload[]; onRemove: (id: string) => void; error?: string | null; onDismissError?: () => void; /** When true, previews are overlaid with a disabled indicator (recipient doesn't support attachments). */ disabled?: boolean; /** Hint text shown when disabled and attachments are present. */ disabledHint?: string; } export const AttachmentPreviewList = ({ attachments, onRemove, error, onDismissError, disabled, disabledHint, }: AttachmentPreviewListProps): React.JSX.Element | null => { const [lightboxIndex, setLightboxIndex] = useState(null); if (attachments.length === 0 && !error) return null; const lightboxSlides = attachments.map((att) => ({ src: `data:${att.mimeType};base64,${att.data}`, alt: att.filename, })); return (
{attachments.length > 0 ? (
{attachments.map((att, i) => ( setLightboxIndex(i)} disabled={disabled} /> ))}
) : null} {disabled && disabledHint && attachments.length > 0 ? (

{disabledHint}

) : null} {error ? (

{error}

{onDismissError ? ( ) : null}
) : null} {lightboxIndex !== null && lightboxSlides[lightboxIndex] ? ( setLightboxIndex(null)} slides={lightboxSlides} index={lightboxIndex} /> ) : null}
); };