import React, { useState, useMemo } from 'react' import { Box, Button, HStack, Text, VStack, } from '@chakra-ui/react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' interface LearningMaterialViewerProps { content: string linesPerPage?: number } export const LearningMaterialViewer = ({ content, linesPerPage = 30 }: LearningMaterialViewerProps) => { const [currentPage, setCurrentPage] = useState(0) // Разделяем контент на страницы по linesPerPage строк const pages = useMemo(() => { const lines = content.split('\n') const pagesArray: string[] = [] for (let i = 0; i < lines.length; i += linesPerPage) { const pageLines = lines.slice(i, i + linesPerPage) pagesArray.push(pageLines.join('\n')) } return pagesArray }, [content, linesPerPage]) const totalPages = pages.length if (totalPages === 0) { return null } const goToPrevious = () => { setCurrentPage(prev => Math.max(0, prev - 1)) } const goToNext = () => { setCurrentPage(prev => Math.min(totalPages - 1, prev + 1)) } return ( Дополнительные материалы {totalPages > 1 && ( Страница {currentPage + 1} из {totalPages} )} p': { marginTop: '0.25em', marginBottom: '0.25em' }, // Инлайн-код '& code': { backgroundColor: '#EDF2F7', color: '#C53030', padding: '0.15em 0.4em', borderRadius: '4px', fontSize: '0.9em', fontFamily: 'Monaco, Consolas, "Courier New", monospace', fontWeight: '500' }, // Блоки кода '& pre': { backgroundColor: '#1A202C', color: '#E2E8F0', padding: '1em 1.2em', borderRadius: '8px', overflowX: 'auto', marginTop: '1em', marginBottom: '1em', border: '1px solid #2D3748', fontSize: '0.9em', lineHeight: '1.6' }, '& pre code': { backgroundColor: 'transparent', color: '#E2E8F0', padding: '0', fontFamily: 'Monaco, Consolas, "Courier New", monospace' }, // Цитаты '& blockquote': { borderLeft: '4px solid #4299E1', paddingLeft: '1em', paddingTop: '0.5em', paddingBottom: '0.5em', marginLeft: '0', marginTop: '1em', marginBottom: '1em', fontStyle: 'italic', color: '#4A5568', backgroundColor: '#EBF8FF', borderRadius: '0 4px 4px 0' }, '& blockquote p': { marginTop: '0.25em', marginBottom: '0.25em' }, // Ссылки '& a': { color: '#3182CE', textDecoration: 'underline', fontWeight: '500', transition: 'color 0.2s', '&:hover': { color: '#2C5282' } }, // Горизонтальная линия '& hr': { border: 'none', borderTop: '2px solid #E2E8F0', marginTop: '1.5em', marginBottom: '1.5em' }, // Таблицы '& table': { borderCollapse: 'collapse', width: '100%', marginTop: '1em', marginBottom: '1em', fontSize: '0.95em' }, '& table thead': { backgroundColor: '#F7FAFC' }, '& table th': { border: '1px solid #E2E8F0', padding: '0.75em 1em', textAlign: 'left', fontWeight: '600', color: '#2D3748' }, '& table td': { border: '1px solid #E2E8F0', padding: '0.75em 1em', textAlign: 'left' }, '& table tr:nth-of-type(even)': { backgroundColor: '#F7FAFC' }, // Выделение (strong, em) '& strong': { fontWeight: '600', color: '#2D3748' }, '& em': { fontStyle: 'italic' }, // Изображения '& img': { maxWidth: '100%', height: 'auto', borderRadius: '8px', marginTop: '1em', marginBottom: '1em' } }} > {pages[currentPage]} {totalPages > 1 && ( )} ) }