import { VegaColorSchemaOverridingController } from './controllers/color-schema-overriding-controller';
import './controllers/dark-mode-style-controller';
import ChangeManager from '../change-manager/change-manager';
import { DARK_MODE_CHANGE, GP_BRAND_CHANGE, } from '../change-manager/subject/static-subject/static-subject-title';
import './controllers/brand-style-controller';
import { emptySanitizeStrategy, htmlSanitizer } from '../../utils/sanitize';
/**
 * Vega components controller to control the internal theme manager
 */
class InternalThemeManager {
  constructor() {
    this.currentBranding = 'heartland';
  }
  /**
   * It takes the colors you passed in, parses them into the correct format, and then applies them to the theme
   *
   * @param {VegaThemeOverrideColors} overrideColors - OverrideColors - This is the object that you pass to the function.
   */
  overrideColors(overrideColors) {
    const overrideThemes = VegaColorSchemaOverridingController.generateOverrideThemes(overrideColors);
    VegaColorSchemaOverridingController.applyTheme(overrideThemes);
  }
  /**
   * It removes all the custom override theme styles from the DOM
   */
  reset() {
    VegaColorSchemaOverridingController.getOverrideThemeContainer().innerHTML = htmlSanitizer.sanitize('', emptySanitizeStrategy);
  }
  /* eslint-disable no-restricted-globals */
  /**
   * This function toggles the dark mode of a webpage by adding or removing a 'dark' class to the HTML element.
   *
   * @param {boolean | undefined} darkMode - A boolean or undefined value that determines whether to enable or disable dark mode.
   * If it is true, dark mode is enabled.
   * If it is false, dark mode is disabled.
   */
  toggleDarkMode(darkMode) {
    if (darkMode) {
      document.documentElement.classList.add('dark');
    }
    else {
      document.documentElement.classList.remove('dark');
    }
    ChangeManager.notify(DARK_MODE_CHANGE, darkMode);
  }
  /* eslint-enable no-restricted-globals */
  /**
   * The function checks if the HTML element has a class of "dark" and returns a boolean value accordingly.
   *
   * @returns {boolean} A boolean value indicating whether the HTML element has a class of "dark", which is
   * typically used to indicate that the website is in dark mode.
   */
  isDarkMode() {
    // eslint-disable-next-line no-restricted-globals
    return document.documentElement.classList.contains('dark');
  }
  /**
   * This function return the new brand name.
   *
   * @returns {BrandOptions} return the new brand options.
   */
  getBranding() {
    return this.currentBranding;
  }
  /**
   * This function switches the Vega theme to a brand theme based on the provided options.
   *
   * @param {BrandOptions} options - The options includes 'gp', 'genius' and 'heartland' options
   */
  applyBranding(options) {
    this.currentBranding = options;
    ChangeManager.notify(GP_BRAND_CHANGE, options);
  }
}
export const VegaInternalThemeManager = new InternalThemeManager();
