/** Keep-alive room visibility gates for timeline network pagination (no React). */

const needsScrollBeforeNetwork = new Set<string>();

export const setRoomTimelineVisible = (roomId: string, visible: boolean): void => {
  if (visible) {
    // Stays in needsScroll until the user scrolls (armed while hidden).
    return;
  }
  needsScrollBeforeNetwork.add(roomId);
};

export const armRoomTimelineNetworkPaginate = (roomId: string): void => {
  needsScrollBeforeNetwork.delete(roomId);
};

export const canRoomTimelineNetworkPaginate = (roomId: string): boolean =>
  !needsScrollBeforeNetwork.has(roomId);

export const clearRoomTimelineVisibilityGate = (roomId: string): void => {
  needsScrollBeforeNetwork.delete(roomId);
};
