interface JsonLdSchema {
  '@context'?: string;
  '@type'?: string;
  [key: string]: unknown;
}

interface JsonLdSchemasProps {
  schemas: (string | JsonLdSchema)[];
}

/**
 * Reusable component to render JSON-LD schemas safely
 * Can be used on any page that needs structured data
 */
export default function JsonLdSchemas({ schemas }: JsonLdSchemasProps) {
  if (!schemas || schemas.length === 0) return null;

  return (
    <>
      {schemas.map((schema, index) => {
        // If schema is already a string with script tags, render as-is
        if (typeof schema === 'string') {
          return (
            <div
              key={index}
              dangerouslySetInnerHTML={{ __html: schema }}
            />
          );
        }
        
        // If schema is a JSON object, stringify and wrap in script tags
        if (typeof schema === 'object' && schema !== null) {
          return (
            <script
              key={index}
              type="application/ld+json"
              dangerouslySetInnerHTML={{
                __html: JSON.stringify(schema)
              }}
            />
          );
        }
        
        return null;
      })}
    </>
  );
}