"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const InfiniteTreeListContext_1 = require("../../InfiniteTreeListContext");
const InfiniteTreeListItem_1 = require("../../InfiniteTreeListItem");
const useLogic = ({ actions }) => {
    const { main, secondary = [] } = actions;
    const { setDisabledReason, item } = (0, react_1.useContext)(InfiniteTreeListItem_1.TreeListItemContext);
    const { setDisabled } = (0, react_1.useContext)(InfiniteTreeListContext_1.InfiniteTreeListContext);
    const blockingAction = (0, react_1.useMemo)(() => [...main, ...secondary].find((action) => action.isBlockingOperation && action.loading), [main, secondary]);
    const isDisabledAction = Boolean(blockingAction);
    (0, react_1.useEffect)(() => {
        if (blockingAction) {
            // Добавляем id элемента в Set disabled элементов
            setDisabled(item.id, true);
            setDisabledReason(blockingAction?.loadingNote);
            return;
        }
        // Удаляем id элемента из Set disabled элементов
        setDisabled(item.id, false);
        setDisabledReason('');
    }, [blockingAction, item.id]);
    const handleActionClick = (0, react_1.useCallback)((onClick) => () => {
        onClick?.(item);
    }, [item]);
    const handleWrapperClick = (event) => {
        event.stopPropagation();
    };
    return { isDisabledAction, handleActionClick, handleWrapperClick };
};
exports.useLogic = useLogic;
