import { useState, useRef, useEffect } from 'react'; import ImageCard from './ImageCard'; import BatchMenu from './BatchMenu'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip" import { Copy, Check } from 'lucide-react'; import { Button } from '../ui/button'; const formatTimestamp = (timestamp: string | undefined) => { if (!timestamp) return ''; const date = new Date(timestamp); if (isNaN(date.getTime())) return ''; const now = new Date(); const hours = date.getHours().toString().padStart(2, '0'); const minutes = date.getMinutes().toString().padStart(2, '0'); const day = date.getDate().toString().padStart(2, '0'); const month = (date.getMonth() + 1).toString().padStart(2, '0'); const year = date.getFullYear(); const timeString = `${hours}:${minutes}`; const dateString = date.getFullYear() === now.getFullYear() ? `${day}-${month}` : `${day}-${month}-${year}`; return `${timeString} ${dateString}`; }; interface Image { url: string; } interface Batch { id: number; prompt: string; width: number; height: number; model: string; images: Image[]; createdAt?: string; status?: string; } const modelNames: { [key: string]: string } = { 'runware:100@1': 'FLUX SCHNELL', 'runware:101@1': 'FLUX DEV' }; interface ImageBatchProps { batch: Batch; onDelete: (id: number) => void; onRemix: (batch: Batch) => void; } export default function ImageBatch({ batch, onDelete, onRemix }: ImageBatchProps) { const [copied, setCopied] = useState(false); const [isPromptTruncated, setIsPromptTruncated] = useState(false); const promptRef = useRef(null); const modelName = modelNames[batch.model] || batch.model; const [elapsedTime, setElapsedTime] = useState(0); useEffect(() => { const checkTruncation = () => { if (promptRef.current) { setIsPromptTruncated( promptRef.current.scrollWidth > promptRef.current.clientWidth ); } }; checkTruncation(); window.addEventListener('resize', checkTruncation); return () => { window.removeEventListener('resize', checkTruncation); }; }, [batch.prompt]); useEffect(() => { let interval: NodeJS.Timeout; if (batch.status === 'pending') { const startTime = new Date(batch.createdAt || Date.now()).getTime(); interval = setInterval(() => { const now = Date.now(); setElapsedTime((now - startTime) / 1000); }, 100); } return () => clearInterval(interval); }, [batch.status, batch.createdAt]); const handleDelete = () => { onDelete(batch.id); }; const handleRemix = () => { onRemix(batch); }; const copyToClipboard = () => { navigator.clipboard.writeText(batch.prompt).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }); }; return (

{batch.prompt}

{isPromptTruncated && (

{batch.prompt}

)}

{modelName} | {batch.width}x{batch.height}{formatTimestamp(batch.createdAt) && ` • ${formatTimestamp(batch.createdAt)}`}

{batch.images.map((image, index) => ( ))}
{batch.status === 'error' && (

Error generating images. Please try again.

)}
); }