'use client'
'use strict';

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

var React = require('react');
require('../../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/utils');
require('@dynamic-labs/sdk-api-core');
require('@dynamic-labs-sdk/client/core');
require('../../../client/client.cjs');
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');
var logger = require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../constants/colors.cjs');
require('../../constants/values.cjs');
require('../../../shared/consts/index.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
var serializeWalletConnectors = require('../../functions/serializeWalletConnectors/serializeWalletConnectors.cjs');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../../events/dynamicEvents.cjs');
var settings = require('../../../data/api/settings/settings.cjs');
require('@dynamic-labs/locale');
var useEffectOnce = require('../useEffectOnce/useEffectOnce.cjs');

const useSendDynamicProps = ({ settings: settings$1, environmentId, }) => {
    useEffectOnce.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$1), { customPrivacyPolicy: Boolean(settings$1.customPrivacyPolicy), customTermsOfServices: Boolean(settings$1.customTermsOfServices), policiesConsentInnerComponent: Boolean(settings$1.policiesConsentInnerComponent) }),
        };
        const serializedEventsCallbacks = serializeEventsCallbacks(settings$1.events);
        const serializedWalletConnectors = serializeWalletConnectors.serializeWalletConnectors(settings$1.walletConnectors);
        const serializedDynamicContextProps = Object.assign(Object.assign({}, updatedDynamicProps), { settings: Object.assign(Object.assign({}, updatedDynamicProps.settings), { events: serializedEventsCallbacks, walletConnectors: serializedWalletConnectors }) });
        settings.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.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: React.version,
        },
    });
};

exports.serializeEventsCallbacks = serializeEventsCallbacks;
exports.useSendDynamicProps = useSendDynamicProps;
