import {ReactPortal, useEffect, useState} from 'react'; import {createPortal} from 'react-dom'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faPaperPlane, faStop, faSync, faX} from '@fortawesome/free-solid-svg-icons'; import {useTranslations} from "next-intl"; interface QSTextGeneratedPreviewProps { onClose: () => void; onRefresh: () => void; value: string; onInsert: () => void; isGenerating?: boolean; onStop?: () => void; } export default function QSTextGeneratedPreview( { onClose, onRefresh, value, onInsert, isGenerating = false, onStop, }: QSTextGeneratedPreviewProps): ReactPortal | null { const [mounted, setMounted] = useState(false); const [isVisible, setIsVisible] = useState(false); const t = useTranslations(); useEffect((): () => void => { setMounted(true); const timer = setTimeout(() => setIsVisible(true), 10); return (): void => { setMounted(false); setIsVisible(false); clearTimeout(timer); }; }, []); const handleClose = (): void => { setIsVisible(false); setTimeout(onClose, 300); // Attend la fin de l'animation avant de fermer }; if (!mounted) return null; const modalContent = (

{t("qsTextPreview.title")}

{isGenerating && onStop ? ( ) : ( )}
{isGenerating && !value ? (
) : (
{value}
)}
); return createPortal(modalContent, document.body); }