'use client'
import { version } from 'react';
import '../../../../../_virtual/_tslib.js';
import '@dynamic-labs/utils';
import '@dynamic-labs/sdk-api-core';
import '@dynamic-labs-sdk/client/core';
import '../../../client/client.js';
import '@dynamic-labs-sdk/client';
import '../../../config/ApiEndpoint.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react/jsx-runtime';
import '../../../context/ViewContext/ViewContext.js';
import { logger } from '../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '../../constants/colors.js';
import '../../constants/values.js';
import '../../../shared/consts/index.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import { serializeWalletConnectors } from '../../functions/serializeWalletConnectors/serializeWalletConnectors.js';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../../events/dynamicEvents.js';
import { sendDynamicProps } from '../../../data/api/settings/settings.js';
import '@dynamic-labs/locale';
import { useEffectOnce } from '../useEffectOnce/useEffectOnce.js';

const useSendDynamicProps = ({ settings, environmentId, }) => {
    useEffectOnce(() => {
        // we ReactNode components are not being serialized properly
        // remove them for now and deal with them later
        // context: https://linear.app/dynamic-labs/issue/GVTY-328/[starknet]-sdk-api-is-not-serializing-react-components
        // future work: https://linear.app/dynamic-labs/issue/GVTY-330/bug-figure-out-why-react-components-are-not
        const updatedDynamicProps = {
            settings: Object.assign(Object.assign({}, settings), { customPrivacyPolicy: Boolean(settings.customPrivacyPolicy), customTermsOfServices: Boolean(settings.customTermsOfServices), policiesConsentInnerComponent: Boolean(settings.policiesConsentInnerComponent) }),
        };
        const serializedEventsCallbacks = serializeEventsCallbacks(settings.events);
        const serializedWalletConnectors = serializeWalletConnectors(settings.walletConnectors);
        const serializedDynamicContextProps = Object.assign(Object.assign({}, updatedDynamicProps), { settings: Object.assign(Object.assign({}, updatedDynamicProps.settings), { events: serializedEventsCallbacks, walletConnectors: serializedWalletConnectors }) });
        sendDynamicProps(environmentId, {
            dynamicContextProps: serializedDynamicContextProps,
            frameworkSettings: getFrameworkSettings(),
        });
    });
};
const serializeEventsCallbacks = (events) => {
    try {
        if (!events)
            return undefined;
        const eventsCallbackValues = Object.values(events);
        const eventsKeys = Object.keys(events);
        return eventsKeys.filter((key, index) => {
            if (eventsCallbackValues[index] === undefined) {
                return false;
            }
            return key;
        });
    }
    catch (error) {
        logger.error('error serializing events', error);
        return undefined;
    }
};
const getFrameworkSettings = () => {
    var _a;
    return ({
        nextJs: {
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            version: (_a = window.next) === null || _a === void 0 ? void 0 : _a.version,
        },
        react: {
            version,
        },
    });
};

export { serializeEventsCallbacks, useSendDynamicProps };
