import { useContextSelector } from '@fluentui/react-context-selector';
import { isEditableMode as checkIsEditableMode, isViewMode as checkIsViewMode, getDependentLookupsStructureNode, getDependentLookupEditorState, getAllRelationsToAddAndEdit, getInitialConnection, getInitialConnectionTempEntity, getCachedActiveErrorsForAttributesPager, getGlobalSearchRequestOptions, getDraftsByViewId, getAuthoringItemsFromLayoutByEntityType, checkProfileScreenIsEnabled, ScreenType } from '@reltio/mdm-sdk';
import { MdmModuleActionsContext, MdmModuleListenersContext, MdmModuleValuesContext } from './context';
import { getDependentLookupEditorContext } from './selectors/dependentLookupEditorContext';
import { getModifiedEntity, getModifiedEntityDefaultProfilePic } from './selectors/entity';
var useMdmModuleActionsContext = function (selector) {
    return useContextSelector(MdmModuleActionsContext, selector);
};
var useMdmModuleValuesContext = function (selector) {
    return useContextSelector(MdmModuleValuesContext, selector);
};
var useMdmModuleListenersContext = function (selector) {
    return useContextSelector(MdmModuleListenersContext, selector);
};
export var useMdmAutoCloseInterval = function () { return useMdmModuleValuesContext(function (context) { return context.autoCloseInterval; }); };
export var useMdmUiError = function () { return useMdmModuleValuesContext(function (context) { return context.uiError; }); };
export var useMdmWorkflowEnvironmentUrl = function () {
    return useMdmModuleValuesContext(function (context) { return context.workflowEnvironmentUrl; });
};
export var useMdmExportPath = function () { return useMdmModuleValuesContext(function (context) { return context.exportPath; }); };
export var useMdmAbsoluteImagePath = function () { return useMdmModuleValuesContext(function (context) { return context.absoluteImagePath; }); };
export var useMdmUiPath = function () { return useMdmModuleValuesContext(function (context) { return context.uiPath; }); };
export var useMdmDtssPath = function () { return useMdmModuleValuesContext(function (context) { return context.dtssPath; }); };
export var useMdmServicesPath = function () { return useMdmModuleValuesContext(function (context) { return context.servicesPath; }); };
export var useMdmWorkflowPath = function () { return useMdmModuleValuesContext(function (context) { return context.workflowPath; }); };
export var useMdmImageServicePath = function () { return useMdmModuleValuesContext(function (context) { return context.imageServicePath; }); };
export var useMdmReltioPath = function () { return useMdmModuleValuesContext(function (context) { return context.reltioPath; }); };
export var useMdmApiPath = function () { return useMdmModuleValuesContext(function (context) { return context.apiPath; }); };
export var useMdmImagePath = function () { return useMdmModuleValuesContext(function (context) { return context.imagePath; }); };
export var useMdmCollaborationPath = function () { return useMdmModuleValuesContext(function (context) { return context.collaborationPath; }); };
export var useMdmImageAttributesFieldsOrder = function () {
    return useMdmModuleValuesContext(function (context) { return context.imageAttributesFieldsOrder; });
};
export var useMdmShowEntityId = function () { return useMdmModuleValuesContext(function (context) { return context.showEntityId; }); };
export var useMdmPivotingAttributes = function () { return useMdmModuleValuesContext(function (context) { return context.pivotingAttributes; }); };
export var useMdmDateMask = function () { return useMdmModuleValuesContext(function (context) { return context.dateMask; }); };
export var useMdmDateTimeMask = function () { return useMdmModuleValuesContext(function (context) { return context.dateTimeMask; }); };
export var useMdmAttributesPresentation = function () {
    return useMdmModuleValuesContext(function (context) { return context.attributesPresentation; });
};
export var useMdmMaxValuesInResponse = function () { return useMdmModuleValuesContext(function (context) { return context.maxValuesInResponse; }); };
export var useMdmAttributesSortingStrategy = function () {
    return useMdmModuleValuesContext(function (context) { return context.attributesSortingStrategy; });
};
export var useMdmLookupAutocomplete = function () { return useMdmModuleValuesContext(function (context) { return context.lookupAutocomplete; }); };
export var useMdmModifiedEntities = function () { return useMdmModuleValuesContext(function (context) { return context.modifiedEntities; }); };
export var useMdmEntity = function () { return useMdmModuleValuesContext(function (context) { return context.entity; }); };
export var useMdmEntityUri = function () { return useMdmModuleValuesContext(function (context) { var _a; return (_a = context.entity) === null || _a === void 0 ? void 0 : _a.uri; }); };
export var useMdmEntityWithDiff = function () { return useMdmModuleValuesContext(function (context) { return context.entityWithDiff; }); };
export var useMdmEntityUriWithDataTenant = function () {
    return useMdmModuleValuesContext(function (context) { return context.entityUriWithDataTenant; });
};
export var useMdmMode = function () { return useMdmModuleValuesContext(function (context) { return context.mode; }); };
export var useMdmIsViewMode = function () { return useMdmModuleValuesContext(function (context) { return checkIsViewMode(context.mode); }); };
export var useMdmIsEditableMode = function () { return useMdmModuleValuesContext(function (context) { return checkIsEditableMode(context.mode); }); };
export var useMdmHistoryDiff = function () { return useMdmModuleValuesContext(function (context) { return context.historyDiff; }); };
export var useMdmHistoryMode = function () { return useMdmModuleValuesContext(function (context) { return context.historyMode; }); };
export var useMdmHistorySlice = function () { return useMdmModuleValuesContext(function (context) { return context.historySlice; }); };
export var useMdmHistoryEvent = function () { return useMdmModuleValuesContext(function (context) { return context.historyEvent; }); };
export var useMdmProfileLastLoadedTime = function () { return useMdmModuleValuesContext(function (context) { return context.profileLastLoadedTime; }); };
export var useMdmLookups = function () { return useMdmModuleValuesContext(function (context) { return context.lookups; }); };
export var useMdmDependentLookups = function () { return useMdmModuleValuesContext(function (context) { return context.dependentLookups; }); };
export var useMdmMetadata = function () { return useMdmModuleValuesContext(function (context) { return context.metadata; }); };
export var useMdmUser = function () { return useMdmModuleValuesContext(function (context) { return context.user; }); };
export var useMdmUsername = function () { return useMdmModuleValuesContext(function (context) { var _a; return (_a = context.user) === null || _a === void 0 ? void 0 : _a.username; }); };
export var useMdmUserRoles = function () { return useMdmModuleValuesContext(function (context) { var _a; return (_a = context.user) === null || _a === void 0 ? void 0 : _a.roles; }); };
export var useMdmTenantObject = function () { return useMdmModuleValuesContext(function (context) { return context.tenant; }); };
export var useMdmTenant = function () { return useMdmModuleValuesContext(function (context) { var _a; return (_a = context.tenant) === null || _a === void 0 ? void 0 : _a.id; }); };
export var useMdmTenantName = function () { return useMdmModuleValuesContext(function (context) { var _a; return (_a = context.tenant) === null || _a === void 0 ? void 0 : _a.name; }); };
export var useMdmEnvironment = function () { return useMdmModuleValuesContext(function (context) { return context.environment; }); };
export var useMdmDataTenants = function () { return useMdmModuleValuesContext(function (context) { return context.dataTenants; }); };
export var useMdmDataTenantsWithIdBuilder = function () {
    return useMdmModuleValuesContext(function (context) { return context.dataTenantsWithIdBuilder; });
};
export var useMdmSearchNavigationData = function () { return useMdmModuleValuesContext(function (context) { return context.searchNavigationData; }); };
export var useMdmSearchProviderData = function () { return useMdmModuleValuesContext(function (context) { return context.searchProviderData; }); };
export var useMdmIsCollaborationEnabled = function () {
    return useMdmModuleValuesContext(function (context) { return context.isCollaborationEnabled; });
};
export var useMdmIsWorkflowEnabled = function () { return useMdmModuleValuesContext(function (context) { return context.isWorkflowEnabled; }); };
export var useMdmProfileErrors = function () { return useMdmModuleValuesContext(function (context) { return context.profileErrors; }); };
export var useMdmIsSourcesScreenEnabled = function (entityTypeUri) {
    return useMdmModuleValuesContext(function (context) {
        return checkProfileScreenIsEnabled(context.uiConfigProfile, ScreenType.Sources, entityTypeUri);
    });
};
export var useMdmModifiedEntityDefaultProfilePic = function (entityUri) {
    return useMdmModuleValuesContext(function (context) {
        return getModifiedEntityDefaultProfilePic(context.modifiedEntities, entityUri);
    });
};
export var useMdmModifiedEntity = function (entityUri) {
    return useMdmModuleValuesContext(function (context) { return getModifiedEntity(context.modifiedEntities, entityUri); });
};
export var useMdmInitialConnectionTempEntity = function (viewId, relationUri) {
    return useMdmModuleValuesContext(function (context) {
        return getInitialConnectionTempEntity(context.relations, viewId, relationUri);
    });
};
export var useMdmInitialConnection = function (viewId, relationUri) {
    return useMdmModuleValuesContext(function (context) { return getInitialConnection(context.relations, viewId, relationUri); });
};
export var useMdmDependentLookupEditorState = function (valueUri) {
    return useMdmModuleValuesContext(function (context) { return getDependentLookupEditorState(context.dependentLookups, valueUri); });
};
export var useMdmActiveErrorsForAttributesPager = function (parentUri, attributeType) {
    return useMdmModuleValuesContext(function (context) {
        return getCachedActiveErrorsForAttributesPager(context.profileErrors, parentUri, attributeType);
    });
};
export var useMdmDependentLookupsStructureNode = function (attributeTypeUri) {
    return useMdmModuleValuesContext(function (context) {
        return getDependentLookupsStructureNode(context.dependentLookups, attributeTypeUri);
    });
};
export var useMdmAllRelationsToAddAndEdit = function (viewIds) {
    return useMdmModuleValuesContext(function (context) { return getAllRelationsToAddAndEdit(context.relations, viewIds); });
};
export var useMdmRelationsDrafts = function (viewId) {
    return useMdmModuleValuesContext(function (context) { return getDraftsByViewId(context.relations, viewId); });
};
export var useMdmDependentLookupEditorContext = function (attributeValue, attributeType) {
    var value = useMdmModuleValuesContext(function (context) {
        var _a, _b, _c;
        return getDependentLookupEditorContext({
            dependentLookups: context.dependentLookups,
            metadata: context.metadata,
            relations: context.relations,
            modifiedEntities: context.modifiedEntities,
            entityUri: (_a = context.entity) === null || _a === void 0 ? void 0 : _a.uri,
            attributeValue: attributeValue,
            attributeType: attributeType,
            hiddenAttributes: (_b = context.hiddenAttributes) === null || _b === void 0 ? void 0 : _b[(_c = context.entity) === null || _c === void 0 ? void 0 : _c.uri]
        });
    });
    return value;
};
export var useMdmGlobalSearchRequestOptions = function (omittingFields) {
    return useMdmModuleValuesContext(function (context) {
        return getGlobalSearchRequestOptions({
            activityFilter: context.activityFilter,
            globalFilter: context.globalFilter,
            searchOptions: context.searchOptions
        }, omittingFields);
    });
};
export var useMdmAuthoringItemsByEntityType = function (entityTypeUri) {
    return useMdmModuleValuesContext(function (context) {
        return getAuthoringItemsFromLayoutByEntityType(context.uiConfigProfile, entityTypeUri);
    });
};
export var useMdmAction = function (action) {
    return useMdmModuleActionsContext(function (context) { return context[action]; });
};
export var useMdmListener = function (listener) {
    return useMdmModuleListenersContext(function (context) { return context[listener]; });
};
var emptyHiddenAttributesObject = {};
export var useMdmHiddenAttributes = function () {
    return useMdmModuleValuesContext(function (context) { return context.hiddenAttributes || emptyHiddenAttributesObject; });
};
var emptyControlAttributes = [];
export var useMdmControlAttributes = function () {
    return useMdmModuleValuesContext(function (context) { return context.controlAttributes || emptyControlAttributes; });
};
export var useMdmShowMasking = function () { return useMdmModuleValuesContext(function (context) { return context.showMasking; }); };
export var useMdmReviewDCREnabled = function () { return useMdmModuleValuesContext(function (context) { return context.reviewDCREnabled; }); };
export var useMdmDcrReviewAllowAddAttributes = function () {
    return useMdmModuleValuesContext(function (context) { return context.dcrReviewAllowAddAttributes; });
};
export var useMdmDcrReviewValidation = function () { return useMdmModuleValuesContext(function (context) { return context.dcrReviewValidation; }); };
export var useMdmCanUserMakeExport = function () { return useMdmModuleValuesContext(function (context) { return context.canUserMakeExport; }); };
export var useMdmDisableTimestampLocalization = function () {
    return useMdmModuleValuesContext(function (context) { var _a; return (_a = context.disableTimestampLocalization) !== null && _a !== void 0 ? _a : false; });
};
