import { Thing, WithContext } from 'schema-dts';

interface JsonLdProps {
  id?: string;
  data?: WithContext<Thing> | WithContext<Thing>[];
}

export default function JsonLd({ id, data }: JsonLdProps) {
  // If data is provided, use it. Otherwise, use the default Organization + WebSite schema.
  const schemaData = data || [
    {
      '@context': 'https://schema.org',
      '@type': 'Organization',
      name: 'E-TIB GmbH',
      url: 'https://e-tib.com',
      logo: 'https://e-tib.com/assets/logo.png',
      sameAs: [
        'https://www.instagram.com/me.and.eloise/',
      ],
      description: 'Ihr Partner für Kabelleitungstiefbau, Horizontalspülbohrungen, Planung und Vermessung.',
      address: {
        '@type': 'PostalAddress',
        streetAddress: 'Gewerbestraße 22',
        addressLocality: 'Guben',
        postalCode: '03172',
        addressCountry: 'DE',
      },
    },
    {
      '@context': 'https://schema.org',
      '@type': 'WebSite',
      name: 'E-TIB',
      url: 'https://e-tib.com',
      potentialAction: {
        '@type': 'SearchAction',
        target: {
          '@type': 'EntryPoint',
          urlTemplate: 'https://e-tib.com/search?q={search_term_string}',
        },
        'query-input': 'required name=search_term_string',
      },
    }
  ];

  return (
    <script
      id={id}
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify(schemaData),
      }}
    />
  );
}
