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

export default function BasmatiRiceTemplate({
  data,
  slug,
}: {
  data: BasmatiRiceData;
  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="section"
              className="text-primary text-center"
            >
              {data.title}
            </Heading>
            <p className="mx-auto 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="section"
              className="text-primary text-center"
            >
              Product Features
            </Heading>
            <div className="flex flex-col lg:flex-row justify-between gap-6">
              {data.features.map((feature, index) => (
                <div
                  key={index}
                  className="w-full p-3 flex flex-col min-h-56 justify-evenly items-center text-primary hover:-translate-y-3 transition-transform duration-500 border border-[#273c07] bg-transparent hover:bg-[#273c07] hover:text-white rounded-xl"
                >
                  <Heading as="h4" variant="card" className="text-center">
                    {feature.title}
                  </Heading>
                  <p className="text-center">{feature.description}</p>
                </div>
              ))}
            </div>
          </div>
        </ContainerSm>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-12">
            <Heading
              as="h2"
              variant="section"
              className="text-primary text-center"
            >
              Product Specifications
            </Heading>
            <div className="flex justify-center w-full">
              <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">Property</th>
                      <th className="px-16">Specifications</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.specifications
                      .filter((_, i) => i % 2 == 0)
                      .map((spec, 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">
                            {spec.property}
                          </td>
                          <td className="px-6 py-4 text-center font-normal ">
                            {spec.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">Property</th>
                      <th className="px-16">Specifications</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.specifications
                      .filter((_, i) => i % 2 !== 0)
                      .map((spec, 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">
                            {spec.property}
                          </td>
                          <td className="px-6 py-4 text-center font-normal ">
                            {spec.specifications}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              <div className="block w-full lg:hidden">
                <table className="w-full">
                  <thead className="text-white bg-primary text-lg">
                    <tr className="h-14">
                      <th className="border-4">Property</th>
                      <th className="border-4">Specifications</th>
                    </tr>
                  </thead>
                  <tbody>
                    {data.specifications.map((spec, index) => (
                      <tr
                        key={index}
                        className="h-14 bg-[#EFF8E1]/70 text-primary"
                      >
                        <td className="p-4 border-4 border-white font-bold">
                          {spec.property}
                        </td>
                        <td className="p-4 border-4 border-white font-bold ">
                          {spec.specifications}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </ContainerSm>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          {data.sections.map((section, index) => (
            <div
              key={index}
              className={`flex flex-col-reverse gap-16 items-center ${
                index % 2 == 0
                  ? "lg:flex-row"
                  : "lg:flex-row-reverse my-32 lg:my-44"
              }`}
            >
              <div className="w-full lg:w-1/2">
                <div className="flex flex-col gap-6">
                  <Heading as="h3" variant="section" className="text-primary">
                    {section.title}
                  </Heading>
                  <p className="text-gray-500 leading-7">{section.text}</p>
                </div>
              </div>
              <div className="w-full lg:w-1/2 flex justify-center">
                <Image
                  src={section.image}
                  alt={`Production Areas of ${slug}`}
                  width={400}
                  height={400}
                  className="rounded-xl w-full max-w-lg h-auto"
                />
              </div>
            </div>
          ))}
        </ContainerSm>
      </section>
      <section className="mt-16 lg:mt-32">
        <ContainerSm>
          <div className="flex flex-col gap-12">
            <Heading
              as="h2"
              variant="section"
              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={400}
                    height={400}
                    className="rounded-lg w-64 h-auto"
                  />
                </div>
              ))}
            </div>
          </div>
        </ContainerSm>
      </section>
    </>
  );
}
