import { StandardAutoClosingPairConditional } from "../languageConfiguration.mjs";
class CharacterPairSupport {
  constructor(config) {
    if (config.autoClosingPairs) {
      this._autoClosingPairs = config.autoClosingPairs.map((el) => new StandardAutoClosingPairConditional(el));
    } else if (config.brackets) {
      this._autoClosingPairs = config.brackets.map((b) => new StandardAutoClosingPairConditional({ open: b[0], close: b[1] }));
    } else {
      this._autoClosingPairs = [];
    }
    if (config.colorizedBracketPairs) {
      this._colorizedBracketPairs = filterValidBrackets(config.colorizedBracketPairs.map((b) => [b[0], b[1]]));
    } else if (config.brackets) {
      this._colorizedBracketPairs = filterValidBrackets(config.brackets.map((b) => [b[0], b[1]]).filter((p) => !(p[0] === "<" && p[1] === ">")));
    } else {
      this._colorizedBracketPairs = [];
    }
    if (config.__electricCharacterSupport && config.__electricCharacterSupport.docComment) {
      const docComment = config.__electricCharacterSupport.docComment;
      this._autoClosingPairs.push(new StandardAutoClosingPairConditional({ open: docComment.open, close: docComment.close || "" }));
    }
    this._autoCloseBefore = typeof config.autoCloseBefore === "string" ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED;
    this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs;
  }
  getAutoClosingPairs() {
    return this._autoClosingPairs;
  }
  getAutoCloseBeforeSet() {
    return this._autoCloseBefore;
  }
  getSurroundingPairs() {
    return this._surroundingPairs;
  }
  getColorizedBrackets() {
    return this._colorizedBracketPairs;
  }
}
CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED = ";:.,=}])> \n	";
function filterValidBrackets(bracketPairs) {
  return bracketPairs.filter(([open, close]) => open !== "" && close !== "");
}
export {
  CharacterPairSupport
};
