import * as React from 'react';
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
const Context = createContext([
    // eslint-disable-next-line @typescript-eslint/no-unused-vars,arrow-body-style
    (_cb) => () => {
        return;
    },
    // eslint-disable-next-line @typescript-eslint/no-unused-vars,arrow-body-style
    (_newSuggestion) => {
        return;
    },
]);
export const SharedAutocompleteContext = ({ children }) => {
    const context = useMemo(() => {
        let suggestion = null;
        const listeners = new Set();
        return [
            (cb) => {
                cb(suggestion);
                listeners.add(cb);
                return () => {
                    listeners.delete(cb);
                };
            },
            (newSuggestion) => {
                suggestion = newSuggestion;
                listeners.forEach((listener) => listener(newSuggestion));
            },
        ];
    }, []);
    return React.createElement(Context.Provider, { value: context }, children);
};
export const useSharedAutocompleteContext = () => {
    const [subscribe, publish] = useContext(Context);
    const [suggestion, setSuggestion] = useState(null);
    useEffect(() => subscribe((newSuggestion) => {
        setSuggestion(newSuggestion);
    }), [subscribe]);
    return [suggestion, publish];
};
//# sourceMappingURL=SharedAutocompleteContext.js.map