'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-22fd9091.js');
const makeTheme = require('./makeTheme-57745705.js');

const Theme = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.theme = null;
  }
  async componentWillRender() {
    if (this.theme) {
      const userConfig = typeof this.theme === "string" ? JSON.parse(this.theme) : this.theme;
      const userTheme = makeTheme.makeTheme(userConfig);
      const existingTag = document.querySelectorAll("head style#corejam-user-style");
      if (userTheme.length > 0) {
        if (existingTag.length > 0) {
          existingTag[0].innerHTML = `
            :root {
              ${userTheme}
            }
          `;
        }
        else {
          const style = document.createElement("style");
          style.id = "corejam-user-style";
          style.innerHTML = `
          :root {
            ${userTheme}
          }
        `;
          document.head.appendChild(style);
        }
      }
    }
  }
};

exports.corejam_ui_theme = Theme;
