'use client'
import { jsxs, jsx } from 'react/jsx-runtime';
import { useMemo, useState, useCallback } from 'react';
import '@dynamic-labs/utils';
import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
import 'react-i18next';
import '@dynamic-labs/iconic';
import '../../../../context/ViewContext/ViewContext.js';
import '../../../../../../_virtual/_tslib.js';
import '@dynamic-labs/wallet-connector-core';
import { logger } from '../../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '../../../../utils/constants/colors.js';
import '../../../../utils/constants/values.js';
import '@dynamic-labs/sdk-api-core';
import '../../../../shared/consts/index.js';
import '../../../../components/Alert/Alert.js';
import '../../../../events/dynamicEvents.js';
import '../../../../context/DynamicContext/DynamicContext.js';
import '../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
import '../../../../store/state/authMode/authMode.js';
import '../../../../context/CaptchaContext/CaptchaContext.js';
import '../../../../context/ErrorContext/ErrorContext.js';
import '@dynamic-labs/multi-wallet';
import { isPhoneNumberProviderEnabled } from '../../../../utils/functions/isPhoneNumberProviderEnabled/isPhoneNumberProviderEnabled.js';
import { validatePhoneLength } from '../../../../utils/functions/validatePhoneLength/validatePhoneLength.js';
import 'react-international-phone';
import { getCustomCountries } from '../../../../utils/functions/getCustomCountries/getCustomCountries.js';
import '../../../../store/state/nonce/nonce.js';
import { getSupportedCountriesForVerificationFromProjectSettings } from '../../../../utils/functions/getSupportedCountriesForVerificationFromProjectSettings/getSupportedCountriesForVerificationFromProjectSettings.js';
import { getDefaultCountriesIfEmpty } from '../../../../utils/functions/getDefaultCountriesIfEmpty/getDefaultCountriesIfEmpty.js';
import '@dynamic-labs-sdk/client/core';
import '../../../../client/client.js';
import '@dynamic-labs-sdk/client';
import '../../../../config/ApiEndpoint.js';
import { useProjectSettings } from '../../../../client/extension/projectSettings/useProjectSettings/useProjectSettings.js';
import '@dynamic-labs/locale';
import '../../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
import '../../../../context/AccountExistsContext/AccountExistsContext.js';
import '../../../../context/UserWalletsContext/UserWalletsContext.js';
import '../../../../context/VerificationContext/VerificationContext.js';
import 'react-dom';
import '../../../../utils/functions/compareChains/compareChains.js';
import '../../../Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
import '../../../../context/ThemeContext/ThemeContext.js';
import '../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
import 'bs58';
import '@dynamic-labs/types';
import '../../../../context/SocialRedirectContext/SocialRedirectContext.js';
import '../../../../context/LoadingContext/LoadingContext.js';
import '../../../../context/WalletContext/WalletContext.js';
import '../../../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js';
import 'yup';
import '../../../../context/MockContext/MockContext.js';
import '../../../CollectUserDataView/useFields.js';
import '../../../../context/FieldsStateContext/FieldsStateContext.js';
import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
import '@dynamic-labs/rpc-providers';
import '../../../../store/state/walletOptions/walletOptions.js';
import '../../../../context/FooterAnimationContext/index.js';
import '../../../../components/ShadowDOM/ShadowDOM.js';
import '../../../../components/Transition/ZoomTransition/ZoomTransition.js';
import '../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
import '../../../../components/Transition/OpacityTransition/OpacityTransition.js';
import '../../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
import '../../../../context/WalletGroupContext/WalletGroupContext.js';
import '../../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
import 'react-focus-lock';
import '../../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
import '../../../../components/IconButton/IconButton.js';
import { TypographyButton } from '../../../../components/TypographyButton/TypographyButton.js';
import '../../../../components/MenuList/Dropdown/Dropdown.js';
import 'formik';
import '../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
import '../../../../store/state/sendBalances.js';
import '../../../../components/Input/Input.js';
import '../../../../components/OverlayCard/OverlayCard.js';
import '../../../TransactionConfirmationView/TransactionConfirmationView.js';
import '../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
import '../../../../context/PasskeyContext/PasskeyContext.js';
import '../../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.js';
import '../../../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.js';
import '../../../../context/OnrampContext/OnrampContext.js';
import '../../../../../index.js';
import '../../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.js';
import 'qrcode';
import '../../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
import '../../../../context/IpConfigurationContext/IpConfigurationContext.js';
import '../../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
import '../../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
import '@hcaptcha/react-hcaptcha';
import '../../../ExchangeWhitelistWarning/ExchangeWhitelistWarning.js';
import '../../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
import { useSubmitPhoneNumber } from './useSubmitPhoneNumber/useSubmitPhoneNumber.js';
import '../../../MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.js';
import '../../../../store/state/connectorsInitializing/connectorsInitializing.js';
import '../../../../store/state/tokenBalances.js';
import '../../../../store/state/multichainBalances.js';
import '../../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
import { InlineSubmitButton } from '../../../../components/InlineSubmitButton/InlineSubmitButton.js';
import '../../../../components/InlineWidget/InlineWidget.js';
import '../../../../components/IsBrowser/IsBrowser.js';
import { PhoneNumberField } from '../../../../components/PhoneNumberField/PhoneNumberField.js';
import '../../../../components/Popper/Popper/Popper.js';
import '../../../../components/Popper/PopperContext/PopperContext.js';

