"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from "react";
import { FileChangeSetStatus, } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
import { displayFileChangeSets } from "@stigmer/sdk";
import { cn } from "@stigmer/theme";
import { FileReviewCard } from "../execution/FileReviewCard.js";
import { useExecutionStream } from "../execution/useExecutionStream.js";
/**
 * Renders the child agent file reviews surfaced on a parent WorkflowExecution.
 *
 * Reference-only, derive-from-child: the parent status carries only
 * {@link WorkflowPendingFileReview} references (child id + change set ids). This
 * list mounts one {@link WorkflowChildFileReview} per referenced child, which
 * streams that child's execution and reuses the agent-level {@link FileReviewCard}
 * to render the actual diff — the heavy content stays single-sourced on the child.
 * A decision is forwarded to the child via `WorkflowExecution.submitFileDecision`.
 *
 * This is the file-review sibling of the workflow tool-approval surface
 * (`WorkflowExecutionApprovalCard`). Empty `pendingFileReviews` renders nothing.
 */
export function WorkflowFileReviewList({ pendingFileReviews, onSubmitFileDecision, submittingDecisionKeys, decisionErrors, onNavigateToAgentExecution, className, }) {
    if (pendingFileReviews.length === 0)
        return null;
    return (_jsx("div", { className: cn("stgm space-y-3", className), children: pendingFileReviews.map((ref) => (_jsx(WorkflowChildFileReview, { reference: ref, onSubmitFileDecision: onSubmitFileDecision, submittingDecisionKeys: submittingDecisionKeys, decisionErrors: decisionErrors, onNavigateToAgentExecution: onNavigateToAgentExecution }, ref.childAgentExecutionId))) }));
}
/**
 * Streams a single referenced child agent execution and renders its
 * AWAITING_REVIEW change sets (intersected with the parent's surfaced reference,
 * so a decision always targets a gate the workflow has actually surfaced).
 */
function WorkflowChildFileReview({ reference, onSubmitFileDecision, submittingDecisionKeys, decisionErrors, onNavigateToAgentExecution, }) {
    const childId = reference.childAgentExecutionId;
    const { execution } = useExecutionStream(childId);
    const changeSets = useMemo(() => {
        const referenced = new Set(reference.changeSetId);
        return displayFileChangeSets(execution?.status).filter((cs) => cs.status === FileChangeSetStatus.AWAITING_REVIEW &&
            referenced.has(cs.id) &&
            cs.changes.length > 0);
    }, [execution?.status, reference.changeSetId]);
    // Nothing to show yet (child still loading, or its projection has not caught up
    // to the reference). The parent list already signals "review pending" for this
    // child by virtue of the reference existing.
    if (changeSets.length === 0)
        return null;
    return (_jsxs("div", { className: "space-y-2", children: [onNavigateToAgentExecution && (_jsx("button", { type: "button", onClick: () => onNavigateToAgentExecution(childId), className: "text-xs text-muted-foreground hover:text-foreground underline underline-offset-2", children: "View agent execution" })), changeSets.map((changeSet) => (_jsx(FileReviewCard, { fileChangeSet: changeSet, interactive: true, submittingDecisionKeys: submittingDecisionKeys, decisionErrors: decisionErrors, onSubmit: (action, options) => onSubmitFileDecision(childId, changeSet.id, action, options) }, changeSet.id)))] }));
}
//# sourceMappingURL=WorkflowFileReviewList.js.map