"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonViewer = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const CopyOutlineMd_1 = require("../../icons/CopyOutlineMd");
const FullSizeOutlineMd_1 = require("../../icons/FullSizeOutlineMd");
const MinimizeOutlineMd_1 = require("../../icons/MinimizeOutlineMd");
const JsonNode_1 = require("./JsonNode");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const JsonViewer = (props) => {
    const { data, copyStatus, collapseAll, expandAll, copyAll, toggleExpanded, checkExpanded, } = (0, useLogic_1.useLogic)(props);
    const renderRootNodes = () => {
        if (Array.isArray(data)) {
            return data.map((item, index) => ((0, jsx_runtime_1.jsx)(JsonNode_1.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]) => ((0, jsx_runtime_1.jsx)(JsonNode_1.JsonNode, { nodeKey: key, value: value, keyPath: key, level: 0, toggleExpanded: toggleExpanded, checkExpanded: checkExpanded }, key)));
        }
        return ((0, jsx_runtime_1.jsx)(JsonNode_1.JsonNode, { nodeKey: "root", value: data, keyPath: "root", level: 0, toggleExpanded: toggleExpanded, checkExpanded: checkExpanded }));
    };
    return ((0, jsx_runtime_1.jsxs)(styles_1.Container, { children: [(0, jsx_runtime_1.jsx)(styles_1.Actions, { secondaryVisible: [
                    {
                        onClick: copyAll,
                        name: copyStatus,
                        icon: (0, jsx_runtime_1.jsx)(CopyOutlineMd_1.CopyOutlineMd, {}),
                        variant: 'text',
                    },
                    {
                        onClick: expandAll,
                        name: 'Развернуть все',
                        icon: (0, jsx_runtime_1.jsx)(FullSizeOutlineMd_1.FullSizeOutlineMd, {}),
                        variant: 'text',
                    },
                    {
                        onClick: collapseAll,
                        name: 'Свернуть все',
                        icon: (0, jsx_runtime_1.jsx)(MinimizeOutlineMd_1.MinimizeOutlineMd, {}),
                        variant: 'text',
                    },
                ] }), (0, jsx_runtime_1.jsx)(styles_1.Content, { children: renderRootNodes() })] }));
};
exports.JsonViewer = JsonViewer;
