import React, { useCallback, useMemo } from 'react';
import { createContext } from '@fluentui/react-context-selector';
import { getEntityType } from '@reltio/mdm-sdk';
import { useMdmEntity, useMdmMetadata } from '../MdmModuleContext';
import { getIsVerificationAttribute, getVerificationStatus as getVerificationStatusHelper, getVerificationType as getVerificationTypeHelper, getAllVerificationAttributeTypeUris, getAllVerificationTypes as getAllVerificationTypesHelper } from './helpers';
export var AttributesVerificationContext = createContext(null);
export var AttributesVerificationProvider = function (_a) {
    var children = _a.children;
    var metadata = useMdmMetadata();
    var currentEntity = useMdmEntity();
    var attributeVerificationConfig = useMemo(function () {
        var _a;
        var entityType = (currentEntity === null || currentEntity === void 0 ? void 0 : currentEntity.type) && metadata && getEntityType(metadata, currentEntity.type);
        return ((_a = entityType === null || entityType === void 0 ? void 0 : entityType.cleanseConfig) === null || _a === void 0 ? void 0 : _a.attributeVerificationConfig) || [];
    }, [currentEntity === null || currentEntity === void 0 ? void 0 : currentEntity.type, metadata]);
    var verificationAttributeTypeUris = useMemo(function () {
        return getAllVerificationAttributeTypeUris(attributeVerificationConfig, currentEntity === null || currentEntity === void 0 ? void 0 : currentEntity.type);
    }, [attributeVerificationConfig, currentEntity === null || currentEntity === void 0 ? void 0 : currentEntity.type]);
    var isVerificationAttribute = useCallback(function (attributeType) {
        return getIsVerificationAttribute(attributeType, attributeVerificationConfig);
    }, [attributeVerificationConfig]);
    var getVerificationStatus = useCallback(function (attributeType, attributeValue) {
        return getVerificationStatusHelper(attributeType, attributeValue, attributeVerificationConfig);
    }, [attributeVerificationConfig]);
    var getVerificationType = useCallback(function (attributeType) {
        return getVerificationTypeHelper(attributeType, attributeVerificationConfig);
    }, [attributeVerificationConfig]);
    var getAllVerificationTypes = useCallback(function () {
        return getAllVerificationTypesHelper(attributeVerificationConfig);
    }, [attributeVerificationConfig]);
    var contextValue = useMemo(function () { return ({
        isVerificationAttribute: isVerificationAttribute,
        getVerificationStatus: getVerificationStatus,
        getVerificationType: getVerificationType,
        verificationAttributeTypeUris: verificationAttributeTypeUris,
        getAllVerificationTypes: getAllVerificationTypes
    }); }, [
        isVerificationAttribute,
        getVerificationStatus,
        getVerificationType,
        verificationAttributeTypeUris,
        getAllVerificationTypes
    ]);
    return (React.createElement(AttributesVerificationContext.Provider, { value: contextValue }, children));
};
