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 block={block} />;
        break;
      case "ImageWithTextBlock":
        return <ImageWithTextBlock block={block} />;
        break;
        case "EmbedBlock":
          return <EmbedBlock block={block} />;
          break;
      case "ImageSliderBlock":
        return <ImageSliderBlock block={block} pageContent />;
        break;
      case "HorizontalRuleBlock":
        return <HorizontalRuleBlock block={block} />;
        break;
      case "FeaturedBlock":
        return <FeaturedBlock block={block} />;
        break;
      case "AccordionBlock":
        return <AccordionBlock block={block} />;
        break;
      case "FactBoxBlock":
        return <FactBoxBlock block={block} />;
        break;
      case "PageSectionBlock":
        return <PageSectionBlock block={block} />;
        break;
      case "PageSectionNavigationBlock":
        return <PageSectionNavigationBlock sections={sections} />;
        break;
      case "ContactSectionBlock":
        return <ContactSectionBlock block={block} />;
        break;
      case "ContactSubsectionBlock":
        return <ContactSubsectionBlock block={block} />;
        break;
      case "ContactListBlock":
        return <ContactListBlock block={block} />;
        break;
      case "ContactEntityBlock":
        return <ContactEntityBlock 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>;
    }
  });
};
