import { useContext } from 'react';
import { DataGridContext } from '../../../DataGridContext';
import { Variant } from '../../../enums';
export const useLogic = ({ rowId, data, level, variant, initialVisibleChildrenCount, }) => {
    const { checkIsMoreOpened, toggleOpenMoreItems } = useContext(DataGridContext);
    const isTreeVariant = Object.is(variant, 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,
    };
};
