import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { CopyOutlineMd } from '../../icons/CopyOutlineMd';
import { FullSizeOutlineMd } from '../../icons/FullSizeOutlineMd';
import { MinimizeOutlineMd } from '../../icons/MinimizeOutlineMd';
import { JsonNode } from './JsonNode';
import { Actions, Container, Content } from './styles';
import { useLogic } from './useLogic';
export const JsonViewer = (props) => {
    const { data, copyStatus, collapseAll, expandAll, copyAll, toggleExpanded, checkExpanded, } = useLogic(props);
    const renderRootNodes = () => {
        if (Array.isArray(data)) {
            return data.map((item, index) => (_jsx(JsonNode, { nodeKey: index, value: item, keyPath: String(index), level: 0, toggleExpanded: toggleExpanded, checkExpanded: checkExpanded }, String(index))));
        }
        if (typeof data === 'object' && data !== null) {
            return Object.entries(data).map(([key, value]) => (_jsx(JsonNode, { nodeKey: key, value: value, keyPath: key, level: 0, toggleExpanded: toggleExpanded, checkExpanded: checkExpanded }, key)));
        }
        return (_jsx(JsonNode, { nodeKey: "root", value: data, keyPath: "root", level: 0, toggleExpanded: toggleExpanded, checkExpanded: checkExpanded }));
    };
    return (_jsxs(Container, { children: [_jsx(Actions, { secondaryVisible: [
                    {
                        onClick: copyAll,
                        name: copyStatus,
                        icon: _jsx(CopyOutlineMd, {}),
                        variant: 'text',
                    },
                    {
                        onClick: expandAll,
                        name: 'Развернуть все',
                        icon: _jsx(FullSizeOutlineMd, {}),
                        variant: 'text',
                    },
                    {
                        onClick: collapseAll,
                        name: 'Свернуть все',
                        icon: _jsx(MinimizeOutlineMd, {}),
                        variant: 'text',
                    },
                ] }), _jsx(Content, { children: renderRootNodes() })] }));
};
