"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCachedErrors = void 0;
var react_1 = require("react");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var helpers_1 = require("./helpers");
var useCachedErrors = function (allErrors) {
    var mode = (0, MdmModuleContext_1.useMdmMode)();
    var filteredErrors = (0, react_1.useMemo)(function () { return ((0, mdm_sdk_1.isViewMode)(mode) ? allErrors : allErrors.filter(function (_a) {
        var type = _a.type;
        return type !== mdm_sdk_1.ErrorType.rdmIssueInReference;
    })); }, [mode, allErrors]);
    var cacheForFilteredErrors = (0, react_1.useRef)(filteredErrors);
    var areEqualErrors = (0, helpers_1.areErrorsEqual)(filteredErrors, cacheForFilteredErrors.current);
    if (!areEqualErrors) {
        cacheForFilteredErrors.current = filteredErrors;
    }
    return cacheForFilteredErrors.current;
};
exports.useCachedErrors = useCachedErrors;
