import { h } from '@stencil/core';
import { RTEBlockTextNodesRenderer } from './block-text-nodes-renderer.abstract';
class RTETextBlockRenderer extends RTEBlockTextNodesRenderer {
  render(block, renderContext) {
    if (block.shouldRenderAsInternalWrapper()) {
      const outerTag = this.getOuterInlineTag(block.children);
      if (outerTag) {
        const OuterTag = outerTag.htmlTag;
        return (h(OuterTag, Object.assign({}, outerTag.annotation.renderProps(), { key: block.id, ref: (ref) => super.registerRef(ref, block) }), super.renderGroupedNodesAtDepth(block.children, 1, renderContext)));
      }
    }
    const BlockTag = block.getBlockTag();
    return (h(BlockTag, Object.assign({}, this.getCustomAttrs(block), { key: block.id, ref: (ref) => super.registerRef(ref, block), style: block.getStyles(), class: block.getClasses() }), super.renderNodes(block, renderContext)));
  }
  /**
   * Returns the promotable inline HTML tag when the block wraps exactly one
   * inline-HTML element (e.g. `<summary>`, `<section>`), or `null` otherwise.
   */
  getOuterInlineTag(children) {
    if (children.length !== 1)
      return null;
    return children[0].getInlineHtmlTagAtDepth(0);
  }
}
export default new RTETextBlockRenderer();
