"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getLocale = void 0;
var _locale = require("@mirai/locale");
var _themeDirection = require("./themeDirection");
const DEFAULT_APP_LOCALE = 'en-GB';
const DELIMITER = '-';
const getLocale = function () {
  var _document, _document$documentEle, _document$documentEle2, _window$navigator$lan, _instance$locale;
  let instance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  let {
    lang: urlLanguage
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  const [documentLanguage] = ((_document = document) === null || _document === void 0 ? void 0 : (_document$documentEle = _document.documentElement) === null || _document$documentEle === void 0 ? void 0 : (_document$documentEle2 = _document$documentEle.getAttribute('lang')) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.toLowerCase().split(DELIMITER)) || [];
  const [navigatorLanguage, navigatorCountry] = typeof window.navigator.language === 'string' && ((_window$navigator$lan = window.navigator.language) === null || _window$navigator$lan === void 0 ? void 0 : _window$navigator$lan.split(DELIMITER)) || [];
  const [instanceLanguage, instanceCountry] = !urlLanguage ? ((_instance$locale = instance.locale) === null || _instance$locale === void 0 ? void 0 : _instance$locale.split(DELIMITER)) || [] : [];
  const baseLanguage = urlLanguage || documentLanguage || instanceLanguage || navigatorLanguage;
  const baseCountry = instanceCountry || (baseLanguage === navigatorLanguage ? navigatorCountry : undefined) || _locale.COUNTRIES[baseLanguage];
  const [language, country] = _locale.COUNTRIES[baseLanguage] ? [baseLanguage, baseCountry] : DEFAULT_APP_LOCALE.split(DELIMITER);
  (0, _themeDirection.themeDirection)(language);
  return {
    // ! TODO: country should be the ip.country
    country,
    language,
    locale: [language, country].join('-')
  };
};
exports.getLocale = getLocale;
//# sourceMappingURL=getLocale.js.map