"use client";
import { useMemo } from "react";
import { useWorkflowExecution } from "../useWorkflowExecution";
import { deriveExecutionComparison } from "./derive-execution-comparison";
/**
 * Behavior hook that fetches two workflow executions and derives
 * a structural comparison between them.
 *
 * Pass `null` for either ID to skip that fetch (e.g., while the
 * user is selecting a comparison target). The comparison result
 * is only produced when both executions are loaded.
 *
 * Returns referentially stable objects when inputs haven't changed
 * (DD-010 compliance).
 *
 * @example
 * ```tsx
 * const { comparison, isLoading } = useExecutionComparison({
 *   baseId: "wfx_failed_123",
 *   compareId: "wfx_success_456",
 * });
 * if (comparison) {
 *   console.log(comparison.divergencePoint);
 * }
 * ```
 */
export function useExecutionComparison({ baseId, compareId, }) {
    const { execution: baseExecution, isLoading: baseLoading, error: baseError, refetch: baseRefetch, } = useWorkflowExecution(baseId);
    const { execution: compareExecution, isLoading: compareLoading, error: compareError, refetch: compareRefetch, } = useWorkflowExecution(compareId);
    const comparison = useMemo(() => {
        if (!baseExecution || !compareExecution)
            return null;
        return deriveExecutionComparison(baseExecution, compareExecution);
    }, [baseExecution, compareExecution]);
    const refetch = useMemo(() => () => {
        baseRefetch();
        compareRefetch();
    }, [baseRefetch, compareRefetch]);
    return {
        comparison,
        isLoading: baseLoading || compareLoading,
        error: baseError ?? compareError ?? null,
        refetch,
    };
}
//# sourceMappingURL=useExecutionComparison.js.map