const PhoneNumberSignInSection = ({ isLoading, onSubmit, onSubmitError, }) => {
    var _a, _b;
    const projectSettings = useProjectSettings();
    const countriesWithVerification = useMemo(() => {
        const enabledCountries = getSupportedCountriesForVerificationFromProjectSettings(projectSettings);
        // For login, we always want to use only countries with verification supported
        return getCustomCountries(getDefaultCountriesIfEmpty(enabledCountries));
    }, [projectSettings]);
    const [invalidNumberMessage, setInvalidNumberMessage] = useState(undefined);
    const [isInputComplete, setIsInputComplete] = useState(false);
    const [phoneData, setPhoneData] = useState({
        country: undefined,
        phone: '',
    });
    const handleUpdate = useCallback((phoneData) => {
        setPhoneData(phoneData);
        setIsInputComplete(validatePhoneLength(phoneData.phone, phoneData.country));
    }, []);
    const [isHovered, setIsHovered] = useState(false);
    const [isFocused, setIsFocused] = useState(false);
    const handleSubmit = useSubmitPhoneNumber({
        country: phoneData.country,
        onSubmit,
        onSubmitError,
        phone: phoneData.phone,
        setInvalidNumberMessage,
    });
    if (!projectSettings) {
        logger.debug('Failed to render PhoneNumberSignInSection - no project settings');
        return null;
    }
    if (!isPhoneNumberProviderEnabled((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) !== null && _a !== void 0 ? _a : [])) {
        logger.error('Failed to render PhoneNumberSignInSection - no sign in provider enabled');
        return null;
    }
    const showBigSubmitButton = !((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _b === void 0 ? void 0 : _b.emailSubmitButtonInsideInput);
    return (jsxs("form", { className: 'login-with-phone-number-form', onSubmit: (e) => handleSubmit(e), children: [jsx(PhoneNumberField, { countries: countriesWithVerification, onUpdate: handleUpdate, error: invalidNumberMessage, setIsHovered: setIsHovered, setIsFocused: setIsFocused, appendRight: jsx(InlineSubmitButton, { disabled: isLoading || !isInputComplete, highlighted: isInputComplete, isFocused: isFocused, isHovered: isHovered, className: 'login-with-phone-number-form__fields__inline-submit', emailSubmitButtonInsideInput: !showBigSubmitButton }) }), showBigSubmitButton && (jsx(TypographyButton, { dataTestId: 'big-submit-button', buttonClassName: 'login-with-phone-number-form__button', type: 'submit', loading: isLoading, disabled: isLoading || !isInputComplete, buttonVariant: 'brand-primary', buttonPadding: 'login-screen-height', expanded: true, typographyProps: {
                    color: 'inherit',
                }, children: "Continue" }))] }));
};

export { PhoneNumberSignInSection };
