export function OrganizationJsonLd({ siteTitle, siteDescription, url, logo }: {
  siteTitle: string;
  siteDescription: string;
  url: string;
  logo: string;
}) {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify({
          "@context": "https://schema.org",
          "@type": "Organization",
          name: siteTitle,
          description: siteDescription,
          url,
          logo,
          sameAs: [
            "https://www.facebook.com/SigmaTaxPro",
            "https://twitter.com/sigmataxpro",
            "https://www.linkedin.com/company/sigma-tax-pro",
          ],
        }),
      }}
    />
  );
}

export function ProductJsonLd({
  name,
  description,
  sku,
  price,
  currency = "USD",
  image,
  url,
}: {
  name: string;
  description: string;
  sku: string;
  price: string | number;
  currency?: string;
  image?: string;
  url: string;
}) {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify({
          "@context": "https://schema.org",
          "@type": "Product",
          name,
          description,
          sku: sku || undefined,
          image: image || undefined,
          offers: {
            "@type": "Offer",
            price: Number(price),
            priceCurrency: currency,
            availability: "https://schema.org/InStock",
            url,
          },
        }),
      }}
    />
  );
}

export function ArticleJsonLd({
  title,
  description,
  url,
  image,
  datePublished,
  authorName = "Sigma Tax Pro",
}: {
  title: string;
  description: string;
  url: string;
  image?: string | null;
  datePublished: string;
  authorName?: string;
}) {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify({
          "@context": "https://schema.org",
          "@type": "Article",
          headline: title,
          description,
          url,
          image: image || undefined,
          datePublished,
          author: { "@type": "Organization", name: authorName },
          publisher: { "@type": "Organization", name: "Sigma Tax Pro" },
        }),
      }}
    />
  );
}

export function ServiceJsonLd({
  name,
  description,
  url,
}: {
  name: string;
  description: string;
  url: string;
}) {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify({
          "@context": "https://schema.org",
          "@type": "Service",
          name,
          description,
          url,
          provider: { "@type": "Organization", name: "Sigma Tax Pro" },
        }),
      }}
    />
  );
}

export function ItemListJsonLd({
  name,
  description,
  url,
  itemList,
}: {
  name: string;
  description: string;
  url: string;
  itemList: Array<{ name: string; url: string; price?: string | number; sku?: string }>;
}) {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{
        __html: JSON.stringify({
          "@context": "https://schema.org",
          "@type": "ItemList",
          name,
          description,
          url,
          itemListElement: itemList.map((item, i) => ({
            "@type": "ListItem",
            position: i + 1,
            item: {
              "@type": "Product",
              name: item.name,
              ...(item.sku ? { sku: item.sku } : {}),
              ...(item.price !== undefined
                ? {
                    offers: {
                      "@type": "Offer",
                      price: Number(item.price),
                      priceCurrency: "USD",
                      url: item.url,
                    },
                  }
                : {}),
            },
          })),
        }),
      }}
    />
  );
}
