"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useProvideAIData = useProvideAIData;
exports.AIData = AIData;
const react_1 = require("react");
const AIAgentContext_1 = require("./AIAgentContext.js");
/**
 * Hook to register data in the AI agent context.
 *
 * Registration happens in `useEffect`, so `getData()` is only meaningful
 * **after mount** of components that register data. Do not call `getData()`
 * synchronously during render or in `useLayoutEffect` in the same commit.
 *
 * Uses a ref + getter pattern: the registry stores `() => propsRef.current`
 * so `getData()` always reads the latest props without re-registering on every render.
 */
function useProvideAIData(props) {
    const ctx = (0, react_1.useContext)(AIAgentContext_1._AIAgentContext);
    const id = (0, react_1.useId)();
    const propsRef = (0, react_1.useRef)(props);
    propsRef.current = props;
    (0, react_1.useEffect)(() => {
        if (!ctx) {
            // eslint-disable-next-line no-console
            console.warn('useProvideAIData must be used inside AIAgentContextProvider');
            return;
        }
        ctx.register(id, () => propsRef.current);
        // eslint-disable-next-line consistent-return
        return () => {
            ctx.unregister(id);
        };
    }, [ctx, id]);
}
/**
 * Component that registers data in the AI agent context.
 * Pure side-effect — renders nothing.
 */
function AIData(props) {
    useProvideAIData(props);
    return null;
}
//# sourceMappingURL=AIData.js.map
