import { Box, Container, Spacer, Text } from '../../tui/index.js';
import { theme } from '../theme/runtime.js';
/**
 * Owns the transient "Active subagents" surface that shows grouped task tool
 * output while child agents are still running.
 */
export class ActiveTaskOverlay {
    hostContainer = new Container();
    overlayContent = new Container();
    overlayPanel = undefined;
    suspendCount = 0;
    getContainer() {
        return this.hostContainer;
    }
    clear() {
        this.hostContainer.clear();
        this.overlayContent.clear();
    }
    showGroup(group) {
        group.setSuppressOuterPrefix(true);
        if (!this.overlayContent.children.includes(group)) {
            this.overlayContent.addChild(group);
        }
        this.ensureVisible();
    }
    moveGroupToChat(group, chatContainer) {
        if (this.overlayContent.children.includes(group)) {
            this.overlayContent.removeChild(group);
        }
        group.setSuppressOuterPrefix(false);
        if (!chatContainer.children.includes(group)) {
            chatContainer.addChild(group);
        }
        this.ensureVisible();
    }
    removeGroup(group) {
        if (this.overlayContent.children.includes(group)) {
            this.overlayContent.removeChild(group);
            this.ensureVisible();
        }
    }
    hasGroup(group) {
        return this.overlayContent.children.includes(group);
    }
    suspend() {
        this.suspendCount += 1;
        this.ensureVisible();
        let resumed = false;
        return () => {
            if (resumed)
                return;
            resumed = true;
            this.suspendCount = Math.max(0, this.suspendCount - 1);
            this.ensureVisible();
        };
    }
    ensureVisible() {
        if (this.overlayContent.children.length === 0 || this.suspendCount > 0) {
            this.hostContainer.clear();
            return;
        }
        if (!this.overlayPanel) {
            this.overlayPanel = new Box(1, 0, (text) => theme.bg('customMessageBg', text));
            this.overlayPanel.addChild(new Text(`${theme.fg('warning', '●')} ${theme.fg('customMessageLabel', theme.bold('Active subagents'))}`, 0, 0));
            this.overlayPanel.addChild(this.overlayContent);
        }
        if (!this.hostContainer.children.includes(this.overlayPanel)) {
            this.hostContainer.clear();
            this.hostContainer.addChild(new Spacer(1));
            this.hostContainer.addChild(this.overlayPanel);
        }
    }
}
//# sourceMappingURL=active-task-overlay.js.map