import type { ReactElement } from 'react'

/**
 * Embed schema.org JSON-LD structured data.
 *
 * Pair with the generators from `@startsimpli/api/blog`
 * (`createStructuredData(...).article(...)` etc.). Accepts a single object or an
 * array; renders one `<script type="application/ld+json">` per item.
 */
export function JsonLd({ data }: { data: object | object[] }): ReactElement {
  const items = Array.isArray(data) ? data : [data]
  return (
    <>
      {items.map((item, index) => (
        <script
          key={index}
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(item) }}
        />
      ))}
    </>
  )
}
