import { VegaThemeManager } from '../../../../../helpers/theme/theme-manager';
import { rgbToHex } from '../../../../../utils/ui';
import { RTE_TABLE_DEFAULT_COLORS, RTE_TABLE_HEAD_DEFAULT_BACKGROUND_COLOR, } from '../constants/styles.constants';
/**
 * Manages table colors for the rich text editor.
 */
export class RTETableColorManager {
  /**
   * Get the list of table colors.
   *
   * @returns {VegaRTEColorSchema[]} - Array of table colors.
   */
  static getTableColors() {
    return RTETableColorManager.TABLE_COLORS;
  }
  /**
   * Set the list of table colors.
   *
   * @param {VegaRTEColorSchema[]} colors - Array of table colors.
   */
  static setTableColors(colors) {
    RTETableColorManager.TABLE_COLORS = colors;
  }
  /**
   * Get color key from color value
   *
   * @param {string} colorValue - color value
   * @param {boolean} isHeadCellColor - whether the color is for a head cell
   * @returns {string} - color key
   */
  static getColorKey(colorValue, isHeadCellColor = false) {
    var _a;
    let result = null;
    const defaultColorList = RTETableColorManager.TABLE_COLORS;
    const tableColors = isHeadCellColor
      ? [...defaultColorList, RTE_TABLE_HEAD_DEFAULT_BACKGROUND_COLOR]
      : defaultColorList;
    if (tableColors) {
      const hexColor = (_a = rgbToHex(colorValue)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
      if (hexColor) {
        result = tableColors.find((schema) => VegaThemeManager.isDarkMode() ? schema.dark === hexColor : schema.light === hexColor);
      }
      else {
        for (const color of tableColors) {
          if (color.key === colorValue) {
            result = color;
            break;
          }
        }
      }
    }
    return result ? result.key : '';
  }
}
RTETableColorManager.TABLE_COLORS = RTE_TABLE_DEFAULT_COLORS;
