'use client'
import { jsx } from 'react/jsx-runtime';
import { useCallback } from 'react';
import '@dynamic-labs/utils';
import '../../../components/Accordion/components/AccordionItem/AccordionItem.js';
import 'react-i18next';
import { ReactComponent as SvgArrowLeft } from '../../../shared/assets/arrow-left.js';
import { ReactComponent as SvgClose } from '../../../shared/assets/close.js';
import { ReactComponent as SvgFooterInfoIcon } from '../../../shared/assets/footer-info-icon.js';
import { ReactComponent as SvgQuestionMark } from '../../../shared/assets/question-mark.js';
import '@dynamic-labs/iconic';
import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
import '../../../../../_virtual/_tslib.js';
import '@dynamic-labs/wallet-connector-core';
import '../../../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 { useErrorContext } from '../../../context/ErrorContext/ErrorContext.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import '@dynamic-labs-sdk/client/core';
import '../../../client/client.js';
import '@dynamic-labs-sdk/client';
import '../../../config/ApiEndpoint.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 { useAccountExistsContext } from '../../../context/AccountExistsContext/AccountExistsContext.js';
import '../../../context/UserWalletsContext/UserWalletsContext.js';
import '../../../context/VerificationContext/VerificationContext.js';
import 'react-dom';
import '../../../utils/functions/compareChains/compareChains.js';
import '../../../views/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 '../../../views/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 { Typography } from '../../../components/Typography/Typography.js';
import { useAuthLayoutChecks } from '../../../utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.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 { useFooterAnimationContext } from '../../../context/FooterAnimationContext/index.js';
import { Skeleton } from '../../../components/Skeleton/Skeleton.js';
import { Tooltip } from '../../../components/Tooltip/Tooltip.js';
import '../../../context/WalletGroupContext/WalletGroupContext.js';
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
import 'react-focus-lock';
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
import { IconButton } from '../../../components/IconButton/IconButton.js';
import { ModalHeader } from '../../../components/ModalHeader/ModalHeader.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 '../../../views/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 '../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.js';
import '../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
import '../../../views/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 '../../../components/InlineWidget/InlineWidget.js';
import '../../../components/IsBrowser/IsBrowser.js';
import '../../../components/Popper/Popper/Popper.js';
import '../../../components/Popper/PopperContext/PopperContext.js';

const Header = ({ onClose: handleClose, heading, projectSettings, copykey, description, descriptionCopykey, }) => {
    const { setError } = useErrorContext();
    const { isFooterExpanded, setIsFooterExpanded } = useFooterAnimationContext();
    const { view, canGoBack, goBack } = useViewContext();
    const { showCloseButton, showHelpContent, isWalletListTypeView, displayBorderBelowHeader, } = useAuthLayoutChecks();
    const { setExistentAccountData } = useAccountExistsContext();
    const handleBackClick = useCallback(() => {
        var _a, _b;
        (_b = (_a = view.events) === null || _a === void 0 ? void 0 : _a.onBackClick) === null || _b === void 0 ? void 0 : _b.call(_a);
        goBack();
        setExistentAccountData(undefined);
        setError(undefined);
    }, [view.events, goBack, setExistentAccountData, setError]);
    const closeButton = showCloseButton && handleClose && (jsx(IconButton, { onClick: handleClose, type: 'button', id: 'close-button', "data-testid": 'close-button', className: 'layout-header__icon', children: jsx(SvgClose, {}) }));
    const infoButton = showHelpContent && (jsx(Tooltip, { content: 'Need some help?', className: 'layout-header__tooltip', children: jsx(IconButton, { type: 'button', onClick: () => setIsFooterExpanded(!isFooterExpanded), "data-testid": 'info-button', className: 'layout-header__icon', children: isWalletListTypeView ? jsx(SvgQuestionMark, {}) : jsx(SvgFooterInfoIcon, {}) }) }, 'info-button'));
    const leadingButtons = [];
    if (canGoBack) {
        leadingButtons.push(jsx(IconButton, { type: 'button', onClick: handleBackClick, "data-testid": 'back-button', className: 'layout-header__icon', children: jsx(SvgArrowLeft, {}) }, 'back-button'));
    }
    // if has close button and info button, info button should be on the right
    if (closeButton && infoButton) {
        leadingButtons.push(infoButton);
    }
    return (jsx("div", { className: 'layout-header', children: jsx(ModalHeader, { leading: leadingButtons, trailing: closeButton || infoButton, displayBorder: displayBorderBelowHeader, alignContent: 'bottom', description: description && (jsx(Typography, { as: 'p', variant: 'body_mini', color: 'secondary', copykey: descriptionCopykey, className: 'layout-header__description', children: description })), children: (!projectSettings || heading) && (jsx(Typography, { as: 'h1', variant: 'title', color: 'primary', "data-testid": 'dynamic-auth-modal-heading', className: 'layout-header__typography', copykey: copykey, children: !projectSettings ? (jsx(Skeleton, { className: 'layout-header__skeleton' })) : (heading) })) }) }));
};

export { Header };
