/*!
 * KoliBri - The accessible HTML-Standard
 */
let WINDOW = null;
let DOCUMENT = null;
export const getWindow = () => {
    if (WINDOW)
        return WINDOW;
    if (typeof window !== 'undefined')
        return window;
    return {};
};
export const setWindow = (value) => {
    WINDOW = value;
};
export const getDocument = () => {
    if (DOCUMENT)
        return DOCUMENT;
    const win = getWindow();
    if (win && typeof win.document !== 'undefined')
        return win.document;
    return {};
};
export const setDocument = (value) => {
    DOCUMENT = value;
};
const MODES = ['development', 'production', 'test'];
let runtimeMode = 'production';
export const setRuntimeMode = (mode) => {
    try {
        if (MODES.includes(mode)) {
            runtimeMode = mode;
        }
        else {
            throw new Error(`Invalid NODE_ENV value: ${mode}. Expected one of ${MODES.join(', ')}.`);
        }
    }
    catch (_a) {
        runtimeMode = 'production';
    }
};
const getInitialMode = () => {
    try {
        const nodeEnv = typeof process !== 'undefined' && process.env ? process.env['NODE_ENV'] : undefined;
        if (nodeEnv && MODES.includes(nodeEnv)) {
            return nodeEnv;
        }
    }
    catch (_a) {
    }
    return 'production';
};
setRuntimeMode(getInitialMode());
let EXPERIMENTAL_MODE = false;
let COLOR_CONTRAST_ANALYSIS = false;
export const isDevMode = () => runtimeMode === 'development';
export const isTestMode = () => runtimeMode === 'test';
export const isProdMode = () => runtimeMode === 'production';
export const getExperimentalMode = () => EXPERIMENTAL_MODE === true;
export const setExperimentalMode = (mode) => {
    EXPERIMENTAL_MODE = mode === true;
};
export const getColorContrastAnalysis = () => COLOR_CONTRAST_ANALYSIS === true;
export const setColorContrastAnalysis = (mode) => {
    COLOR_CONTRAST_ANALYSIS = mode === true;
};
const LOG_STYLE = 'color: white; background: #666; font-weight: bold; padding: .25em .5em; border-radius: 3px; border: 1px solid #000';
const mapToArray = (msg) => {
    return Array.isArray(msg) ? msg : [msg];
};
const getLogLabel = (label) => {
    return `%c${label}`;
};
const handleClassifier = (label, classifier) => {
    if (typeof classifier === 'string' && classifier.length > 0) {
        return `${getLogLabel(label)} | ${classifier}`;
    }
    else {
        return getLogLabel(label);
    }
};
const getShield = (label, options) => {
    return [handleClassifier(label, options === null || options === void 0 ? void 0 : options.classifier), `${LOG_STYLE};${(options === null || options === void 0 ? void 0 : options.overwriteStyle) || ''}`];
};
const isDevModeOrForceLog = (forceLog) => isDevMode() || forceLog === true;
export class Logger {
    constructor(label) {
        this.label = label;
    }
    debug(msg, options) {
        if (isDevModeOrForceLog(options === null || options === void 0 ? void 0 : options.forceLog)) {
            console.debug(...getShield(this.label, options), ...mapToArray(msg));
        }
    }
    info(msg, options) {
        if (isDevModeOrForceLog(options === null || options === void 0 ? void 0 : options.forceLog)) {
            console.info(...getShield(this.label, options), ...mapToArray(msg));
        }
    }
    trace(msg, options) {
        if (isDevModeOrForceLog(options === null || options === void 0 ? void 0 : options.forceLog)) {
            console.trace(...getShield(this.label, options), ...mapToArray(msg));
        }
    }
    warn(msg, options) {
        if (isDevModeOrForceLog(options === null || options === void 0 ? void 0 : options.forceLog)) {
            console.warn(...getShield(this.label, options), ...mapToArray(msg));
        }
    }
    error(msg, options) {
        console.error(...getShield(this.label, options), ...mapToArray(msg));
    }
    throw(msg, options) {
        if (isDevModeOrForceLog(options === null || options === void 0 ? void 0 : options.forceLog)) {
            throw new Error(...getShield(this.label, options), ...mapToArray(msg));
        }
    }
}
export const Log = new Logger('KoliBri');
//# sourceMappingURL=dev.utils.js.map
