const DEBUG_SNIPPET_LENGTH = 180;
let debugEnabled = false;
const listeners = new Set();
export function isDebugModeEnabled() {
    return debugEnabled;
}
export function setDebugMode(enabled) {
    const normalized = Boolean(enabled);
    if (normalized === debugEnabled) {
        return;
    }
    debugEnabled = normalized;
    for (const listener of listeners) {
        listener(debugEnabled);
    }
}
export function onDebugModeChange(listener) {
    listeners.add(listener);
    return () => {
        listeners.delete(listener);
    };
}
export function logDebug(...args) {
    if (!debugEnabled) {
        return;
    }
    console.error(...args);
}
export function debugSnippet(value, maxLength = DEBUG_SNIPPET_LENGTH) {
    if (!value) {
        return '';
    }
    const collapsed = value.replace(/\s+/g, ' ').trim();
    if (collapsed.length <= maxLength) {
        return collapsed;
    }
    return `${collapsed.slice(0, maxLength)}…`;
}
//# sourceMappingURL=debugLogger.js.map