"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.incrementTmuxControlCapturePaneCalls = incrementTmuxControlCapturePaneCalls;
exports.setTmuxControlActiveSessions = setTmuxControlActiveSessions;
exports.setTmuxControlSubscriberCount = setTmuxControlSubscriberCount;
exports.incrementTmuxControlCleanupCount = incrementTmuxControlCleanupCount;
exports.observeTmuxControlFirstOutputLatency = observeTmuxControlFirstOutputLatency;
exports.getTmuxControlModeMetrics = getTmuxControlModeMetrics;
exports.resetTmuxControlModeMetrics = resetTmuxControlModeMetrics;
const state = {
    capturePaneCalls: 0,
    activeControlSessions: 0,
    subscriberCount: 0,
    cleanupCount: 0,
    firstOutputLatencyCount: 0,
    firstOutputLatencyTotalMs: 0,
    firstOutputLatencyLastMs: null,
    firstOutputLatencyMinMs: null,
    firstOutputLatencyMaxMs: null,
};
function incrementTmuxControlCapturePaneCalls() {
    state.capturePaneCalls += 1;
}
function setTmuxControlActiveSessions(count) {
    state.activeControlSessions = Math.max(0, count);
}
function setTmuxControlSubscriberCount(count) {
    state.subscriberCount = Math.max(0, count);
}
function incrementTmuxControlCleanupCount() {
    state.cleanupCount += 1;
}
function observeTmuxControlFirstOutputLatency(durationMs) {
    const normalized = Math.max(0, Math.round(durationMs));
    state.firstOutputLatencyCount += 1;
    state.firstOutputLatencyTotalMs += normalized;
    state.firstOutputLatencyLastMs = normalized;
    state.firstOutputLatencyMinMs = state.firstOutputLatencyMinMs === null
        ? normalized
        : Math.min(state.firstOutputLatencyMinMs, normalized);
    state.firstOutputLatencyMaxMs = state.firstOutputLatencyMaxMs === null
        ? normalized
        : Math.max(state.firstOutputLatencyMaxMs, normalized);
}
function getTmuxControlModeMetrics() {
    return {
        capturePaneCalls: state.capturePaneCalls,
        activeControlSessions: state.activeControlSessions,
        subscriberCount: state.subscriberCount,
        cleanupCount: state.cleanupCount,
        firstOutputLatency: {
            count: state.firstOutputLatencyCount,
            lastMs: state.firstOutputLatencyLastMs,
            minMs: state.firstOutputLatencyMinMs,
            maxMs: state.firstOutputLatencyMaxMs,
            avgMs: state.firstOutputLatencyCount > 0
                ? Math.round(state.firstOutputLatencyTotalMs / state.firstOutputLatencyCount)
                : null,
        },
    };
}
function resetTmuxControlModeMetrics() {
    state.capturePaneCalls = 0;
    state.activeControlSessions = 0;
    state.subscriberCount = 0;
    state.cleanupCount = 0;
    state.firstOutputLatencyCount = 0;
    state.firstOutputLatencyTotalMs = 0;
    state.firstOutputLatencyLastMs = null;
    state.firstOutputLatencyMinMs = null;
    state.firstOutputLatencyMaxMs = null;
}
