"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.theme = void 0;
var _ui = require("@mirai/ui");
var _findDangerousCSSRules = require("./findDangerousCSSRules");
var _helpers = require("../components/helpers");
let cssTheme;
if (!_helpers.IS_JEST) cssTheme = require('bundle-text:../theme.css');
const LEGACY_ACCENT_VARIABLE = '--corporative-color';
const theme = function () {
  let {
    accent = '',
    findDangerousCSS = false
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  // Import css variables from theme.css
  if (cssTheme) {
    const style = document.createElement('style');
    const {
      head
    } = document;
    style.textContent = cssTheme;
    head.insertBefore(style, head.firstChild);
  }

  // Generate accent palette using legacy
  let legacyAccent = getComputedStyle(document.documentElement).getPropertyValue(LEGACY_ACCENT_VARIABLE);
  if (legacyAccent) {
    legacyAccent = legacyAccent.replace(/^"|"$/g, '').trim();
    _ui.Theme.generatePalette('accent', legacyAccent);
  }
  if (accent.length === 6) _ui.Theme.generatePalette('accent', "#".concat(accent));

  // Dangerous CSS rules
  if (findDangerousCSS) {
    const cssRules = (0, _findDangerousCSSRules.findDangerousCSSRules)();
    // eslint-disable-next-line no-console
    if (cssRules.length) console.warn('WARNING: css rules ending with html tags', cssRules);
  }
};
exports.theme = theme;
//# sourceMappingURL=theme.js.map