'use client';

import React from 'react';
import TextRenderer from './TextRenderer';
import SectionBlock from './SectionBlock';
import ActionsBlock from './ActionsBlock';
import DividerBlock from './DividerBlock';
import ImageBlock from './ImageBlock';
import ContextBlock from './ContextBlock';
import HeaderBlock from './HeaderBlock';

export interface Block {
  type: string;
  text?: { type: string; text: string };
  elements?: any[];
  fields?: { type: string; text: string }[];
  accessory?: any;
  image_url?: string;
  alt_text?: string;
  title?: { type: string; text: string };
}

interface BlockRendererProps {
  blocks: Block[];
  context?: { channelId: string; messageId: string };
}

export default function BlockRenderer({ blocks, context }: BlockRendererProps) {
  return (
    <div className="space-y-1">
      {blocks.map((block, index) => {
        switch (block.type) {
          case 'section':
            return <SectionBlock key={index} block={block} context={context} />;
          case 'divider':
            return <DividerBlock key={index} />;
          case 'image':
            return <ImageBlock key={index} block={block} />;
          case 'actions':
            return <ActionsBlock key={index} block={block} context={context} />;
          case 'context':
            return <ContextBlock key={index} block={block} />;
          case 'header':
            return <HeaderBlock key={index} block={block} />;
          default:
            console.warn(`Unknown block type: ${block.type}`);
            return null;
        }
      })}
    </div>
  );
}