function userKey(session) {
    const name = session.user?.name?.trim().toLowerCase();
    return name || `session:${session.sessionId}`;
}
/**
 * Reduces page presence to one stable representative session per user.
 * The Sessions sidebar deliberately shows every session; the menubar avatar
 * stack represents people and must not let one user's tabs consume several
 * slots. The current session wins for the current user, then users and their
 * representative sessions are ordered deterministically.
 */
export function selectActiveUserSessions(sessions, currentSessionId) {
    const sorted = [...sessions].sort((left, right) => {
        const leftIsCurrent = left.sessionId === currentSessionId;
        const rightIsCurrent = right.sessionId === currentSessionId;
        if (leftIsCurrent !== rightIsCurrent)
            return leftIsCurrent ? -1 : 1;
        const byUser = userKey(left).localeCompare(userKey(right));
        return byUser || left.sessionId.localeCompare(right.sessionId);
    });
    const seenUsers = new Set();
    return sorted.filter((session) => {
        const key = userKey(session);
        if (seenUsers.has(key))
            return false;
        seenUsers.add(key);
        return true;
    });
}
//# sourceMappingURL=activeUserSessions.js.map