"use client"
import { useRouter } from "next/navigation"

import { renderOptions as currentRenderOptions } from "@/components/Current/currentRenderOptions"
import DeprecatedJsonToHtml from "@/components/DeprecatedJsonToHtml"
import Image from "@/components/Image"
import Button from "@/components/TempDesignSystem/Button"

import { renderOptions } from "./renderOptions"

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

import type { PuffProps } from "@/types/components/current/asides/puff"
import { PuffStyleEnum } from "@/types/requests/puff"

export default function Puff({
  imageConnection,
  link,
  text,
  puff_style,
  title,
}: PuffProps) {
  const router = useRouter()

  switch (puff_style) {
    case PuffStyleEnum.button:
      function onClick() {
        router.push(link.href)
      }

      return (
        <article>
          {imageConnection.edges.map((image) => (
            <Image
              alt={image.node.title}
              className={styles.image}
              height={image.node.dimension.height}
              key={image.node.system.uid}
              src={image.node.url}
              width={image.node.dimension.width}
            />
          ))}
          <section className={styles.content}>
            <DeprecatedJsonToHtml
              embeds={[]}
              nodes={text.json.children}
              renderOptions={{ ...currentRenderOptions, ...renderOptions }}
            />
            <div>
              <Button onPress={onClick}>{link.title || title}</Button>
            </div>
          </section>
        </article>
      )
    case PuffStyleEnum.default:
      return (
        <a className={styles.link} href={link.href}>
          <article>
            {imageConnection.edges.map((image) => (
              <Image
                alt={image.node.title}
                className={styles.image}
                height={image.node.dimension.height}
                key={image.node.system.uid}
                src={image.node.url}
                width={image.node.dimension.width}
              />
            ))}
            <section className={styles.content}>
              <header>
                <h3 className={styles.heading}>{title}</h3>
              </header>
              <DeprecatedJsonToHtml
                embeds={[]}
                nodes={text.json.children}
                renderOptions={{ ...currentRenderOptions, ...renderOptions }}
              />
            </section>
          </article>
        </a>
      )
  }
}
