import type { Metadata, Viewport } from "next";
import LandingPageClient from "./LandingPageClient";

const BASE_URL = process.env.NEXT_PUBLIC_SITE_URL ?? "https://routecommerce.com";

// JSON-LD structured data for the platform landing page.
// Schema.org SoftwareApplication + Organization + FAQPage so Google
// can render rich results for the product.
const structuredData = {
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Organization",
      "@id": `${BASE_URL}/#organization`,
      name: "Route Commerce",
      url: BASE_URL,
      logo: `${BASE_URL}/logo.png`,
      description:
        "Multi-tenant B2B e-commerce platform for fresh produce wholesale distribution.",
      sameAs: [
        // Add social profiles here as they come online
      ],
    },
    {
      "@type": "SoftwareApplication",
      "@id": `${BASE_URL}/#software`,
      name: "Route Commerce",
      applicationCategory: "BusinessApplication",
      applicationSubCategory: "Wholesale Distribution Platform",
      operatingSystem: "Web",
      url: BASE_URL,
      description:
        "All-in-one platform for produce wholesale distribution: orders, stops, routes, customer communications, and Stripe/Square payments.",
      offers: {
        "@type": "AggregateOffer",
        priceCurrency: "USD",
        lowPrice: 49,
        highPrice: 399,
        priceSpecification: [
          { "@type": "UnitPriceSpecification", name: "Starter", price: 49, priceCurrency: "USD", description: "$49/month" },
          { "@type": "UnitPriceSpecification", name: "Farm", price: 149, priceCurrency: "USD", description: "$149/month" },
          { "@type": "UnitPriceSpecification", name: "Enterprise", price: 399, priceCurrency: "USD", description: "Custom pricing" },
        ],
      },
      aggregateRating: {
        "@type": "AggregateRating",
        // Placeholder — replace with real review data once collected.
        ratingValue: 4.9,
        reviewCount: 12,
      },
    },
    {
      "@type": "WebSite",
      "@id": `${BASE_URL}/#website`,
      url: BASE_URL,
      name: "Route Commerce",
      publisher: { "@id": `${BASE_URL}/#organization` },
      inLanguage: "en-US",
    },
  ],
} as const;

export const metadata: Metadata = {
  title: "Route Commerce — Fresh Produce Wholesale Platform",
  description: "The all-in-one platform for produce wholesale distribution. Manage orders, stops, routes, and customer communications. Built for farms, Co-ops, and distributors.",
  keywords: ["produce wholesale", "farm management", "route commerce", "agricultural platform", "order management", "stop scheduling", "B2B e-commerce", "fresh produce delivery"],
  authors: [{ name: "Route Commerce" }],
  creator: "Route Commerce",
  publisher: "Route Commerce",
  openGraph: {
    title: "Route Commerce — Fresh Produce Wholesale Platform",
    description: "The all-in-one platform for produce wholesale distribution. Manage orders, stops, routes, and customer communications.",
    url: BASE_URL,
    siteName: "Route Commerce",
    locale: "en_US",
    type: "website",
    images: [
      {
        url: "/og-default.svg",
        width: 1200,
        height: 630,
        alt: "Route Commerce Platform",
      },
    ],
  },
  twitter: {
    card: "summary_large_image",
    title: "Route Commerce — Fresh Produce Wholesale Platform",
    description: "The all-in-one platform for produce wholesale distribution.",
    site: "@RouteCommerce",
    creator: "@RouteCommerce",
    images: ["/og-default.svg"],
  },
  alternates: {
    canonical: BASE_URL,
  },
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      "max-video-preview": -1,
      "max-image-preview": "large",
      "max-snippet": -1,
    },
  },
  icons: {
    icon: "/favicon.ico",
    apple: "/apple-touch-icon.png",
  },
};

export const viewport = {
  width: "device-width",
  initialScale: 1,
  maximumScale: 5,
};

export default function LandingPage() {
  return (
    <>
      <script
        type="application/ld+json"
        // eslint-disable-next-line react/no-danger
        dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
      />
      <LandingPageClient />
    </>
  );
}