import { RichTextBlock } from "./RichTextBlock";
import { ImageWithTextBlock } from "./ImageWithTextBlock";
import { ImageSliderBlock } from "./ImageSliderBlock";
import { HorizontalRuleBlock } from "./HorizontalRuleBlock";
import { FeaturedBlock } from "./FeaturedBlock";
import { AccordionBlock } from "./AccordionBlock";
import { EmbedBlock } from "./EmbedBlock";
import { FactBoxBlock } from "./FactBoxBlock";
import { PageSectionBlock, PageSectionNavigationBlock } from "./PageSection";
import { ContactSectionBlock, ContactSubsectionBlock } from "./ContactSection";
import { ContactListBlock } from "./ContactListBlock";
import { ContactEntityBlock } from "./ContactEntityBlock";
import { NeufAddressSectionBlock } from "./NeufAddressSectionBlock";
import { OpeningHoursSectionBlock } from "./OpeningHoursSectionBlock";

export const Blocks = ({ blocks, pageContent }: { blocks: any, pageContent?: boolean }) => {
  const sections = blocks.filter(
    (block: any) => block?.__typename === "PageSectionBlock"
  );

  return blocks.map((block: any) => {
    switch (block?.blockType) {
      case "RichTextBlock":
        return <RichTextBlock key={block.id} block={block} />;
        break;
      case "ImageWithTextBlock":
        return <ImageWithTextBlock key={block.id} block={block} />;
        break;
        case "EmbedBlock":
          return <EmbedBlock key={block.id} block={block} />;
          break;
      case "ImageSliderBlock":
        return <ImageSliderBlock key={block.id} block={block} pageContent />;
        break;
      case "HorizontalRuleBlock":
        return <HorizontalRuleBlock key={block.id} block={block} />;
        break;
      case "FeaturedBlock":
        return <FeaturedBlock key={block.id} block={block} />;
        break;
      case "AccordionBlock":
        return <AccordionBlock key={block.id} block={block} />;
        break;
      case "FactBoxBlock":
        return <FactBoxBlock key={block.id} block={block} />;
        break;
      case "PageSectionBlock":
        return <PageSectionBlock key={block.id} block={block} />;
        break;
      case "PageSectionNavigationBlock":
        return <PageSectionNavigationBlock sections={sections} />;
        break;
      case "ContactSectionBlock":
        return <ContactSectionBlock key={block.id} block={block} />;
        break;
      case "ContactSubsectionBlock":
        return <ContactSubsectionBlock key={block.id} block={block} />;
        break;
      case "ContactListBlock":
        return <ContactListBlock key={block.id} block={block} />;
        break;
      case "ContactEntityBlock":
        return <ContactEntityBlock key={block.id} block={block} />;
        break;
      case "NeufAddressSectionBlock":
        return <NeufAddressSectionBlock />;
        break;
      case "OpeningHoursSectionBlock":
        return <OpeningHoursSectionBlock />;
        break;
      default:
        console.log("unsupported block", block);
        return <div>Unsupported block type {block?.blockType}</div>;
    }
  });
};
