import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useCallback, useContext, useMemo, useRef } from 'react';
const AIAgentContext = createContext(null);
/** Raw context — internal use only, not exported from the package. */
export { AIAgentContext as _AIAgentContext };
/**
 * Provider that manages the AI data registry.
 * Wrap your app or chat area with this to enable AIData collection.
 */
export function AIAgentContextProvider({ children }) {
    const registryRef = useRef(new Map());
    const contextValue = useMemo(() => ({
        register: (id, getter) => {
            registryRef.current.set(id, getter);
        },
        unregister: (id) => {
            registryRef.current.delete(id);
        },
        getData: () => Array.from(registryRef.current.values()).map((getter) => {
            const { label, data } = getter();
            return { label, data };
        }),
    }), []);
    return _jsx(AIAgentContext.Provider, { value: contextValue, children: children });
}
/**
 * Hook for consumers to access registered AI data.
 * Returns { getData } where getData() returns the current list of all entries.
 * If no AIAgentContextProvider exists above, getData() returns [].
 *
 * Generic `T` is the **expected** shape of `data` for this consumer — not validated
 * or guaranteed at runtime. The registry is populated by arbitrary `AIData`
 * registrations; entries may not match `T`.
 */
export function useAIAgentContext() {
    const ctx = useContext(AIAgentContext);
    const getData = useCallback(() => {
        if (!ctx)
            return [];
        return ctx.getData();
    }, [ctx]);
    return useMemo(() => ({ getData }), [getData]);
}
//# sourceMappingURL=AIAgentContext.js.map
