import { Annotation } from './annotation.abstract';
import { CustomAttributeAnnotation } from './custom-attribute-annotation';
import { NodeAnnotationTypeEnum } from './node-annotation.abstract';
import { CustomClassAnnotation } from './custom-class-annotation';
import { CustomStyleAnnotation } from './custom-style-annotation';
import { cleanObject } from '../../../../utils/object';
/**
 * Inline HTML annotation
 */
export class InlineHtmlAnnotation extends Annotation {
  constructor(htmlTag) {
    super();
    this.type = NodeAnnotationTypeEnum.INLINE_HTML;
    this.htmlTag = htmlTag;
  }
  /**
   * Generate the map item for the annotation
   *
   * @param {VegaInlineHtmlSchema} inlineHtml - Inline HTML node
   * @returns {[NodeAnnotationTypeEnum.INLINE_HTML, InlineHtmlAnnotation]} Map item for the annotation
   */
  static from(inlineHtml) {
    const { htmlTag, child, customStyle, customClass, customAttribute } = inlineHtml;
    const inlineHtmlAnnotation = new InlineHtmlAnnotation(htmlTag);
    inlineHtmlAnnotation.groupId = inlineHtml.groupId;
    inlineHtmlAnnotation.child = child ? InlineHtmlAnnotation.from(child)[1] : undefined;
    inlineHtmlAnnotation.customAttribute = customAttribute
      ? CustomAttributeAnnotation.from(customAttribute)[1]
      : undefined;
    inlineHtmlAnnotation.customClass = customClass
      ? CustomClassAnnotation.from(customClass)[1]
      : undefined;
    inlineHtmlAnnotation.customStyle = customStyle
      ? CustomStyleAnnotation.from(customStyle)[1]
      : undefined;
    return [NodeAnnotationTypeEnum.INLINE_HTML, inlineHtmlAnnotation];
  }
  /**
   * Create a new inline HTML annotation
   *
   * @returns {InlineHtmlAnnotation} - Inline HTML annotation
   */
  clone() {
    var _a, _b, _c, _d;
    const inlineHtmlAnnotation = new InlineHtmlAnnotation(this.htmlTag);
    inlineHtmlAnnotation.groupId = this.groupId;
    inlineHtmlAnnotation.child = (_a = this.child) === null || _a === void 0 ? void 0 : _a.clone();
    inlineHtmlAnnotation.customAttribute = (_b = this.customAttribute) === null || _b === void 0 ? void 0 : _b.clone();
    inlineHtmlAnnotation.customClass = (_c = this.customClass) === null || _c === void 0 ? void 0 : _c.clone();
    inlineHtmlAnnotation.customStyle = (_d = this.customStyle) === null || _d === void 0 ? void 0 : _d.clone();
    return inlineHtmlAnnotation;
  }
  /**
   * Build the props object used when rendering this annotation.
   *
   * @returns {Record<string, unknown>} Props for h(tag, props, children).
   */
  renderProps() {
    var _a, _b, _c;
    return Object.assign(Object.assign({}, (_a = this.customAttribute) === null || _a === void 0 ? void 0 : _a.render()), { style: (_b = this.customStyle) === null || _b === void 0 ? void 0 : _b.renderStyle(), class: (_c = this.customClass) === null || _c === void 0 ? void 0 : _c.renderClass().join(' ') });
  }
  /**
   * Generate the JSON representation of the annotation
   *
   * @returns {Record<string, unknown>} JSON representation of the annotation
   */
  toJSON() {
    var _a, _b, _c, _d;
    return {
      inlineHtml: cleanObject({
        htmlTag: this.htmlTag,
        groupId: this.groupId,
        child: (_a = this.child) === null || _a === void 0 ? void 0 : _a.toJSON().inlineHtml,
        customAttribute: (_b = this.customAttribute) === null || _b === void 0 ? void 0 : _b.toJSON().customAttribute,
        customClass: (_c = this.customClass) === null || _c === void 0 ? void 0 : _c.toJSON().customClass,
        customStyle: (_d = this.customStyle) === null || _d === void 0 ? void 0 : _d.toJSON().customStyle,
      }),
    };
  }
}
