"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._AIAgentContext = void 0;
exports.AIAgentContextProvider = AIAgentContextProvider;
exports.useAIAgentContext = useAIAgentContext;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const AIAgentContext = (0, react_1.createContext)(null);
exports._AIAgentContext = AIAgentContext;
/**
 * Provider that manages the AI data registry.
 * Wrap your app or chat area with this to enable AIData collection.
 */
function AIAgentContextProvider({ children }) {
    const registryRef = (0, react_1.useRef)(new Map());
    const contextValue = (0, react_1.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 (0, jsx_runtime_1.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`.
 */
function useAIAgentContext() {
    const ctx = (0, react_1.useContext)(AIAgentContext);
    const getData = (0, react_1.useCallback)(() => {
        if (!ctx)
            return [];
        return ctx.getData();
    }, [ctx]);
    return (0, react_1.useMemo)(() => ({ getData }), [getData]);
}
//# sourceMappingURL=AIAgentContext.js.map
