"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestedChildren = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const Collapse_1 = require("../../../Collapse");
const constants_1 = require("../constants");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
exports.NestedChildren = (0, react_1.memo)((props) => {
    const { isShowAllChildren, isShowMoreButton, isShowConnector, nextLevel, initialVisibleChildren, otherChildren, handleToggleShowAllChildren, } = (0, useLogic_1.useLogic)(props);
    const { isOpen, data, keyId, level, gridColumns, moreButtonColumnPosition, renderRow, } = props;
    if (!data || !data.length) {
        return null;
    }
    return ((0, jsx_runtime_1.jsx)(Collapse_1.Collapse, { in: isOpen, unmountOnExit: true, children: (0, jsx_runtime_1.jsxs)(styles_1.NestedRows, { "$level": level, "$isShowConnector": isShowConnector, children: [initialVisibleChildren.map(({ children, options, ...nestedRow }) => {
                    const nestedRowId = nestedRow[keyId];
                    return renderRow({
                        key: nestedRowId,
                        row: nestedRow,
                        options,
                        nestedChildren: children,
                        level: nextLevel,
                    });
                }), isOpen && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Collapse_1.Collapse, { in: isShowAllChildren, component: "li", unmountOnExit: true, children: (0, jsx_runtime_1.jsx)(styles_1.NestedRows, { "$level": level, "$isShowConnector": isShowConnector, children: otherChildren.map(({ children, options, ...nestedRow }) => {
                                    const nestedRowId = nestedRow[keyId];
                                    return renderRow({
                                        key: nestedRowId,
                                        row: nestedRow,
                                        options,
                                        nestedChildren: children,
                                        level: nextLevel,
                                        className: constants_1.dataGridRowClassnames.hidden,
                                    });
                                }) }) }), isShowMoreButton && ((0, jsx_runtime_1.jsx)(styles_1.MoreButtonRow, { "$level": nextLevel, "$isShowConnector": isShowConnector, "$gridColumns": gridColumns, children: (0, jsx_runtime_1.jsx)(styles_1.MoreButton, { "$moreButtonColumnPosition": moreButtonColumnPosition, variant: "link", onClick: handleToggleShowAllChildren, children: isShowAllChildren ? 'Скрыть' : 'Показать все' }) }))] }))] }) }));
});
