"use client";

import React, { useState } from "react";
import Title from "../title";
import Text from "../text";
import { Asphalt, Ekskavator, Forklift, Kran, Truck } from "@/assets";
import Image from "next/image";
import type {productFilterTypes, ProductTypes}  from "@/types";
import { allProducts } from "@/data";
import ProductCard from "../carTypePageParts/productCard";

const productFilterTypes: productFilterTypes[] = [
  { name: "trucks", image: Truck },
  { name: "cranes", image: Kran },
  { name: "forklift-trucks", image: Ekskavator },
  { name: "excavators", image: Forklift },
  { name: "road-repairs", image: Asphalt },
];

export default function Products() {
  //product type togle states
  const [productFilter, setProductFilter] = useState<string | null>(null);
  return (
    <div className="max-w-[1200px] w-full mx-auto">
      {/* title part */}
      <div className="flex flex-col md:gap-8 gap-4">
        <div className="flex items-center justify-center w-full ">
          <div className="text-secondary px-2  py-1 text-[18px] font-semibold ">
            <Text txt="equipment" />
          </div>
          <div className="bg-primary text-secondary px-3 py-1 text-[18px] font-semibold ">
            <Text txt="amazing" />
          </div>
        </div>
        <Title text="pricing-h2" />
      </div>

      {/* product filters */}
      <div className="flex flex-wrap gap-1 items-center justify-center mb-10 ">
        {productFilterTypes.map((item, index) => (
          <button
            key={index}
            onClick={() => setProductFilter(item.name)}
            className={`${
              productFilter === item.name ? "bg-secondary" : ""
            } flex items-center gap-2 h-[58px] hover:bg-secondary border-gray-300 hover:border-secondary border-[1px] px-7 text-2xl rounded-tr-full rounded-bl-full `}
          >
            <Text txt={item.name} />
            <Image
              src={item.image}
              alt="Truck images"
              width={50}
              height={50}
              className="object-cover"
            />
          </button>
        ))}
      </div>

      {/* products */}
      <div className="grid gap-5 grid-cols-1 min-sm:grid-cols-2 min-lg:grid-cols-4 min-[1210px]:grid-cols-4" >
        {allProducts.map((item:ProductTypes)=>(
          <ProductCard data={item} />
        ))}
      </div>
    </div>
  );
}
