import JsonToHtml from "@/components/JsonToHtml"

import JoinLoyaltyContact from "./JoinLoyalty"

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

import { SidebarTypenameEnum } from "@/types/components/loyalty/enums"
import { SidebarProps } from "@/types/components/loyalty/sidebar"

export default function SidebarLoyalty({ blocks, lang }: SidebarProps) {
  return (
    <aside className={styles.aside}>
      {blocks.map((block) => {
        switch (block.__typename) {
          case SidebarTypenameEnum.LoyaltyPageSidebarContent:
            return (
              <section className={styles.content}>
                <JsonToHtml
                  embeds={block.content.content.embedded_itemsConnection.edges}
                  nodes={block.content.content.json.children}
                />
              </section>
            )
          case SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact:
            return (
              <JoinLoyaltyContact
                block={block.join_loyalty_contact}
                lang={lang}
              />
            )
          default:
            return null
        }
      })}
    </aside>
  )
}
