import { useCallback } from 'react';
/**
 * This hooks handles managing a step's output within the graph manager. This hook assumes
 * that each step will have a single output, which will become an invariant we expand upon
 * in the future.
 *
 * @param graph - the graph manager
 * @returns A callback to use when the step output changes
 */ export function useHandleStepOutputChanged(graph) {
    return useCallback((step, output)=>{
        // remove any existing output
        const spec = graph.outputDefinitions.find((def)=>def.node === step.id);
        if (spec) {
            graph.removeOutput(spec.name);
        }
        // if the output is defined, add it
        if (output) {
            graph.addOutput({
                node: step.id,
                name: output
            });
        }
    }, [
        graph
    ]);
}
