import type { Metadata } from "next";
import Image from "next/image";
import { Container } from "@/app/components/layout/Container";
import { ContainerSm } from "@/app/components/layout/ContainerSm";
import Heading from "@/app/components/ui/Heading";
import { mills } from "./_data/mills";
import MillsGrid from "./_components/MillsGrid";
import heroImg from "@/app/(services)/milling/_assets/milling-hero-banner.png";

export const metadata: Metadata = {
  title: "Pakistan Rice Mills Directory — Certified Exporters & Processors",
  description:
    "Explore Pakistan's leading rice mills. Discover certified basmati rice processing mills with modern milling facilities, international food safety certifications, and global export reach.",
  alternates: {
    canonical: "https://basmatipakistan.com/mills/",
  },
  openGraph: {
    title: "Pakistan Rice Mills Directory — Certified Exporters & Processors",
    description:
      "Explore Pakistan's leading rice mills. Discover certified basmati rice processing mills with modern milling facilities, international food safety certifications, and global export reach.",
    url: "https://basmatipakistan.com/mills/",
    images: [
      {
        url: "https://basmatipakistan.com/wp-content/uploads/2024/10/Introduction-to-Paddy-Milling.png",
      },
    ],
    type: "website",
  },
  twitter: {
    card: "summary_large_image",
    title: "Pakistan Rice Mills Directory — Certified Exporters & Processors",
    description:
      "Explore Pakistan's leading rice mills. Discover certified basmati rice processing mills with modern milling facilities, international food safety certifications, and global export reach.",
    images: [
      "https://basmatipakistan.com/wp-content/uploads/2024/10/Introduction-to-Paddy-Milling.png",
    ],
  },
};

export default function MillsPage() {
  const totalCertifications = new Set(
    mills.flatMap((m) => m.certifications),
  ).size;

  const totalExportDestinations = new Set(
    mills.flatMap((m) => m.exportDestinations),
  ).size;

  const totalCities = new Set(
    mills.map((m) => m.city).filter(Boolean),
  ).size;

  return (
    <>
      {/* Hero Section matching the website design */}
      <section className="relative h-[65vh] w-full">
        <Image
          src={heroImg}
          alt="Pakistan Rice Milling Industry Hero"
          fill
          placeholder="blur"
          className="absolute top-0 left-0 w-full h-full object-cover object-top-left"
          priority
          fetchPriority="high"
          loading="eager"
        />
        <div className="relative bg-black/60 w-full h-full flex items-center">
          <Container>
            <div className="flex flex-col gap-2 items-center text-center">
              <Heading as="h1" variant="title" className="text-white text-center">
                Pakistan&apos;s Rice Mills Directory
              </Heading>
              <p className="text-base lg:text-lg text-white/80 max-w-3xl mx-auto mt-2">
                Discover accredited rice processing mills equipped with state-of-the-art technology, international food safety certifications, and global supply capabilities.
              </p>
            </div>
          </Container>
        </div>
        <div className="absolute z-10 bottom-0 w-full bg-white h-24 [clip-path:polygon(100%_100%,100%_0,0_100%)]"></div>
      </section>

      {/* Intro Section */}
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-6">
            <Heading
              as="h2"
              variant="section"
              className="text-primary text-center"
            >
              Premier Rice Milling &amp; Processing Network
            </Heading>
            <p className="mx-auto text-gray-600 text-center leading-relaxed">
              Pakistan is home to world-renowned Basmati and non-Basmati rice processing facilities. Our directory profiles prominent mills across the Punjab rice belt, Sindh, and nationwide, detailing certified quality standards, milling capacities, grain varieties, and international export reach.
            </p>
          </div>
        </ContainerSm>
      </section>

      {/* Stats Counter Section */}
      <section className="mt-12 lg:mt-16">
        <Container>
          <div className="grid grid-cols-2 md:grid-cols-4 gap-6">
            <div className="border border-gray-200 rounded-xl p-6 text-center bg-white shadow-xs hover:border-primary transition-all duration-300">
              <p className="text-4xl lg:text-5xl font-bold text-primary">
                {mills.length}
              </p>
              <p className="text-gray-600 font-medium mt-2">Profiled Mills</p>
            </div>
            <div className="border border-gray-200 rounded-xl p-6 text-center bg-white shadow-xs hover:border-primary transition-all duration-300">
              <p className="text-4xl lg:text-5xl font-bold text-primary">
                {totalCities}
              </p>
              <p className="text-gray-600 font-medium mt-2">Cities &amp; Hubs</p>
            </div>
            <div className="border border-gray-200 rounded-xl p-6 text-center bg-white shadow-xs hover:border-primary transition-all duration-300">
              <p className="text-4xl lg:text-5xl font-bold text-primary">
                {totalCertifications}
              </p>
              <p className="text-gray-600 font-medium mt-2">Quality Certifications</p>
            </div>
            <div className="border border-gray-200 rounded-xl p-6 text-center bg-white shadow-xs hover:border-primary transition-all duration-300">
              <p className="text-4xl lg:text-5xl font-bold text-primary">
                {totalExportDestinations}
              </p>
              <p className="text-gray-600 font-medium mt-2">Export Markets</p>
            </div>
          </div>
        </Container>
      </section>

      {/* Mills Grid Section */}
      <section className="mt-16 lg:mt-24">
        <Container>
          <MillsGrid mills={mills} />
        </Container>
      </section>
    </>
  );
}
