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

export default function OrganicBasmatiRiceTemplate({
  data,
  slug,
}: {
  data: OrganicBasmatiRiceData;
  slug: string;
}) {
  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(100%_100%,100%_0,0_100%)]"></div>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-6">
            <Heading
              as="h2"
              variant="title"
              className="text-primary text-center"
            >
              {data.title}
            </Heading>
            <p className="text-gray-500 text-center">{data.description}</p>
          </div>
        </ContainerSm>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-12">
            <Heading
              as="h2"
              variant="title"
              className="text-primary text-center"
            >
              Nutritional Information Table
            </Heading>
            <div className="flex justify-center">
              <div className="hidden lg:flex gap-1 w-full max-w-5xl">
                <table className="h-fit w-1/2">
                  <thead className="text-white bg-primary text-lg">
                    <tr className="h-14 border-b-4">
                      <th className="px-16">Nutritional Fact</th>
                      <th className="px-16">Amount</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.specifications
                      .filter((_, i) => i % 2 === 0)
                      .map((fact, index) => (
                        <tr
                          key={index}
                          className="h-14 border-t-4 border-white bg-[#EFF8E1]/70 text-primary text-lg text-nowrap"
                        >
                          <td className="px-6 py-4 text-center font-semibold">
                            {fact.property}
                          </td>
                          <td className="px-6 py-4 text-center font-normal ">
                            {fact.specifications}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
                <table className="h-fit w-1/2">
                  <thead className="text-white bg-primary text-lg">
                    <tr className="h-14 border-b-4">
                      <th className="px-16">Nutritional Fact</th>
                      <th className="px-16">Amount</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.specifications
                      .filter((_, i) => i % 2 !== 0)
                      .map((fact, index) => (
                        <tr
                          key={index}
                          className="h-14 border-t-4 border-white bg-[#EFF8E1]/70 text-primary text-lg text-nowrap"
                        >
                          <td className="px-6 py-4 text-center font-semibold">
                            {fact.property}
                          </td>
                          <td className="px-6 py-4 text-center font-normal ">
                            {fact.specifications}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              <div className="block w-full lg:hidden mt-12">
                <table className="w-full">
                  <thead className="text-white bg-primary text-lg">
                    <tr className="h-14">
                      <th className="border-4">Nutritional Fact</th>
                      <th className="border-4">Amount</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.specifications.map((fact, index) => (
                      <tr
                        key={index}
                        className="h-14 bg-[#EFF8E1]/70 text-primary"
                      >
                        <td className="p-4 border-4 border-white font-bold">
                          {fact.property}
                        </td>
                        <td className="p-4 border-4 border-white font-bold ">
                          {fact.specifications}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </ContainerSm>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-12">
            <Heading
              as="h2"
              variant="title"
              className="text-primary text-center"
            >
              Product Gallery
            </Heading>
            <div className="grid justify-items-center grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
              {data.gallery.map((img, index) => (
                <div
                  key={index}
                  className="border px-5 py-4 w-fit border-gray-200 rounded-xl hover:border-primary hover:-translate-y-3 transition-transform duration-500"
                >
                  <Image
                    src={img}
                    alt={slug}
                    width={250}
                    height={250}
                    className="rounded-lg w-64 h-auto"
                  />
                </div>
              ))}
            </div>
          </div>
        </ContainerSm>
      </section>
    </>
  );
}
