'use strict';

var SDKErrors = require('./SDKErrors-CyFa69Ys.js');

/**
 * A set of tokens to stylize the console.log output
 * First token is the raw text. %c is a placeholder for string formatting
 * Second token starts our stylizing - adding custom color and background
 * Third token resets stylizing to baseline before showing the rest of the content.
 */ const STYTCH_BADGE = [
    '%c[Stytch]%c',
    'background: #19303d; color: #13E5C0; padding: 2px;border-radius: 4px',
    ''
];
// Turn this to true to enable debug logs
// TODO: Make this an env var
const DEBUG = false;
/* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-explicit-any */ /**
 * An ultralightweight wrapper around console.log.
 * In the future, the logger might be passed in from the customer,
 * or the level might be configurable.
 */ const logger = {
    debug: (...args)=>DEBUG,
    log: (...args)=>console.log(...STYTCH_BADGE, ...args),
    warn: (...args)=>console.warn(...STYTCH_BADGE, ...args),
    error: (...args)=>console.error(...STYTCH_BADGE, ...args)
}; /* eslint-enable @typescript-eslint/no-explicit-any */  /* eslint-enable no-console */

/**
 * This function and its parameter is stripped in production builds using rollup plugin.
 * NOTE: Be careful when wrapping render function return values. React before v18 do not allow undefined
 *       to be returned, so wrapping the entire return value will crash those runtimes.
 */ const DEV = (input)=>input;
/**
 * This function is stripped in production builds using rollup plugin. Useful for adding
 * logging or validation in dev only
 */ function RUN_IN_DEV(callback) {
    callback();
}
const validateInDev = (methodName, obj, rules)=>{
    const errors = [];
    for (const [key, rule] of Object.entries(rules)){
        if (rule == null) continue;
        const val = obj[key];
        if (rule.startsWith('optional') && val == null) continue;
        switch(rule){
            case 'object':
            case 'optionalObject':
                {
                    const isObject = typeof val === 'object' && !Array.isArray(val) && val !== null;
                    if (!isObject) {
                        errors.push(new SDKErrors.StytchSDKUsageError(methodName, `${key} must be an object.`));
                    }
                    break;
                }
            case 'string':
            case 'optionalString':
                if (typeof val !== 'string') {
                    errors.push(new SDKErrors.StytchSDKUsageError(methodName, `${key} must be a string.`));
                }
                break;
            case 'number':
            case 'optionalNumber':
                if (typeof val !== 'number') {
                    errors.push(new SDKErrors.StytchSDKUsageError(methodName, `${key} must be a number.`));
                }
                break;
            case 'stringArray':
            case 'optionalStringArray':
                if (!Array.isArray(val) || !val.every((str)=>typeof str === 'string')) {
                    errors.push(new SDKErrors.StytchSDKUsageError(methodName, `${key} must be an array of strings.`));
                }
                break;
            case 'boolean':
            case 'optionalBoolean':
                if (typeof val !== 'boolean') {
                    errors.push(new SDKErrors.StytchSDKUsageError(methodName, `${key} must be a boolean.`));
                }
                break;
        }
    }
    if (errors.length > 0) {
        if (errors.length === 1) {
            throw errors[0];
        } else {
            throw new AggregateError(errors);
        }
    }
};

exports.DEV = DEV;
exports.RUN_IN_DEV = RUN_IN_DEV;
exports.logger = logger;
exports.validateInDev = validateInDev;
//# sourceMappingURL=dev-DSQ2JLWy.js.map
