import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { memo } from 'react';
import { Collapse } from '../../../Collapse';
import { dataGridRowClassnames } from '../constants';
import { MoreButton, MoreButtonRow, NestedRows } from './styles';
import { useLogic } from './useLogic';
export const NestedChildren = memo((props) => {
    const { isShowAllChildren, isShowMoreButton, isShowConnector, nextLevel, initialVisibleChildren, otherChildren, handleToggleShowAllChildren, } = useLogic(props);
    const { isOpen, data, keyId, level, gridColumns, moreButtonColumnPosition, renderRow, } = props;
    if (!data || !data.length) {
        return null;
    }
    return (_jsx(Collapse, { in: isOpen, unmountOnExit: true, children: _jsxs(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 && (_jsxs(_Fragment, { children: [_jsx(Collapse, { in: isShowAllChildren, component: "li", unmountOnExit: true, children: _jsx(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: dataGridRowClassnames.hidden,
                                    });
                                }) }) }), isShowMoreButton && (_jsx(MoreButtonRow, { "$level": nextLevel, "$isShowConnector": isShowConnector, "$gridColumns": gridColumns, children: _jsx(MoreButton, { "$moreButtonColumnPosition": moreButtonColumnPosition, variant: "link", onClick: handleToggleShowAllChildren, children: isShowAllChildren ? 'Скрыть' : 'Показать все' }) }))] }))] }) }));
});
