"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.resolveFontWeights = resolveFontWeights;
exports.getFontFamily = exports.getFont = void 0;

var _plexSans = require("./fonts/plexSans.js");

var _plexSansArabic = require("./fonts/plexSansArabic.js");

var _plexSansThaiLooped = require("./fonts/plexSansThaiLooped.js");

var _weights = require("./fonts/weights.js");

var SUFFIX = '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,"Fira Sans","Droid Sans","Helvetica Neue","Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji",sans-serif,system-ui'; // this should be good for all latin based languages

var PREFIX = '"IBM Plex Sans"';
var CHINESE_FONT_FAMILY = '"Microsoft YaHei UI","Microsoft YaHei New","Microsoft YaHei","微软雅黑","Hiragino Sans GB","冬青黑体简体中文","ヒラギノ角ゴ簡体中文",STXihei,"华文细黑",SimHei,"黑体"';
var JA_FONT_FAMILY = '"Hiragino Kaku Gothic ProN","ヒラギノ角ゴ ProN W3","Yu Gothic UI","Yu Gothic","游ゴシック体",YuGothic,Osaka,"Meiryo UI",Meiryo,メイリオ,"ＭＳ Ｐゴシック","MS PGothic"';
var KO_FONT_FAMILY = '"Apple SD Gothic Neo","애플 SD 산돌고딕 Neo","Malgun Gothic","맑은 고딕",Gulim,"굴림",Dotum';
var AR_COUNTRIES = ['dz', 'bh', 'td', 'km', 'dj', 'eg', 'er', 'iq', 'jo', 'kw', 'lb', 'ly', 'mr', 'ma', 'om', 'ps', 'qa', 'sa', 'so', 'sd', 'sy', 'tz', 'tn', 'ae', 'ye']; // Note about font files
// need to host google fonts by ourselves since China wont have an access to google

function resolveFontWeights(paramFontWeights) {
  if (paramFontWeights && paramFontWeights.length) {
    return paramFontWeights;
  }

  return [_weights.FontWeight.Regular, _weights.FontWeight.Bold, _weights.FontWeight.SemiBold];
}

var getFont = function getFont(casedLocale, casedCountry, paramFontWeights) {
  var fontWeights = resolveFontWeights(paramFontWeights);
  var country = (casedCountry || '').toLowerCase();
  var locale = (casedLocale || '').toLowerCase();

  if (locale === 'th' || country === 'th') {
    return (0, _plexSansThaiLooped.plexSansThaiLoopedFont)(fontWeights);
  }

  if (locale === 'ar' || AR_COUNTRIES.includes(country)) {
    return (0, _plexSansArabic.plexSansArabicFont)(fontWeights);
  }

  return (0, _plexSans.plexSansFont)(fontWeights);
};

exports.getFont = getFont;

function testJa(locale, country) {
  return locale === 'ja' || country === 'jp' && !locale.match(/^zh/gi);
}

var getFontFamily = function getFontFamily(casedLocale, casedCountry) {
  var country = (casedCountry || '').toLowerCase();
  var locale = (casedLocale || '').toLowerCase();
  var fontFamily = "".concat(PREFIX, ",").concat(CHINESE_FONT_FAMILY, ",").concat(SUFFIX);

  if (testJa(locale, country)) {
    fontFamily = "".concat(PREFIX, ",").concat(JA_FONT_FAMILY, ",").concat(SUFFIX);
  } else if (locale === 'ko' || country === 'kr') {
    fontFamily = "".concat(PREFIX, ",").concat(KO_FONT_FAMILY, ",").concat(CHINESE_FONT_FAMILY, ",").concat(SUFFIX);
  } else if (locale === 'th' || country === 'th') {
    fontFamily = "".concat(PREFIX, ",\"IBM Plex Sans Thai Looped\",").concat(CHINESE_FONT_FAMILY, ",").concat(SUFFIX);
  } else if (locale === 'ar' || AR_COUNTRIES.includes(country)) {
    fontFamily = "".concat(PREFIX, ",\"IBM Plex Sans Arabic\",").concat(CHINESE_FONT_FAMILY, ",").concat(SUFFIX);
  }

  return fontFamily;
};

exports.getFontFamily = getFontFamily;
