import { renderLeaf } from "../render-leaf";
import { BlockTreeNode } from "../block-tree";
import { RenderContext } from "../render-context";

/**
 * table / form / embed / calendar blocks are TERMINAL (see block-types.ts):
 * the segmenter never descends into them, and their sole owned leaf is
 * exactly the pre-existing `table`/`form`/… ReaderObject already built by
 * explore-table/form-helper — so rendering is just `renderLeaf` on that one
 * leaf, wrapped in a labelled `<section>` for a bit of context.
 */
export function renderPassthrough(block: BlockTreeNode, ctx: RenderContext, parent: HTMLElement): void {
  const leaves = ctx.leavesOf(block);
  if (leaves.length === 0) return;
  const section = document.createElement("section");
  if (block.n != undefined) {
    const heading = document.createElement("h2");
    heading.textContent = block.n;
    section.append(heading);
  }
  for (const leaf of leaves) {
    renderLeaf(leaf, section, ctx.calendarLang);
  }
  if (section.childNodes.length > 0) parent.append(section);
}
