import { getActuateConfig } from '../config/runtime.js';
const GLOBAL_KEY = '__actuateEmailSender';
const FACTORY_KEY = '__actuateEmailProviderFactory';
function store() {
    return globalThis;
}
/**
 * Register the process-wide transactional email sender. Called once at boot by
 * the email plugin. Pass `null` to clear it (used in tests).
 */
export function setEmailSender(sender) {
    store()[GLOBAL_KEY] = sender;
}
/** The sender registered via {@link setEmailSender}, if any. */
export function getRegisteredEmailSender() {
    return store()[GLOBAL_KEY] ?? null;
}
/**
 * Resolve the active transactional email sender, or `null` when email is not
 * configured. Prefers an explicit `platform.email` adapter, then a
 * plugin-registered sender.
 *
 * NOTE: this sync resolver does not see settings configured through the admin
 * UI (Settings > Email). Send paths should prefer `resolveEmailSenderAsync()`
 * from `email/resolve.js`, which checks the DB-backed config first.
 */
export function resolveEmailSender() {
    return getActuateConfig()?.platform?.email ?? getRegisteredEmailSender();
}
/**
 * Register the factory that turns DB-configured email settings into a sender.
 * Called once at boot by the email plugin. Pass `null` to clear (tests).
 */
export function setEmailProviderFactory(factory) {
    store()[FACTORY_KEY] = factory;
}
/** The factory registered via {@link setEmailProviderFactory}, if any. */
export function getEmailProviderFactory() {
    return store()[FACTORY_KEY] ?? null;
}
//# sourceMappingURL=sender.js.map