"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useHistoryEnabled = void 0;
var react_1 = require("react");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var PerspectivesSettingsContext_1 = require("../../../contexts/PerspectivesSettingsContext");
var useHistoryEnabled = function (_a) {
    var perspectiveId = _a.perspectiveId, entity = _a.entity, historyButtonId = _a.historyButtonId;
    var perspectiveSettings = (0, PerspectivesSettingsContext_1.usePerspectivesSettings)(perspectiveId).perspectiveSettings;
    var active = (perspectiveSettings || {}).active;
    var isHistoryTabActive = active === historyButtonId;
    var _b = (0, react_1.useState)(false), wasHistoryTabActive = _b[0], setWasHistoryTabActive = _b[1];
    var entityUri = entity === null || entity === void 0 ? void 0 : entity.uri;
    (0, react_1.useEffect)(function () {
        if (!isHistoryTabActive) {
            setWasHistoryTabActive(false);
        }
    }, [entityUri]);
    (0, react_1.useEffect)(function () {
        if (isHistoryTabActive) {
            setWasHistoryTabActive(true);
        }
    }, [isHistoryTabActive]);
    var isProfilePersisted = entityUri && !(0, mdm_sdk_1.isTempUri)(entityUri) && !(0, mdm_sdk_1.isDataTenantEntity)(entity);
    var isHistoryEnabled = wasHistoryTabActive && isProfilePersisted;
    return { isHistoryEnabled: isHistoryEnabled, isProfilePersisted: isProfilePersisted };
};
exports.useHistoryEnabled = useHistoryEnabled;
