import { jsx } from "react/jsx-runtime";
import cache from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import { ReactFlowProvider, useReactFlow } from "../../../xyflow/react.js";
import { createContext, useCallback, useContext, useMemo } from "react";
import { BASE_CANVAS_DEFAULTS } from "../../BaseCanvas/BaseCanvas.constants.js";
const AgentFlowProviderContext = /*#__PURE__*/ createContext(null);
const AgentVisualizationFlowProviderInner = ({ children, styleContainer, fitViewOptions })=>{
    const reactFlow = useReactFlow();
    const emotionCache = useMemo(()=>{
        if (styleContainer) return cache({
            key: 'agent-flow-shadow',
            container: styleContainer,
            prepend: true
        });
    }, [
        styleContainer
    ]);
    const resetViewport = useCallback(()=>{
        reactFlow.fitView(fitViewOptions ?? BASE_CANVAS_DEFAULTS.fitViewOptions);
    }, [
        reactFlow,
        fitViewOptions
    ]);
    const value = useMemo(()=>({
            resetViewport
        }), [
        resetViewport
    ]);
    const content = /*#__PURE__*/ jsx(AgentFlowProviderContext.Provider, {
        value: value,
        children: children
    });
    return emotionCache ? /*#__PURE__*/ jsx(CacheProvider, {
        value: emotionCache,
        children: content
    }) : content;
};
const AgentVisualizationFlowProvider = ({ styleContainer, fitViewOptions, ...props })=>/*#__PURE__*/ jsx(ReactFlowProvider, {
        children: /*#__PURE__*/ jsx(AgentVisualizationFlowProviderInner, {
            styleContainer: styleContainer,
            fitViewOptions: fitViewOptions,
            ...props
        })
    });
const useAgentFlow = ()=>{
    const context = useContext(AgentFlowProviderContext);
    if (!context) throw new Error('useAgentFlow must be used within an AgentFlowProvider');
    return context;
};
export { AgentVisualizationFlowProvider, useAgentFlow };
