"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const DataGridContext_1 = require("../../../DataGridContext");
const enums_1 = require("../../../enums");
const useLogic = ({ rowId, data, level, variant, initialVisibleChildrenCount, }) => {
    const { checkIsMoreOpened, toggleOpenMoreItems } = (0, react_1.useContext)(DataGridContext_1.DataGridContext);
    const isTreeVariant = Object.is(variant, enums_1.Variant.Tree);
    const nextLevel = isTreeVariant ? level + 1 : 0;
    const initialVisibleChildren = data?.slice(0, initialVisibleChildrenCount);
    const otherChildren = data?.slice(initialVisibleChildrenCount);
    const isShowAllChildren = checkIsMoreOpened(rowId);
    const isShowMoreButton = Boolean(otherChildren?.length);
    const handleToggleShowAllChildren = (event) => {
        event.stopPropagation();
        toggleOpenMoreItems(rowId);
    };
    return {
        isShowAllChildren,
        isShowMoreButton,
        isShowConnector: isTreeVariant,
        initialVisibleChildren,
        otherChildren,
        nextLevel,
        handleToggleShowAllChildren,
    };
};
exports.useLogic = useLogic;
