import { NodeAnnotationTypeEnum } from '../annotations/node-annotation.abstract';
/**
 * Predicate class provides static methods to check specific conditions on HTML elements or dto instances.
 */
export class Predicate {
  /**
   * Checks if the given class name corresponds to a text block.
   *
   * @param {string} className The class name to check.
   * @returns {boolean} True if the class name corresponds to a text block, false otherwise.
   */
  static isTextBlock(className) {
    return className === this.RTE_TEXT_BLOCK_CLASS_NAME;
  }
  /**
   * Checks if the given class name corresponds to a code block.
   *
   * @param {string} className The class name to check.
   * @returns {boolean} True if the class name corresponds to a code block, false otherwise.
   */
  static isCodeBlock(className) {
    return className === 'RTECodeBlock';
  }
  /**
   * Checks if the given class name corresponds to a list block.
   *
   * @param {string} className The class name to check.
   * @returns {boolean} True if the class name corresponds to a list block, false otherwise.
   */
  static isListBlock(className) {
    return className === 'RTEListBlock';
  }
  /**
   * Checks if the given class name corresponds to a list item block.
   *
   * @param {string} className The class name to check.
   * @returns {boolean} True if the class name corresponds to a list item block, false otherwise.
   */
  static isListItemBlock(className) {
    return className === 'RTEListItemBlock';
  }
  /**
   * Checks if the given class name corresponds to a text node.
   *
   * @param {string} className The class name to check.
   * @returns {boolean} True if the class name corresponds to a text node, false otherwise.
   */
  static isTextNode(className) {
    return className === this.RTE_TEXT_NODE_CLASS_NAME;
  }
  /**
   * Checks if the given block or node instance is a text node and has a link annotation.
   *
   * @param {RTEBlock | RTENode} blockOrNodeInstance The block or node instance to check.
   * @returns {boolean} True if the block or node instance is a text node and has a link annotation, false otherwise.
   */
  static isLinkNode(blockOrNodeInstance) {
    return (this.isTextNode(blockOrNodeInstance.constructor.name) &&
      !!blockOrNodeInstance.getAnnotationByType(NodeAnnotationTypeEnum.LINK));
  }
  /**
   * Checks if the given block or node instance is a code node, which is defined as a text node that has a code annotation.
   *
   * @param {RTEBlock | RTENode} blockOrNodeInstance The block or node instance to check.
   * @returns {boolean} True if the block or node instance is a code node, false otherwise.
   */
  static isCodeNode(blockOrNodeInstance) {
    if (this.isTextNode(blockOrNodeInstance.constructor.name)) {
      const codeAnnotation = blockOrNodeInstance.getAnnotationByType(NodeAnnotationTypeEnum.CODE);
      return !!codeAnnotation && codeAnnotation.code;
    }
    return false;
  }
  /**
   * Check if the given block or node instance is an image node, which is defined as an instance of RTEImageNode.
   *
   * @param {RTEBlock | RTENode} blockOrNodeInstance The block or node instance to check.
   * @returns {boolean} True if the block or node instance is an image node, false otherwise.
   */
  static isImageNode(blockOrNodeInstance) {
    return blockOrNodeInstance.constructor.name === 'RTEImageNode';
  }
  /**
   * Check if the given block or node instance is a code block node, which is defined as an instance of RTECodeBlockNode.
   *
   * @param {RTEBlock | RTENode} blockOrNodeInstance The block or node instance to check.
   * @returns {boolean} True if the block or node instance is a code block node, false otherwise.
   */
  static isCodeBlockNode(blockOrNodeInstance) {
    return blockOrNodeInstance.constructor.name === 'RTECodeBlockNode';
  }
}
Predicate.RTE_TEXT_NODE_CLASS_NAME = 'RTETextNode';
Predicate.RTE_TEXT_BLOCK_CLASS_NAME = 'RTETextBlock';
