'use client'
'use strict';

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

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var iconic = require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
var dotsHorizontal = require('../../shared/assets/dots-horizontal.cjs');
require('../../context/ViewContext/ViewContext.cjs');
var logger = require('../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
require('../../utils/constants/colors.cjs');
require('../../utils/constants/values.cjs');
var providerLabel = require('../../shared/utils/functions/providerLabel/providerLabel.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../shared/consts/index.cjs');
var classNames = require('../../utils/functions/classNames/classNames.cjs');
require('../../events/dynamicEvents.cjs');
require('../../../../_virtual/_tslib.cjs');
require('../../context/DynamicContext/DynamicContext.cjs');
require('../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
require('../../store/state/authMode/authMode.cjs');
require('../../context/CaptchaContext/CaptchaContext.cjs');
require('../../context/ErrorContext/ErrorContext.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../store/state/nonce/nonce.cjs');
require('@dynamic-labs-sdk/client/core');
require('../../client/client.cjs');
require('@dynamic-labs-sdk/client');
require('../../config/ApiEndpoint.cjs');
require('@dynamic-labs/locale');
require('../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../context/AccessDeniedContext/AccessDeniedContext.cjs');
require('../../context/AccountExistsContext/AccountExistsContext.cjs');
require('../../context/UserWalletsContext/UserWalletsContext.cjs');
require('../../context/VerificationContext/VerificationContext.cjs');
require('react-dom');
require('../../utils/functions/compareChains/compareChains.cjs');
require('../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
var useIconThemeVariant = require('../../utils/hooks/useIconThemeVariant/useIconThemeVariant.cjs');
require('../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
require('bs58');
require('@dynamic-labs/types');
require('../../context/SocialRedirectContext/SocialRedirectContext.cjs');
require('../../context/LoadingContext/LoadingContext.cjs');
require('../../context/WalletContext/WalletContext.cjs');
require('../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
require('yup');
require('../../context/MockContext/MockContext.cjs');
require('../../views/CollectUserDataView/useFields.cjs');
require('../../context/FieldsStateContext/FieldsStateContext.cjs');
require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
require('@dynamic-labs/rpc-providers');
require('../../store/state/walletOptions/walletOptions.cjs');
require('../Accordion/components/AccordionItem/AccordionItem.cjs');
require('../Alert/Alert.cjs');
var Typography = require('../Typography/Typography.cjs');
var Icon = require('../Icon/Icon.cjs');
require('../ShadowDOM/ShadowDOM.cjs');
var IconWithSpinner = require('../IconWithSpinner/IconWithSpinner.cjs');
require('../IconButton/IconButton.cjs');
var IconListTile = require('../IconListTile/IconListTile.cjs');
require('../InlineWidget/InlineWidget.cjs');
require('../Input/Input.cjs');
require('../IsBrowser/IsBrowser.cjs');
require('../MenuList/Dropdown/Dropdown.cjs');
var OverlayCard = require('../OverlayCard/OverlayCard.cjs');
require('../Transition/ZoomTransition/ZoomTransition.cjs');
require('../Transition/SlideInUpTransition/SlideInUpTransition.cjs');
require('../Transition/OpacityTransition/OpacityTransition.cjs');
require('../PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
require('../Popper/Popper/Popper.cjs');
require('../Popper/PopperContext/PopperContext.cjs');
require('react-focus-lock');
require('qrcode');
require('../../context/ThemeContext/ThemeContext.cjs');
require('formik');
require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
require('../../context/WalletGroupContext/WalletGroupContext.cjs');
require('../../context/IpConfigurationContext/IpConfigurationContext.cjs');
require('../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
require('../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
require('@hcaptcha/react-hcaptcha');
require('../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
require('../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
require('../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../../context/FooterAnimationContext/index.cjs');
require('../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
require('../../context/PasskeyContext/PasskeyContext.cjs');
require('../../context/OnrampContext/OnrampContext.cjs');
require('../../store/state/sendBalances.cjs');
require('../../store/state/connectorsInitializing/connectorsInitializing.cjs');
require('../OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
require('../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
require('../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
require('../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs');
require('../../../index.cjs');
require('../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
require('../../store/state/tokenBalances.cjs');
require('../../store/state/multichainBalances.cjs');
require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');

const INTERNAL_MAX_INLINE_ITEMS = 5;
const SocialSignIn = ({ providers, onSelectProvider, isLoading, selectedProvider, testId, defaultProvider, numOfItemsToDisplay: externalMaxInlineItems = 5, collapsedLayout, }) => {
    const { t } = reactI18next.useTranslation();
    const iconThemeVariant = useIconThemeVariant.useIconThemeVariant();
    // ====================================
    // INLINE VS DEFAULT PROVIDERS
    // ====================================
    // Set default provider as the first available provider if default provider isn't within the providers
    if (defaultProvider && !providers.includes(defaultProvider)) {
        [defaultProvider] = providers;
    }
    /** All enabled providers except the default one */
    const inlineProviders = providers.filter((provider) => provider !== defaultProvider);
    // ====================================
    // ALL PROVIDERS VIEW
    // ====================================
    /** Number of items set in prop, with a max limit of INTERNAL_MAX_INLINE_ITEMS */
    const maxInlineItems = Math.min(externalMaxInlineItems, INTERNAL_MAX_INLINE_ITEMS);
    // Show card button if there are more inline providers than the max
    const showAllProvidersButton = inlineProviders.length > maxInlineItems;
    /** The inline providers that we will show */
    const cappedInlineProviders = showAllProvidersButton
        ? inlineProviders.slice(0, maxInlineItems - 1)
        : inlineProviders.slice(0, maxInlineItems);
    const [showAllProvidersCard, setShowAllProvidersCard] = React.useState(false);
    const closeAllProvidersCard = () => !isLoading && setShowAllProvidersCard(false);
    // ====================================
    // REACT DISPLAY
    // ====================================
    // Display all with full width if there's only one, or
    // there's no wallet list and 3 social items or less
    const showAllFullWidth = providers.length === 1 || (!collapsedLayout && providers.length < 4);
    const getProviderAsString = (provider) => provider;
    const renderProviderItem = (provider, fullWidth = false, insideCard = false) => (jsxRuntime.jsxs(IconListTile.IconListTile, { dataTestId: insideCard ? `card-${provider}` : `inline-${provider}`, onClick: () => onSelectProvider(provider), disabled: Boolean(selectedProvider), className: classNames.classNames({
            'social-sign-in--card--tile': insideCard,
            'social-sign-in--tile': !insideCard,
            'social-sign-in--tile__full-width': fullWidth,
        }), children: [jsxRuntime.jsx(IconWithSpinner.IconWithSpinner, { Icon: 
                // eslint-disable-next-line react/jsx-wrap-multilines
                jsxRuntime.jsx(iconic.SocialIcon, { name: getProviderAsString(provider), variant: iconThemeVariant }), isSpinning: selectedProvider === provider, iconSize: 32 }), !insideCard && fullWidth && (jsxRuntime.jsx(Typography.Typography, { variant: 'button_primary', copykey: 'dyn_login.social.button_label', children: t('dyn_login.social.button_label', {
                    provider: providerLabel.providerLabel(provider),
                }) }))] }, getProviderAsString(provider)));
    if (!providers.length) {
        logger.logger.error('Failed to render SocialSignInSection - no social providers enabled');
        return null;
    }
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: 'social-sign-in', "data-testid": testId, children: [defaultProvider && renderProviderItem(defaultProvider, true), cappedInlineProviders.map((provider) => renderProviderItem(provider, showAllFullWidth)), showAllProvidersButton && (jsxRuntime.jsx(IconListTile.IconListTile, { dataTestId: 'show-more-options', onClick: () => setShowAllProvidersCard(true), className: 'social-sign-in--tile', children: jsxRuntime.jsx(Icon.Icon, { color: 'text-primary', children: jsxRuntime.jsx(dotsHorizontal.ReactComponent, {}) }) }, 'show-more-options'))] }), jsxRuntime.jsxs(OverlayCard.OverlayCard, { isOpen: showAllProvidersCard, onClose: closeAllProvidersCard, children: [jsxRuntime.jsx(OverlayCard.OverlayCard.Header, { closeDisabled: isLoading, children: t('dyn_login.social.overlay_title') }), jsxRuntime.jsx(OverlayCard.OverlayCard.Content, { className: 'social-sign-in--card--body', children: providers.map((provider) => renderProviderItem(provider, false, true)) })] })] }));
};

exports.SocialSignIn = SocialSignIn;
