import React__default, { useContext } from 'react';
import { noop } from '../../utils/index.mjs';
import { useEvent } from '../hooks/useEvent.mjs';
import { reducer } from './reducer.mjs';
import { Wallets, OTPMethods } from '../../../../core/src/public/ui.mjs';

/* eslint-disable lingui/no-unlocalized-strings -- internal constants, not user-facing strings */ const AppScreens = {
    Main: 'Main',
    FloatingOneTap: 'FloatingOneTap',
    PasskeyRegistrationStart: 'PasskeyRegistrationStart',
    PasskeyRegistrationSuccess: 'PasskeyRegistrationSuccess',
    PasskeyConfirmation: 'PasskeyConfirmation',
    PasswordCreateOrLogin: 'PasswordCreateOrLogin',
    PasswordResetForm: 'PasswordResetForm',
    PasswordForgot: 'PasswordForgot',
    PasswordBreached: 'PasswordBreached',
    PasswordSetNew: 'PasswordSetNew',
    PasswordDedupe: 'PasswordDedupe',
    PasswordConfirmation: 'PasswordConfirmation',
    EmailConfirmation: 'EmailConfirmation',
    OTPAuthenticate: 'OTPAuthenticate',
    OTPConfirmation: 'OTPConfirmation',
    CryptoConnect: 'CryptoConnect',
    CryptoSignMessage: 'CryptoSignMessage',
    CryptoOtherScreen: 'CryptoOtherScreen',
    CryptoSetupWallet: 'CryptoSetupWallet',
    CryptoError: 'CryptoError',
    CryptoConfirmation: 'CryptoConfirmation'
};
const DEFAULT_STATE = {
    screen: AppScreens.Main,
    formState: {
        magicLinkState: {
            email: ''
        },
        otpState: {
            type: OTPMethods.Email,
            methodId: '',
            otpDestination: ''
        },
        cryptoState: {
            walletAddress: '',
            walletOption: Wallets.Metamask,
            walletChallenge: ''
        },
        passwordState: {
            email: '',
            type: 'new'
        },
        resetPasswordState: {
            token: ''
        }
    }
};
const GlobalContext = /*#__PURE__*/ React__default.createContext({
    client: {},
    config: {},
    state: [
        DEFAULT_STATE,
        ()=>null
    ]
});
const GlobalContextProvider = ({ children, client, config, callbacks, initialState })=>{
    const state = React__default.useReducer(reducer, initialState ?? DEFAULT_STATE);
    return /*#__PURE__*/ React__default.createElement(GlobalContext.Provider, {
        value: {
            client,
            state,
            config,
            callbacks
        }
    }, children);
};
const useGlobalContext = ()=>useContext(GlobalContext);
const useStytch$1 = ()=>useGlobalContext().client;
const useGlobalReducer = ()=>useGlobalContext().state;
const useConfig = ()=>useGlobalContext().config;
const useErrorCallback = ()=>useEvent(useGlobalContext().callbacks?.onError ?? noop);
const useEventCallback = ()=>useEvent(useGlobalContext().callbacks?.onEvent ?? noop);

export { AppScreens, DEFAULT_STATE, GlobalContext, GlobalContextProvider, useConfig, useErrorCallback, useEventCallback, useGlobalContext, useGlobalReducer, useStytch$1 as useStytch };
//# sourceMappingURL=GlobalContextProvider.mjs.map
