import { useRef } from 'react';
import { locales } from '@pisell/utils';
import useEngineContext from "./useEngineContext";
var DEFAULT_LOCALE = 'en';
var useInitLocalesOnce = function useInitLocalesOnce(localeTexts) {
  var _context$appHelper, _context$engine;
  var fallbackLocale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LOCALE;
  if (!localeTexts) return;
  var initializedRef = useRef(false);
  if (initializedRef.current) return;
  var context = useEngineContext();
  var _locale = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.storage) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.get('umi_locale')) || (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || fallbackLocale;
  locales.init(localeTexts, _locale);
  initializedRef.current = true;
};
export default useInitLocalesOnce;