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

import styles from "./blocks.module.css"

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

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

  return (
    <section className={styles.wrapper}>
      {blocks.map((block) => {
        const type = block.__typename
        switch (type) {
          case BlocksTypenameEnum.CurrentBlocksPageBlocksList:
            return <List 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
        }
      })}
      <div id="mainarea_personalized"></div>
    </section>
  )
}
