import { SchemaType } from '@/lib/seo/schema/types';

interface JsonLdProps {
  data: SchemaType | SchemaType[];
}

/**
 * Server-safe JSON-LD schema component
 * Renders directly to HTML for SSR (no client-side JS needed)
 * 
 * @param data - Single schema object or array of schemas
 * @returns Script tag with JSON-LD
 * @example
 * <JsonLd data={productSchema} />
 * <JsonLd data={[productSchema, breadcrumbSchema]} />
 */
export function JsonLd({ data }: JsonLdProps) {
  // Handle single schema or array
  const schemas = Array.isArray(data) ? data : [data];
  
  return (
    <>
      {schemas.map((schema, index) => (
        <script
          key={index}
          id={`json-ld-${index}`}
          type="application/ld+json"
          dangerouslySetInnerHTML={{
            __html: JSON.stringify(schema),
          }}
        />
      ))}
    </>
  );
}

export default JsonLd;
