"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAttributeState = void 0;
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var react_1 = require("react");
var AttributeStates;
(function (AttributeStates) {
    AttributeStates["Reading"] = "Reading";
    AttributeStates["Hovered"] = "Hovered";
    AttributeStates["Editing"] = "Editing";
})(AttributeStates || (AttributeStates = {}));
var HIDE_INTERVAL = 50;
var useAttributeState = function () {
    var _a = (0, react_1.useState)(null), attributeState = _a[0], setAttributeState = _a[1];
    var isReadingMode = attributeState === AttributeStates.Reading;
    var isEditingMode = attributeState === AttributeStates.Editing;
    var isHovered = attributeState === AttributeStates.Hovered;
    (0, react_1.useEffect)(function () {
        setAttributeState(AttributeStates.Reading);
    }, []);
    // eslint-disable-next-line react-hooks/exhaustive-deps
    var setAttributeStateDebounced = (0, react_1.useCallback)((0, mdm_sdk_1.debounce)(setAttributeState, HIDE_INTERVAL), []);
    var onMouseEnter = (0, react_1.useCallback)(function () {
        if (!isEditingMode)
            setAttributeStateDebounced(AttributeStates.Hovered);
    }, [setAttributeStateDebounced, isEditingMode]);
    var onMouseLeave = (0, react_1.useCallback)(function () {
        if (!isEditingMode)
            setAttributeStateDebounced(AttributeStates.Reading);
    }, [setAttributeStateDebounced, isEditingMode]);
    var setReadingMode = (0, react_1.useCallback)(function () { return setAttributeState(AttributeStates.Reading); }, [setAttributeState]);
    var setEditingMode = (0, react_1.useCallback)(function () { return setAttributeState(AttributeStates.Editing); }, [setAttributeState]);
    return {
        setReadingMode: setReadingMode,
        setEditingMode: setEditingMode,
        onMouseLeave: onMouseLeave,
        onMouseEnter: onMouseEnter,
        isReadingMode: isReadingMode,
        isEditingMode: isEditingMode,
        isHovered: isHovered
    };
};
exports.useAttributeState = useAttributeState;
