import { NodeAnnotation, NodeAnnotationTypeEnum } from './node-annotation.abstract';
import { isNonNullable } from '../../../../types/type-guard';
/**
 * Annotation for image
 */
export class ImageAnnotation extends NodeAnnotation {
  constructor(size, alt) {
    super();
    this.type = NodeAnnotationTypeEnum.IMAGE;
    this.size = size;
    this.alt = alt;
  }
  /**
   * Generate the map item for the annotation
   *
   * @param {string} size - Image size
   * @param {string} alt - Image alt
   * @returns {[NodeAnnotationTypeEnum.IMAGE, ImageAnnotation]} Map item for the annotation
   */
  static from(size, alt) {
    return [NodeAnnotationTypeEnum.IMAGE, new ImageAnnotation(size, alt)];
  }
  /**
   * Get the default standalone base styles for an image node.
   *
   * @returns {AnnotationStyle} The default styles.
   */
  static getDefaultStyles() {
    return {
      verticalAlign: 'bottom',
    };
  }
  /**
   * Generate the JSON representation of the annotation
   *
   * @returns {Nullable<Record<string, unknown>>} JSON representation of the annotation
   */
  toJSON() {
    return isNonNullable(this.alt)
      ? {
        size: this.size,
        alt: this.alt,
      }
      : {
        size: this.size,
      };
  }
  /**
   * @inheritDoc
   */
  clone() {
    return new ImageAnnotation(this.size, this.alt);
  }
  /**
   * @inheritDoc
   */
  renderClass(options) {
    if (options === null || options === void 0 ? void 0 : options.standalone)
      return null;
    return this.size ? `v-rte--image-size-${this.size}` : null;
  }
  /**
   * @inheritDoc
   */
  renderStyle(options) {
    if (!(options === null || options === void 0 ? void 0 : options.standalone))
      return null;
    const baseStyle = ImageAnnotation.getDefaultStyles();
    switch (this.size) {
      case 'sm': {
        return Object.assign(Object.assign({}, baseStyle), { width: '25%' });
      }
      case 'md': {
        return Object.assign(Object.assign({}, baseStyle), { width: '50%' });
      }
      case 'lg': {
        return Object.assign(Object.assign({}, baseStyle), { width: '100%' });
      }
    }
  }
}
ImageAnnotation.BASE_STYLES = { verticalAlign: 'bottom' };
