import { LightModeBorderTokens } from '../../../constants/tokens/themes/v2-new-brand/light-mode-border-tokens';
import { LightModeShadowTokens } from '../../../constants/tokens/themes/v2-new-brand/light-mode-shadow-tokens';
import { LightModeColorTokens } from '../../../constants/tokens/themes/v2-new-brand/light-mode-color-tokens';
import { Observer } from '../../change-manager/observer/observer';
import ChangeManager from '../../change-manager/change-manager';
import { DARK_MODE_CHANGE, GP_BRAND_CHANGE, } from '../../change-manager/subject/static-subject/static-subject-title';
import { VegaInternalThemeManager } from '../internal-theme-manager';
import { StyleControllerAbstract } from './style-controller.abstract';
import { htmlSanitizer, styleSanitizeStrategy } from '../../../utils/sanitize';
/**
 * Vega components brand style controller
 */
class BrandStyleController extends StyleControllerAbstract {
  constructor() {
    super();
    this.tokens = {};
    this.themeStyleContainerKey = 'vega-brand-theme';
    this.observer = new Observer(this.isAcceptObserver.bind(this), (options) => {
      if (options === 'heartland') {
        this.reset(this.themeStyleContainerKey);
      }
      else {
        this.generateThemeStyle();
      }
      const isDarkMode = VegaInternalThemeManager.isDarkMode();
      if (isDarkMode) {
        ChangeManager.notify(DARK_MODE_CHANGE, isDarkMode);
      }
    });
    ChangeManager.register(GP_BRAND_CHANGE, this.observer);
  }
  /**
   * It generates a CSS style for light mode to override the style.
   */
  generateThemeStyle() {
    this.tokens = Object.assign(LightModeColorTokens, LightModeBorderTokens, LightModeShadowTokens);
    const keys = Object.keys(this.tokens);
    const styleString = `
:root {
\t\t${keys.map((key) => `--v-${key}: ${this.tokens[key]};`).join('\n\t\t')}}`;
    this.getStyleContainer(this.themeStyleContainerKey).innerHTML = htmlSanitizer.sanitize(styleString, styleSanitizeStrategy);
  }
  /**
   * Determines whether the observer should accept changes.
   *
   * @returns {boolean} Always returns true in the current implementation.
   */
  isAcceptObserver() {
    return true;
  }
}
export const VegaBrandStyleController = new BrandStyleController();
