"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.buildFontFace = buildFontFace;
exports.buildPreloadLink = buildPreloadLink;
exports.getCdnPath = getCdnPath;

var _react = require("@emotion/react");

var _startCase = _interopRequireDefault(require("lodash/startCase"));

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

var _jsxRuntime = require("@emotion/react/jsx-runtime");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function getCdnPath(fontFolder, fontFile) {
  if (!CONFIG.cdnURL) {
    throw new Error("\"cdnURL\" has not been set in the node-config files");
  }

  var fontPath = "".concat(CONFIG.cdnURL, "/fonts/ibmplex/v5.1.3/").concat(fontFolder);
  var cdnIndex = fontFile.split('').reduce(function (a, b) {
    return a + b.charCodeAt(0);
  }, 0) % 4;
  return "".concat(fontPath, "/").concat(fontFile).replace('cdn0', "cdn".concat(cdnIndex));
}

function buildPreloadLink(href) {
  return (0, _jsxRuntime.jsx)("link", {
    rel: "preload",
    as: "font",
    crossOrigin: "anonymous",
    href: href
  }, href);
}

function buildFontFace(_ref) {
  var name = _ref.name,
      weight = _ref.weight,
      unicodeRange = _ref.unicodeRange,
      isItalic = _ref.isItalic,
      woff = _ref.woff,
      woff2 = _ref.woff2;
  var unicodeSettings = '';

  if (unicodeRange) {
    unicodeSettings = "unicode-range: ".concat(unicodeRange, ";");
  }

  var weightName = _weights.FontWeight[weight];
  return /*#__PURE__*/(0, _react.css)("@font-face{font-family:'", (0, _startCase.default)(name), "';src:local(\n          '", (0, _startCase.default)(name), " ", "".concat(weightName).concat(isItalic ? ' Italic' : ''), "' ),local('", name, "-", "".concat(weightName).concat(isItalic ? 'Italic' : ''), "'),url('", woff2, "') format('woff2'),url('", woff, "') format('woff');font-display:swap;font-style:", isItalic ? 'italic' : 'normal', ";font-weight:", weight, ";", unicodeSettings, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label:buildFontFace;"));
}
