// Generic Schema.org / JSON-LD renderer — takes one schema object or an
// array of them and emits one <script type="application/ld+json"> per
// entry. Server Component (no interactivity needed), safe to render
// anywhere in the tree. Used by the product detail page to render both the
// auto-generated Product schema and whatever raw schemas an admin entered
// via SchemaEditor.tsx (`product_schemas`, `category_schemas`,
// `page_schemas`, `post_schemas` — same JSON-column pattern across
// entities, so this component isn't product-specific).
interface JsonLdProps {
  data: Record<string, unknown> | Record<string, unknown>[];
}

export default function JsonLd({ data }: JsonLdProps) {
  const items = Array.isArray(data) ? data : [data];

  return (
    <>
      {items.map((item, index) => (
        <script
          key={index}
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(item) }}
        />
      ))}
    </>
  );
}
