import type { Brand, Scooter } from "@/lib/mock-data";
import { SITE_NAME } from "@/lib/constants";
import { absoluteUrl } from "@/lib/seo";

type ProductJsonLdProps = {
  scooter: Scooter;
  brand?: Brand;
};

export function ProductJsonLd({ scooter, brand }: ProductJsonLdProps) {
  const schema = {
    "@context": "https://schema.org",
    "@type": "Product",
    name: scooter.name,
    description: scooter.shortDescription,
    brand: {
      "@type": "Brand",
      name: brand?.name ?? SITE_NAME,
    },
    image: [absoluteUrl(scooter.heroImage), ...scooter.galleryImages.map(absoluteUrl)],
    offers: {
      "@type": "Offer",
      priceCurrency: "NPR",
      price: scooter.offerPrice ?? scooter.price,
      availability: "https://schema.org/InStock",
      url: absoluteUrl(`/scooters/${scooter.slug}`),
      seller: {
        "@type": "Organization",
        name: SITE_NAME,
      },
    },
    additionalProperty: [
      { "@type": "PropertyValue", name: "Range", value: `${scooter.rangeKm} km` },
      { "@type": "PropertyValue", name: "Top speed", value: `${scooter.topSpeedKmph} km/h` },
      { "@type": "PropertyValue", name: "Battery", value: scooter.battery },
    ],
  };

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