import React, { useState, useEffect } from "react"; import PropTypes from "prop-types"; import Box from "@mui/material/Box"; import Typography from "@mui/material/Typography"; import Paper from "@mui/material/Paper"; import List from "@mui/material/List"; import ListItem from "@mui/material/ListItem"; import ListItemText from "@mui/material/ListItemText"; import ListItemIcon from "@mui/material/ListItemIcon"; import DescriptionIcon from '@mui/icons-material/Description'; import TextField from "@mui/material/TextField"; export const topicsSizeFraction = (topicsCentroids, topicSize) => { const totalSize = topicsCentroids.reduce((sum, topic) => sum + topic.size, 0); return Math.round((topicSize / totalSize) * 100); } function TextContainer({ topicName, topicSizeFraction, content }) { const [selectedDocument, setSelectedDocument] = useState(null); const [searchQuery, setSearchQuery] = useState(""); const [filteredContent, setFilteredContent] = useState([]); useEffect(() => { // Update the filtered content based on the search query if (searchQuery.trim() === "") { setFilteredContent(content); } else { const filtered = content.filter((doc) => doc.toLowerCase().includes(searchQuery.toLowerCase()) ); setFilteredContent(filtered); } // Automatically select the first document when search results change setSelectedDocument(0); }, [searchQuery, content]); const handleDocumentClick = (docIndex) => { setSelectedDocument(docIndex); }; return (