import { themeType, themesType } from './theme.types' // Must be relative as doing publish

import __themes from './themes.json' // Must be relative as doing publish

const _default = __themes.blue as themeType

const themes: themesType = __themes

export default function (theme?: string | undefined, appendTo: HTMLElement = document.documentElement): void {
  let currentTheme = _default

  if (theme && themes[theme]) {
    currentTheme = themes[theme]
  }

  Object.entries(currentTheme).forEach(([variableName, variableValue]) => {
    appendTo.style.setProperty(`--${variableName}`, variableValue)
  })
}
