'use strict';

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

const index = require('./index-e0159b94.js');
const makeTheme = require('./makeTheme-56a2f503.js');

const ThemeProvider = 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);
        }
      }
    }
  }
  render() {
    return index.h(index.Host, null);
  }
};

exports.corejam_ui_theme = ThemeProvider;
