'use client';

/** Diff block — thin chat wrapper around the lazy `DiffViewer`. */

import { LazyDiffViewer } from '../../../../dev/code/DiffViewer/lazy';
import type { DiffBlock } from '../../../types/block';
import type { BlockRendererProps } from './types';

export default function DiffBlockRenderer({ block, ctx }: BlockRendererProps<DiffBlock>) {
  // Compact chat is narrow → default to single-column `unified`; full
  // bubbles have room for `split`. A pinned `layout` always wins.
  const layout = block.layout ?? (ctx.appearance === 'compact' ? 'unified' : 'split');
  const common = {
    layout,
    language: block.language,
    // `diff` is a "bare" block (no clipping card) because the viewer draws
    // its own bordered panel + a floating copy button that a clip would
    // crop. So it owns its frame — re-rounded to the shared 2xl radius.
    // `!`-utilities win over the viewer's template-string `rounded-xl`
    // regardless of stylesheet order.
    className: '!rounded-2xl',
  };

  return block.patch !== undefined ? (
    <LazyDiffViewer {...common} patch={block.patch} />
  ) : (
    <LazyDiffViewer {...common} oldCode={block.oldCode ?? ''} newCode={block.newCode ?? ''} />
  );
}
