import { cx } from "class-variance-authority"

import { nodesToHtml } from "./utils"

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

import type { JsonToHtmlProps } from "@/types/transitionTypes/jsontohtml"

export default function JsonToHtml({
  embeds,
  nodes,
  renderOptions = {},
  className,
}: JsonToHtmlProps) {
  if (!Array.isArray(nodes) || !nodes.length) {
    return null
  }

  return (
    <section className={cx(styles.container, className)}>
      {nodesToHtml(nodes, embeds, renderOptions).filter(Boolean)}
    </section>
  )
}
