import '../../../../../../node_modules/preact/compat/dist/compat.module.mjs';
import { readB2BInternals } from '../../../utils/internal.mjs';
import { useStytch, useConfig } from '../GlobalContextProvider.mjs';
import { useState as h, useEffect as p } from '../../../../../../node_modules/preact/hooks/dist/hooks.module.mjs';

/**
 * Resolves the best email domain to use as a hint for login
 */ const useEmailDomain = ()=>{
    const stytch = useStytch();
    const config = useConfig();
    /**
   * Read the emailDomains out of sync storage, then read out of async storage
   * TODO - Should all bootstrap data live in the config somewhere?
   */ const [emailDomains, setEmailDomains] = h(()=>{
        const { emailDomains } = readB2BInternals(stytch).bootstrap.getSync();
        return emailDomains;
    });
    p(()=>{
        readB2BInternals(stytch).bootstrap.getAsync().then(({ emailDomains })=>{
            setEmailDomains(emailDomains);
        });
    }, [
        stytch
    ]);
    // If a domain is explicitly passed in, use it!
    if (config.emailMagicLinksOptions?.domainHint) {
        return config.emailMagicLinksOptions?.domainHint;
    }
    // If there can only be one logical choice, use it!
    if (emailDomains.length === 1) {
        return emailDomains[0];
    }
    // If it isn't clear who sent the email
    // we simply won't provide a hint!
    return null;
};

export { useEmailDomain };
//# sourceMappingURL=useEmailDomain.mjs.map
