import { cannotInvokeMethodOnServerError } from '../utils/errors.mjs';

const SSRStubKey = Symbol('__stytch_SSRStubKey');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isStytchSSRProxy = (proxy)=>{
    return !!proxy[SSRStubKey];
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const createProxy = (path)=>{
    // eslint-disable-next-line @typescript-eslint/no-empty-function
    const noop = ()=>{};
    return new Proxy(noop, {
        get (target, p) {
            if (p === SSRStubKey) {
                return true;
            }
            return createProxy(path + '.' + String(p));
        },
        apply () {
            throw new Error(cannotInvokeMethodOnServerError(path));
        }
    });
};
// Exported for testing
const createStytchSSRProxy = ()=>createProxy('stytch');
function ssrSafeClientFactory(ClientConstructor) {
    return (...args)=>{
        if (typeof window === 'undefined') {
            return createStytchSSRProxy();
        }
        return new ClientConstructor(...args);
    };
}

export { createStytchSSRProxy, isStytchSSRProxy, ssrSafeClientFactory };
//# sourceMappingURL=StytchSSRProxy.mjs.map
