"use strict";
/**
 * Tiny `debug`-compatible shim. Activated by setting the DEBUG environment
 * variable to a comma-separated list of namespaces (or "*" / "node-telegram-bot-api*").
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = createDebug;
function namespaceEnabled(namespace) {
    const env = process.env.DEBUG ?? "";
    if (!env)
        return false;
    return env
        .split(/[\s,]+/)
        .filter(Boolean)
        .some((pattern) => {
        if (pattern === "*")
            return true;
        if (pattern.endsWith("*"))
            return namespace.startsWith(pattern.slice(0, -1));
        return pattern === namespace;
    });
}
function format(arg, formatter) {
    if (formatter === "%j")
        return JSON.stringify(arg);
    if (typeof arg === "object")
        return JSON.stringify(arg);
    return String(arg);
}
function createDebug(namespace) {
    const enabled = namespaceEnabled(namespace);
    return (template, ...rest) => {
        if (!enabled)
            return;
        let i = 0;
        const expanded = template.replace(/%[sdjOo%]/g, (token) => {
            if (token === "%%")
                return "%";
            const value = rest[i++];
            return format(value, token);
        });
        // eslint-disable-next-line no-console
        console.error(`  ${namespace} ${expanded}`);
    };
}
//# sourceMappingURL=debug.cjs.map