import { CodeAnnotation } from '../../annotations/code-annotation';
import { RTEFilterStylesStrategy } from '../filter-styles-strategy.abstract';
import { Predicate } from '../predicate';
/**
 * The CodeFilterStylesStrategy is responsible for filtering code styles from text nodes that are annotated as code.
 */
export class CodeFilterStylesStrategy extends RTEFilterStylesStrategy {
  constructor() {
    super(...arguments);
    this.stylesToBeFiltered = CodeAnnotation.getDefaultStyles();
    this.elementTagName = 'code';
  }
  /**
   * Only strips code-default styles when the `code` annotation is present,
   * so that a user-applied `fontFamily: 'Roboto Mono'` without code is preserved.
   *
   * @param {VegaRTEAnnotations} annotations - The annotations object (mutated in place).
   * @returns {VegaRTEAnnotations} The same annotations reference.
   */
  filterAnnotations(annotations) {
    const { code, customStyle } = annotations;
    if (!code || !customStyle) {
      return annotations;
    }
    return super.filterAnnotations(annotations);
  }
  /**
   * Determines whether the dto instance is a code text node.
   *
   * @param {RTEBlock | RTENode} blockOrNodeInstance - The block or node instance to check.
   * @returns {boolean} - True if the instance is a code text node, false otherwise.
   */
  canFilter(blockOrNodeInstance) {
    return Predicate.isCodeNode(blockOrNodeInstance);
  }
  /**
   * Check if the node is a text node and it is a code node.
   *
   * @param {string} blockOrNodeClassName - The class name of the block or node instance to check.
   * @param {HTMLElement} element - The HTML element of the node instance.
   * @returns {boolean} True if the node is a text node it a code element.
   */
  canRefill(blockOrNodeClassName, element) {
    return Predicate.isTextNode(blockOrNodeClassName) && element.matches(this.elementTagName);
  }
  /**
   * The code style in title and heading no need to be bold in default.
   *
   * @returns {string} The CSS text string for code styles.
   */
  toCssText() {
    const selector = `.${RTEFilterStylesStrategy.RTE_CONTENT_CONTAINER_CLASS_NAME} ${this.elementTagName}`;
    return `${selector} { ${this.convertStylesMapToCssText(Object.assign(Object.assign({}, this.stylesToBeFiltered), { fontWeight: '500' }))} }`;
  }
}
