import React, { useEffect, useRef, useState } from 'react';
import { Transformer } from 'markmap-lib';
import { Markmap } from 'markmap-view';
import { Spin, Empty, Button, Space } from 'antd';
import { FullscreenOutlined, ZoomInOutlined, ZoomOutOutlined, SyncOutlined } from '@ant-design/icons';
const transformer = new Transformer();
const MindMap = ({ content, title }) => {
const svgRef = useRef(null);
const markmapRef = useRef(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!content || !svgRef.current) return;
setLoading(true);
try {
const { root } = transformer.transform(content);
if (markmapRef.current) {
markmapRef.current.setData(root);
markmapRef.current.fit();
} else {
markmapRef.current = Markmap.create(svgRef.current, {
autoFit: true,
duration: 500,
}, root);
}
} catch (error) {
console.error('Markmap error:', error);
} finally {
setLoading(false);
}
}, [content]);
const handleFit = () => markmapRef.current?.fit();
const handleZoomIn = () => markmapRef.current?.rescale(1.2);
const handleZoomOut = () => markmapRef.current?.rescale(0.8);
if (!content) return