"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useBlockingActions = void 0;
const react_1 = require("react");
const Row_1 = require("../../../DataGrid/Row");
const ActionCellContext_1 = require("../../ActionCellContext");
/**
 * хук позволяющий подписаться на событие блокировки действий
 */
const useBlockingActions = (actions) => {
    const { addDisabledRow, removeDisabledRow } = (0, react_1.useContext)(Row_1.RowContext);
    const { addDisabledCell, removeDisabledCell, isDisabled, onActionClick } = (0, react_1.useContext)(ActionCellContext_1.ActionCellContext);
    const blockingAction = [...(actions || [])].find((action) => action.isBlockingOperation && action.loading);
    (0, react_1.useEffect)(() => {
        if (blockingAction) {
            addDisabledRow(blockingAction?.loadingNote);
            addDisabledCell(blockingAction?.loadingNote);
            return;
        }
        removeDisabledRow();
        removeDisabledCell();
    }, [blockingAction]);
    return {
        isDisabled,
        onActionClick,
    };
};
exports.useBlockingActions = useBlockingActions;
