(function () {
  function applyThemeColors(colors) {
    if (!colors || typeof colors !== 'object') {
      return;
    }

    var root = document.documentElement;
    var map = {
      page_bg_start: '--wcmv-color-page-bg-start',
      page_bg_end: '--wcmv-color-page-bg-end',
      card_bg: '--wcmv-color-card-bg',
      card_border: '--wcmv-color-card-border',
      heading_text: '--wcmv-color-heading',
      body_text: '--wcmv-color-body',
      muted_text: '--wcmv-color-muted',
      button_start: '--wcmv-color-button-start',
      button_end: '--wcmv-color-button-end',
      success: '--wcmv-color-success',
      info: '--wcmv-color-info',
      danger: '--wcmv-color-danger',
      badge_bg: '--wcmv-color-badge',
    };

    Object.keys(map).forEach(function (key) {
      if (typeof colors[key] === 'string' && colors[key]) {
        root.style.setProperty(map[key], colors[key]);
      }
    });
  }

  document.addEventListener('DOMContentLoaded', function () {
    var themeColorsCfg =
      (typeof STAKMV_THEME_COLORS !== 'undefined' && STAKMV_THEME_COLORS) ? STAKMV_THEME_COLORS :
      ((typeof STAKMV_THEME_COLORS !== 'undefined' && STAKMV_THEME_COLORS) ? STAKMV_THEME_COLORS : null);

    if (themeColorsCfg && themeColorsCfg.colors) {
      applyThemeColors(themeColorsCfg.colors);
    }
  });
})();
