import List from "./Blocks/List"
import Preamble from "./Blocks/Preamble"
import Puffs from "./Blocks/Puffs"
import Text from "./Blocks/Text"

import { BlocksTypenameEnum } from "@/types/requests/utils/typename"
import type { BlocksProps } from "@/types/components/current/blocks"

export default function Blocks({ blocks }: BlocksProps) {
  if (!blocks?.length) {
    return null
  }

  return (
    <>
      {blocks.map(block => {
        const type = block.__typename
        switch (type) {
          case BlocksTypenameEnum.CurrentBlocksPageBlocksList:
            return <List key={block.__typename} {...block} />
          case BlocksTypenameEnum.CurrentBlocksPageBlocksPreamble:
            return <Preamble key={block.__typename} {...block} />
          case BlocksTypenameEnum.CurrentBlocksPageBlocksPuffs:
            return <Puffs key={block.__typename} {...block} />
          case BlocksTypenameEnum.CurrentBlocksPageBlocksText:
            return <Text key={block.__typename} {...block} />
          default:
            console.log(`Unknown type: (${type})`)
            return null
        }
      })}
    </>
  )
}
