'use client'
import '@dynamic-labs-sdk/client/core';
import '@dynamic-labs/sdk-api-core';
import 'react';
import 'eventemitter3';
import '@dynamic-labs/utils';
import '@dynamic-labs-sdk/client';
import '../../../../config/ApiEndpoint.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react/jsx-runtime';
import { useViewContext } from '../../../../context/ViewContext/ViewContext.js';
import '../../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '../../../constants/colors.js';
import '../../../constants/values.js';
import { hasPendingMfaAction } from '../../../../shared/utils/functions/hasPendingMfaAction/hasPendingMfaAction.js';
import '../../../../shared/consts/index.js';
import '../../../../../../_virtual/_tslib.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../../store/state/nonce/nonce.js';
import '@dynamic-labs-wallet/browser-wallet-client';
import '@dynamic-labs/locale';
import '../../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
import '../../../../events/dynamicEvents.js';
import { useUserProfile } from '../../../../client/extension/user/useUser/useUser.js';
import '../../../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
import { mfaViewsThatPreventModalClose, viewsThatPreventModalClose, viewsThatHideCloseButton } from '../../../constants/authViewLayoutChecks.js';

const useAllowClose = () => {
    const { view } = useViewContext();
    const user = useUserProfile();
    const { showAuthFlow } = useInternalDynamicContext();
    const isMfaPreventingClose = user &&
        hasPendingMfaAction(user) &&
        mfaViewsThatPreventModalClose.includes(view.type);
    const allowsClosing = !isMfaPreventingClose &&
        (!showAuthFlow || !viewsThatPreventModalClose.includes(view.type));
    const showCloseButton = allowsClosing && !viewsThatHideCloseButton.includes(view.type);
    return {
        /**
         * Whether user can close the current view
         */
        allowsClosing,
        /**
         * Whether the close button should be shown.
         * Even if the view allows closing, the close button may still be hidden.
         */
        showCloseButton,
    };
};

export { useAllowClose };
