/**
 * List-view body composer for ReactAppStarter (Phase 3)
 *
 * Now a thin wrapper around the pattern walker. The 'what a list
 * view looks like' knowledge lives in the pattern registry (section
 * content declarations) + section resolvers in
 * `@specverse/runtime/views/core/section-resolvers/`. This composer
 * just calls `walkPattern('list-view', context)` and emits the
 * resulting RenderNode tree as JSX source.
 *
 * Notice the shape: no column inference, no row-iteration JSX, no
 * header rendering in this file. That logic now lives in the walker
 * where app-demo and ReactAppRuntime can use it too.
 *
 * This is the first of four composers migrated to the walker path.
 * detail, form, dashboard follow the same shape.
 */

import { walkPattern } from '@specverse/runtime/views/core';
import type { EmitContext } from './view-emitter.js';
import { emitJsxSource } from './emit-jsx-source.js';

export function composeListBody(context: EmitContext): string {
  // The walker returns a rendering-agnostic RenderNode tree. The
  // imports set collects any capitalised composite components the
  // tree references — view-emitter injects them at the top of the
  // generated .tsx file. For list views today the tree is all
  // lowercase HTML tags, so imports is typically empty.
  const imports = new Set<string>();
  const nodes = walkPattern('list-view', {
    model: context.model,
    modelSchemas: context.modelSchemas as any,
    view: context.view,
  });

  return emitJsxSource(nodes, { imports, indent: 6 });
}
