import { generateUUID } from '../../../../../../utils/misc';
import { RTEImageBlock } from '../../../../dto/blocks/image-block';
import { RTEImageNode } from '../../../../dto/nodes/image-node';
import htmlElementToAnnotationGenerator from './annotation-handler/html-element-to-annotation-generator';
import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
/** Abstract class for block html element to RTE block dto */
export class ElementToRTEImageBlockStrategyAbstract extends BlockToRTEBlockStrategyAbstract {
  /**
   * Create a RTE Image block according to the img element.
   *
   * @param {HTMLElement} element - current element.
   * @param {VegaRTETransformOptions} [options] - Options for transformation.
   * @returns {RTEImageBlock} -RTE Image block.
   */
  createRTEImageBlock(element, options) {
    // RTEImageBlock is also wrapped by a div, should not as internal wrapper if the parent is a div.
    const isInternalWrapper = !(options && options.autoMatchFormat) &&
      !!(element.parentNode && element.parentNode.nodeName !== 'DIV');
    return RTEImageBlock.from({
      id: generateUUID(),
      type: 'image',
      nodes: [
        {
          id: generateUUID(),
          type: 'image',
          url: element.src,
          annotations: htmlElementToAnnotationGenerator.generate(RTEImageNode, element, options),
        },
      ],
      annotations: Object.assign(Object.assign({}, htmlElementToAnnotationGenerator.generate(RTEImageBlock, element.parentElement, options)), { internalWrapper: isInternalWrapper }),
    }, options);
  }
}
