import { useRef, useMemo } from 'react';
import { ErrorType, isViewMode } from '@reltio/mdm-sdk';
import { useMdmMode } from '../contexts/MdmModuleContext';
import { areErrorsEqual } from './helpers';
export var useCachedErrors = function (allErrors) {
    var mode = useMdmMode();
    var filteredErrors = useMemo(function () { return (isViewMode(mode) ? allErrors : allErrors.filter(function (_a) {
        var type = _a.type;
        return type !== ErrorType.rdmIssueInReference;
    })); }, [mode, allErrors]);
    var cacheForFilteredErrors = useRef(filteredErrors);
    var areEqualErrors = areErrorsEqual(filteredErrors, cacheForFilteredErrors.current);
    if (!areEqualErrors) {
        cacheForFilteredErrors.current = filteredErrors;
    }
    return cacheForFilteredErrors.current;
};
