import { useCallback, useMemo } from "react";
import { selectShouldShowThinkingDots } from "./agentSessionSelectors";
import { selectHasSpawnedAgents, selectHasTodoContent, } from "./agentSessionSelectors";
export function useAgentTerminalViewState(input) {
    const { agent, agentStub, activeProfile, profiles, messages, error, hideGreeting, isSubmitting, isConnecting, activeInlineDialog, allPendingApprovalsCount, isAgentThinking, isExecuting, isWaitingForResponse, sessionCostLimitExceeded, isLoading, sessionState, } = input;
    const showInitialThinkingSplash = messages.length === 0 &&
        !error &&
        hideGreeting &&
        (isSubmitting || isConnecting);
    const shouldShowThinkingDots = selectShouldShowThinkingDots({
        activeInlineDialog,
        allPendingApprovalsCount,
        isAgentThinking,
        isConnecting,
        isExecuting,
        isSubmitting,
        isWaitingForResponse,
        messages,
        sessionCostLimitExceeded,
        showInitialThinkingSplash,
    });
    const resolvedEditorContextMode = useMemo(() => {
        try {
            const normalizedAgentProfileId = agent?.profileId?.toLowerCase();
            const profile = activeProfile ||
                profiles.find((p) => p.id?.toLowerCase() === normalizedAgentProfileId);
            return profile?.editorContextMode ?? null;
        }
        catch {
            return null;
        }
    }, [activeProfile, profiles, agent?.profileId]);
    const parentAgentId = agent?.parentAgentId ||
        agent?.ParentAgentId ||
        agentStub?.parentAgentId ||
        agentStub?.ParentAgentId;
    const handleBackToParent = useCallback(() => {
        if (!parentAgentId)
            return;
        window.dispatchEvent(new CustomEvent("editor:openAgent", {
            detail: { agentId: parentAgentId },
        }));
    }, [parentAgentId]);
    return {
        showInitialThinkingSplash,
        shouldShowThinkingDots,
        resolvedEditorContextMode,
        isLiveEditorContextMode: resolvedEditorContextMode === "live",
        omitsEditorContext: resolvedEditorContextMode === "none",
        parentAgentId,
        handleBackToParent,
        shouldShowLoadingContent: isLoading && !activeInlineDialog,
        hasSpawnedAgents: selectHasSpawnedAgents(sessionState),
        hasTodoContent: selectHasTodoContent(sessionState),
        hasHistoryContent: sessionState.operationHistory.length > 0,
    };
}
//# sourceMappingURL=useAgentTerminalViewState.js.map