---
import { createEntity } from '../src/schema.js';
import { serializeJsonLd } from '../src/lib/serialize-jsonld.js';
import { warnGoogleSchema } from '../src/core/schema-google.js';

/**
 * Internal body shared by the typed entity components. Each public component fixes `type`; the
 * caller's `entity` supplies every other field.
 */
interface Props {
  type: string;
  entity?: Record<string, unknown>;
  eligibility?: 'schema' | 'google';
}
const { type, entity, eligibility = 'schema' } = Astro.props;
const jsonLd = { '@context': 'https://schema.org', ...createEntity({ ...entity, '@type': type }) };
if (entity) warnGoogleSchema(jsonLd, eligibility, { documentUrl: Astro.site ? new URL(Astro.url.pathname, Astro.site).href : Astro.url.href, explicitType: type });
---

{entity && <script type="application/ld+json" set:html={serializeJsonLd(jsonLd)} />}
