import { findParent } from '../../../../utils/ui';
import { RTENode } from './node.abstract';
/**
 * Abstract class for decorator nodes. A decorator node modifies content like an image node that will delete the whole node when the delete button is pressed.
 */
export class RTEDecoratorNode extends RTENode {
  constructor() {
    super(...arguments);
    this.type = 'decorator-node';
    this.isSelected = false;
  }
  /**
   * Check the element is a decorator node container.
   *
   * @param {HTMLElement} element - The checked element.
   * @returns {boolean} - The result of the check.
   */
  static isDecoratorNodeContainerElement(element) {
    return element && element.classList.contains(RTEDecoratorNode.DECORATOR_CONTAINER_CLASS);
  }
  /**
   * Get the decorator node element within the container.
   *
   * @param {HTMLElement} container - The container element.
   * @returns {Nullable<HTMLElement>} - The decorator node element, if found.
   */
  static getDecoratorNodeElement(container) {
    return container.querySelector(`.${RTEDecoratorNode.DECORATOR_NODE_CLASS}`);
  }
  /**
   * @inheritDoc
   */
  getRangeEndOffset() {
    return 1;
  }
  /**
   * @inheritDoc
   */
  getRangeContainer() {
    const element = this.getElementRef();
    if (element) {
      return findParent(element, `.${RTEDecoratorNode.DECORATOR_CONTAINER_CLASS}`);
    }
  }
  /**
   * The decorator node is not content editable from the outside.
   *
   * @returns {boolean} - Always returns false for decorator nodes.
   */
  isContentEditable() {
    return false;
  }
}
// CSS class names for the decorator node parent element
RTEDecoratorNode.DECORATOR_CONTAINER_CLASS = 'v-internal-decorator-container';
// CSS class names for the decorator node element
RTEDecoratorNode.DECORATOR_NODE_CLASS = 'v-internal-decorator-node';
