import { useEffect, useState } from 'react';
import { isTempUri, isDataTenantEntity } from '@reltio/mdm-sdk';
import { usePerspectivesSettings } from '../../../contexts/PerspectivesSettingsContext';
export var useHistoryEnabled = function (_a) {
    var perspectiveId = _a.perspectiveId, entity = _a.entity, historyButtonId = _a.historyButtonId;
    var perspectiveSettings = usePerspectivesSettings(perspectiveId).perspectiveSettings;
    var active = (perspectiveSettings || {}).active;
    var isHistoryTabActive = active === historyButtonId;
    var _b = useState(false), wasHistoryTabActive = _b[0], setWasHistoryTabActive = _b[1];
    var entityUri = entity === null || entity === void 0 ? void 0 : entity.uri;
    useEffect(function () {
        if (!isHistoryTabActive) {
            setWasHistoryTabActive(false);
        }
    }, [entityUri]);
    useEffect(function () {
        if (isHistoryTabActive) {
            setWasHistoryTabActive(true);
        }
    }, [isHistoryTabActive]);
    var isProfilePersisted = entityUri && !isTempUri(entityUri) && !isDataTenantEntity(entity);
    var isHistoryEnabled = wasHistoryTabActive && isProfilePersisted;
    return { isHistoryEnabled: isHistoryEnabled, isProfilePersisted: isProfilePersisted };
};
