'use client';
import { jsx } from 'react/jsx-runtime';
import { useContext, createContext, useRef, useCallback, useState, useEffect } from 'react';
import { T as TransNoContext } from './shared/react.8970326b.mjs';

const LinguiContext = createContext(null);
const useLinguiInternal = (devErrorMessage) => {
  const context = useContext(LinguiContext);
  return context;
};
function useLingui() {
  return useLinguiInternal();
}
const I18nProvider = ({
  i18n,
  defaultComponent,
  children
}) => {
  const latestKnownLocale = useRef(i18n.locale);
  const makeContext = useCallback(
    () => ({
      i18n,
      defaultComponent,
      _: i18n.t.bind(i18n)
    }),
    [i18n, defaultComponent]
  );
  const [context, setContext] = useState(makeContext());
  useEffect(() => {
    const updateContext = () => {
      latestKnownLocale.current = i18n.locale;
      setContext(makeContext());
    };
    const unsubscribe = i18n.on("change", updateContext);
    if (latestKnownLocale.current !== i18n.locale) {
      updateContext();
    }
    return unsubscribe;
  }, [i18n, makeContext]);
  if (!latestKnownLocale.current) {
    return null;
  }
  return /* @__PURE__ */ jsx(LinguiContext.Provider, { value: context, children });
};

function Trans(props) {
  const lingui = useLinguiInternal();
  return /* @__PURE__ */ jsx(TransNoContext, { ...props, lingui });
}

export { I18nProvider, LinguiContext, Trans, useLingui };
//# sourceMappingURL=index.mjs.map
