import { ContainerSm } from "@/app/components/layout/ContainerSm";
import Image from "next/image";
import Link from "next/link";
import Heading from "@/app/components/ui/Heading";
import type { PackagingData } from "@/app/types";

export default function PackagingTemplate({ data }: { data: PackagingData }) {
  return (
    <>
      <section className="relative h-[65vh] w-full">
        {data.heroImage && (
          <Image
            src={data.heroImage}
            alt={data.title || "Hero Background"}
            fill
            className="absolute top-0 left-0 w-full h-full object-cover object-center"
            priority
            fetchPriority="high"
            loading="eager"
          />
        )}
        <div className="relative bg-black/60 w-full h-full flex items-center">
          <ContainerSm>
            <Heading as="h1" variant="title" className="text-white">
              {data.title}
            </Heading>
          </ContainerSm>
        </div>
        <div className="absolute z-10 bottom-0 w-full bg-white h-24 [clip-path:polygon(0%_0%,0%_100%,100%_100%)]"></div>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-16">
            <div className="flex flex-col gap-2">
              <Heading
                as="h2"
                variant="section"
                className="text-primary text-center"
              >
                {data.title}
              </Heading>
              <p className="text-gray-600 text-center">{data.description}</p>
            </div>
            <div className="flex flex-col lg:flex-row justify-center gap-1 w-full lg:w-3/4 mx-auto rounded-xl overflow-hidden">
              <div className="flex flex-col gap-1 w-full">
                {data.features
                  .filter((_, i) => i % 2 == 0)
                  .map((feature, index) => (
                    <div
                      key={index}
                      className="flex w-full justify-between items-center bg-[#C6E6958F] px-3 py-4"
                    >
                      <Heading as="h4" variant="card" className="text-primary">
                        {feature.title}
                      </Heading>
                      <p className="text-primary">{feature.value}</p>
                    </div>
                  ))}
              </div>
              <div className="flex flex-col gap-1 w-full">
                {data.features
                  .filter((_, i) => i % 2 !== 0)
                  .map((feature, index) => (
                    <div
                      key={index}
                      className="flex w-full justify-between items-center bg-[#C6E6958F] px-3 py-4"
                    >
                      <Heading as="h4" variant="card" className="text-primary">
                        {feature.title}
                      </Heading>
                      <p className="text-primary">{feature.value}</p>
                    </div>
                  ))}
              </div>
            </div>
          </div>
        </ContainerSm>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-16">
            <div className="flex flex-col gap-2">
              <Heading
                as="h2"
                variant="section"
                className="text-primary text-center"
              >
                Related Products
              </Heading>
            </div>
            <div className="flex flex-col md:flex-row gap-4 mx-auto w-fit">
              {data.relatedProducts.map((product, index) => (
                <Link key={index} href={product.href}>
                  <div className="border px-3 py-3 w-fit border-gray-200 rounded-xl hover:border-primary hover:-translate-y-3 transition-transform duration-500">
                    <Image
                      src={product.image}
                      alt={product.title}
                      width={280}
                      height={350}
                      className="rounded-lg"
                    />
                    <Heading
                      as="h4"
                      variant="card"
                      className="text-primary text-center"
                    >
                      {product.title}
                    </Heading>
                  </div>
                </Link>
              ))}
            </div>
          </div>
        </ContainerSm>
      </section>
    </>
  );
}
