Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | import { useState, useEffect } from 'react'
import { Brain, Copy, X } from 'lucide-react'
import toast from 'react-hot-toast'
function AssertionsViewerModal({ isOpen, onClose, content, title }) {
const [assertions, setAssertions] = useState([])
useEffect(() => {
if (!isOpen) return
const handleEscape = (e) => {
if (e.key === 'Escape') onClose()
}
window.addEventListener('keydown', handleEscape)
return () => window.removeEventListener('keydown', handleEscape)
}, [isOpen, onClose])
useEffect(() => {
if (!content || !isOpen) return
try {
const data = JSON.parse(content)
const assertionsList = data.assertions || data.facts || data.data || []
// En mode data, data.data peut être un objet (ex: { services: [...], title }).
// On l'affiche comme une entrée unique pour éviter un crash sur .map.
setAssertions(Array.isArray(assertionsList) ? assertionsList : [assertionsList])
} catch (e) {
console.error('Failed to parse assertions:', e)
setAssertions([])
}
}, [content, isOpen])
if (!isOpen || !content) return null
const copyAllAssertions = () => {
const text = assertions.map(f => typeof f === 'string' ? f : JSON.stringify(f)).join('\n')
navigator.clipboard.writeText(text)
toast.success('Assertions copiées !')
}
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
<div className="bg-white rounded-xl shadow-2xl max-w-3xl w-full max-h-[85vh] overflow-hidden flex flex-col">
{/* Header */}
<div className="flex items-center justify-between p-4 border-b">
<div className="flex items-center gap-3">
<Brain className="w-5 h-5 text-gray-600" />
<div>
<h3 className="text-lg font-semibold text-gray-900">{title || 'Assertions'}</h3>
<p className="text-sm text-gray-500">
{assertions.length} assertion{assertions.length !== 1 ? 's' : ''}
</p>
</div>
</div>
<div className="flex items-center gap-2">
<button
onClick={copyAllAssertions}
className="px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 rounded-lg transition-colors flex items-center gap-1"
>
<Copy className="w-4 h-4" />
Copier
</button>
<button
onClick={onClose}
className="p-2 hover:bg-gray-100 rounded-full transition-colors"
>
<X className="w-5 h-5 text-gray-500" />
</button>
</div>
</div>
{/* Assertions List */}
<div className="flex-1 overflow-auto p-6">
{assertions.length === 0 ? (
<div className="text-center text-gray-500 py-8">
Aucune assertion à afficher
</div>
) : (
<ul className="space-y-2">
{assertions.map((assertion, index) => {
const assertionText = typeof assertion === 'string' ? assertion : JSON.stringify(assertion)
return (
<li
key={index}
className="text-gray-700 py-2 border-b border-gray-100 last:border-0"
>
{assertionText}
</li>
)
})}
</ul>
)}
</div>
{/* Footer */}
<div className="p-3 bg-gray-50 border-t text-center text-sm text-gray-500">
Appuyez sur Echap pour fermer
</div>
</div>
</div>
)
}
export default AssertionsViewerModal |