'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var dynamicEvents = require('../../../../events/dynamicEvents.cjs');
require('@dynamic-labs-sdk/client/core');
require('@dynamic-labs/sdk-api-core');
require('../../../client.cjs');
require('react');
require('@dynamic-labs-sdk/client');
require('../../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react/jsx-runtime');
require('../../../../context/ViewContext/ViewContext.cjs');
require('../../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
require('../../../../utils/constants/colors.cjs');
require('../../../../utils/constants/values.cjs');
require('../../../../shared/consts/index.cjs');
require('../../../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../../store/state/nonce/nonce.cjs');
require('@dynamic-labs/locale');
require('../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
var convertSdkUserToUserProfile = require('../convertSdkUserToUserProfile/convertSdkUserToUserProfile.cjs');
var hasSocialAccountChanged = require('../hasSocialAccountChanged/hasSocialAccountChanged.cjs');
var getProjectSettings = require('../../projectSettings/getProjectSettings/getProjectSettings.cjs');

const hasFieldChanged = (fields, record1, record2) => {
    if (!record1 || !record2)
        return false;
    for (const name of fields) {
        const oldValue = record1[name];
        const newValue = record2[name];
        if (JSON.stringify(oldValue) !== JSON.stringify(newValue)) {
            return true;
        }
    }
    return false;
};
const raiseUserProfileEvent = ({ oldUser, newUser, }) => {
    var _a, _b;
    const settings = getProjectSettings.getProjectSettings();
    if (!settings)
        return;
    const hasKycChanged = hasFieldChanged(settings.kyc.map(({ name }) => name), oldUser, newUser);
    const hasCustomFieldsChanged = hasFieldChanged((_b = (_a = settings.customFields) === null || _a === void 0 ? void 0 : _a.map(({ name }) => name)) !== null && _b !== void 0 ? _b : [], oldUser === null || oldUser === void 0 ? void 0 : oldUser.metadata, newUser.metadata);
    // Only check for social account changes if oldUser exists (not initial sign-up)
    const socialAccountChanged = oldUser
        ? hasSocialAccountChanged.hasSocialAccountChanged(oldUser, newUser)
        : false;
    if (!hasKycChanged && !hasCustomFieldsChanged && !socialAccountChanged)
        return;
    dynamicEvents.dynamicEvents.emit('userProfileUpdated', convertSdkUserToUserProfile.convertSdkUserToUserProfile(newUser));
};

exports.hasFieldChanged = hasFieldChanged;
exports.raiseUserProfileEvent = raiseUserProfileEvent;
