"use client";
import { useCallback, useMemo, useState } from "react";
import { serializeWorkflowYaml } from "./serialize-workflow-yaml.js";
import { yamlToGraph } from "./workflow-graph-conversions.js";
import { toReactFlowElements } from "./workflow-graph-conversions.js";
import { applyDagreLayout } from "./layout/index.js";
/**
 * Behavior hook that converts a `Workflow` blueprint into positioned
 * React Flow elements suitable for a read-only overview graph.
 *
 * Pipeline: `Workflow` → YAML → `yamlToGraph` → `applyDagreLayout` → `toReactFlowElements`
 *
 * Manages selected-node state for the click-to-inspect popover.
 *
 * @example
 * ```tsx
 * const { nodesWithSelection, edges, selectedTaskName, setSelectedTaskName } =
 *   useWorkflowOverviewGraph({ workflow });
 * ```
 */
export function useWorkflowOverviewGraph(options) {
    const { workflow } = options;
    const [selectedTaskName, setSelectedTaskName] = useState(null);
    const { nodes, edges } = useMemo(() => {
        if (!workflow?.spec?.tasks?.length) {
            return { nodes: [], edges: [] };
        }
        try {
            const yaml = serializeWorkflowYaml(workflow);
            const graph = yamlToGraph(yaml);
            const laid = applyDagreLayout(graph);
            return toReactFlowElements(laid);
        }
        catch {
            return { nodes: [], edges: [] };
        }
    }, [workflow]);
    const nodesWithSelection = useMemo(() => nodes.map((n) => ({
        ...n,
        selected: n.data.taskName === selectedTaskName,
    })), [nodes, selectedTaskName]);
    const stableSetSelected = useCallback((name) => setSelectedTaskName(name), []);
    return {
        nodes,
        edges,
        selectedTaskName,
        setSelectedTaskName: stableSetSelected,
        nodesWithSelection,
    };
}
//# sourceMappingURL=useWorkflowOverviewGraph.js.map