"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useScrollToAttributeError = void 0;
var react_1 = require("react");
var ramda_1 = require("ramda");
var classnames_1 = __importDefault(require("classnames"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var styles_1 = require("./styles");
var useScrollToAttributeError = function (_a) {
    var _b;
    var context = _a.highlightedError, _c = _a.isSimple, isSimple = _c === void 0 ? false : _c, className = _a.className;
    var styles = (0, styles_1.useStyles)();
    var ref = (0, react_1.useRef)(null);
    var severity = (0, ramda_1.pathOr)(mdm_sdk_1.ErrorSeverity.ERROR, ['element', 'severity'])(context);
    var errorClassName = (0, classnames_1.default)((_b = {},
        _b[styles.highlightError] = severity === mdm_sdk_1.ErrorSeverity.ERROR,
        _b[styles.highlightWarning] = severity === mdm_sdk_1.ErrorSeverity.WARNING,
        _b[styles.simpleAttribute] = isSimple,
        _b), className);
    (0, react_1.useEffect)(function () {
        if (context) {
            context.scrollIntoRef(ref);
        }
    }, [context]);
    return context ? { ref: ref, errorClassName: errorClassName } : { ref: ref };
};
exports.useScrollToAttributeError = useScrollToAttributeError;
