import React from "react";
import type { CMSBlock } from "@/types";

type BlockComponentMap = Partial<
  Record<CMSBlock["blockType"], React.ComponentType<{ data: any }>>
>;

interface Props {
  blocks: CMSBlock[];
  blockComponents: BlockComponentMap;
}

export function RenderBlocks({ blocks, blockComponents }: Props) {
  return (
    <>
      {blocks.map((block, index) => {
        const Block = blockComponents[block.blockType];
        if (!Block) return null;
        return <Block key={index} data={block} />;
      })}
    </>
  );
}
