"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const event = require("../../../../base/common/event.js");
const lifecycle = require("../../../../base/common/lifecycle.js");
const range = require("../../core/range.js");
const editorColorRegistry = require("../../core/editorColorRegistry.js");
const themeService = require("../../../../platform/theme/common/themeService.js");
class ColorizedBracketPairsDecorationProvider extends lifecycle.Disposable {
  constructor(textModel) {
    super();
    this.textModel = textModel;
    this.colorProvider = new ColorProvider();
    this.onDidChangeEmitter = new event.Emitter();
    this.onDidChange = this.onDidChangeEmitter.event;
    this.colorizationOptions = textModel.getOptions().bracketPairColorizationOptions;
    this._register(textModel.bracketPairs.onDidChange((e) => {
      this.onDidChangeEmitter.fire();
    }));
  }
  //#region TextModel events
  handleDidChangeOptions(e) {
    this.colorizationOptions = this.textModel.getOptions().bracketPairColorizationOptions;
  }
  //#endregion
  getDecorationsInRange(range2, ownerId, filterOutValidation) {
    if (ownerId === void 0) {
      return [];
    }
    if (!this.colorizationOptions.enabled) {
      return [];
    }
    const result = new Array();
    const bracketsInRange = this.textModel.bracketPairs.getBracketsInRange(range2);
    for (const bracket of bracketsInRange) {
      result.push({
        id: `bracket${bracket.range.toString()}-${bracket.nestingLevel}`,
        options: { description: "BracketPairColorization", inlineClassName: this.colorProvider.getInlineClassName(bracket) },
        ownerId: 0,
        range: bracket.range
      });
    }
    return result;
  }
  getAllDecorations(ownerId, filterOutValidation) {
    if (ownerId === void 0) {
      return [];
    }
    if (!this.colorizationOptions.enabled) {
      return [];
    }
    return this.getDecorationsInRange(new range.Range(1, 1, this.textModel.getLineCount(), 1), ownerId, filterOutValidation);
  }
}
class ColorProvider {
  constructor() {
    this.unexpectedClosingBracketClassName = "unexpected-closing-bracket";
  }
  getInlineClassName(bracket) {
    if (bracket.isInvalid) {
      return this.unexpectedClosingBracketClassName;
    }
    return this.getInlineClassNameOfLevel(bracket.nestingLevel);
  }
  getInlineClassNameOfLevel(level) {
    return `bracket-highlighting-${level % 30}`;
  }
}
themeService.registerThemingParticipant((theme, collector) => {
  const colors = [
    editorColorRegistry.editorBracketHighlightingForeground1,
    editorColorRegistry.editorBracketHighlightingForeground2,
    editorColorRegistry.editorBracketHighlightingForeground3,
    editorColorRegistry.editorBracketHighlightingForeground4,
    editorColorRegistry.editorBracketHighlightingForeground5,
    editorColorRegistry.editorBracketHighlightingForeground6
  ];
  const colorProvider = new ColorProvider();
  collector.addRule(`.monaco-editor .${colorProvider.unexpectedClosingBracketClassName} { color: ${theme.getColor(editorColorRegistry.editorBracketHighlightingUnexpectedBracketForeground)}; }`);
  const colorValues = colors.map((c) => theme.getColor(c)).filter((c) => !!c).filter((c) => !c.isTransparent());
  for (let level = 0; level < 30; level++) {
    const color = colorValues[level % colorValues.length];
    collector.addRule(`.monaco-editor .${colorProvider.getInlineClassNameOfLevel(level)} { color: ${color}; }`);
  }
});
exports.ColorizedBracketPairsDecorationProvider = ColorizedBracketPairsDecorationProvider;
