import '../../../preact/compat/dist/compat.module.mjs';
import { jsx as u } from '../../../preact/jsx-runtime/dist/jsxRuntime.module.mjs';
import { T as TransNoContext } from './shared/react.8970326b.mjs';
import { useContext as q, useRef as _, useCallback as T, useState as h, useEffect as p } from '../../../preact/hooks/dist/hooks.module.mjs';
import { createContext as F } from '../../../preact/dist/preact.module.mjs';

const LinguiContext = F(null);
const useLinguiInternal = (devErrorMessage) => {
  const context = q(LinguiContext);
  return context;
};
function useLingui() {
  return useLinguiInternal();
}
const I18nProvider = ({
  i18n,
  defaultComponent,
  children
}) => {
  const latestKnownLocale = _(i18n.locale);
  const makeContext = T(
    () => ({
      i18n,
      defaultComponent,
      _: i18n.t.bind(i18n)
    }),
    [i18n, defaultComponent]
  );
  const [context, setContext] = h(makeContext());
  p(() => {
    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__ */ u(LinguiContext.Provider, { value: context, children });
};

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

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