/* eslint-disable @next/next/no-img-element */ import { BookCopy, PlusIcon } from 'lucide-react'; import { useState } from 'react'; import { Message } from './ChatWindow'; import Lightbox, { GenericSlide } from 'yet-another-react-lightbox'; import 'yet-another-react-lightbox/styles.css'; type Document = { url: string; title: string; snippet: string; source: string; type: string; iframe_src: string; }; declare module 'yet-another-react-lightbox' { export interface PDFSlide extends GenericSlide { type: 'pdf'; url: string; iframe_src: string; } interface SlideTypes { 'pdf': PDFSlide; } } const LegalSearch = ({ query, chatHistory, }: { query: string; chatHistory: Message[]; }) => { const [documents, setDocuments] = useState(null); const [loading, setLoading] = useState(false); const [open, setOpen] = useState(false); const [currentDoc, setCurrentDoc] = useState(null); const openDocument = (doc: Document) => { setCurrentDoc(doc); setOpen(true); }; return ( <> {!loading && documents === null && ( )} {loading && (
{[...Array(3)].map((_, i) => (
))}
)} {documents !== null && documents.length > 0 && ( <>
{documents.length > 4 ? documents.slice(0, 3).map((doc, i) => (
openDocument(doc)} className="bg-light-100 dark:bg-dark-100 p-3 rounded-lg hover:bg-light-200 dark:hover:bg-dark-200 transition duration-200 cursor-pointer" >

{doc.title}

{doc.snippet}

{doc.source} {doc.type}
)) : documents.map((doc, i) => (
openDocument(doc)} className="bg-light-100 dark:bg-dark-100 p-3 rounded-lg hover:bg-light-200 dark:hover:bg-dark-200 transition duration-200 cursor-pointer" >

{doc.title}

{doc.snippet}

{doc.source} {doc.type}
))} {documents.length > 4 && ( )}
setOpen(false)} render={{ slide: ({ slide }) => slide.type === 'pdf' ? (

Le document ne peut pas être affiché directement.

Ouvrir le document dans un nouvel onglet

{currentDoc?.title}

{currentDoc?.snippet}

) : null, }} slides={[ { type: 'pdf', url: currentDoc?.url || '', iframe_src: currentDoc?.url || '', } ]} /> )} ); }; export default LegalSearch;