"use client"; import { useEffect, useState } from "react"; import EmptyState from "./emptyData"; import { GET } from "@/lib/allProducts"; import { ProductModal } from "../ProductModal"; import { motion } from "framer-motion"; import { ProductCard } from "../ProductCard"; const itemVariants = { hidden: { opacity: 0, y: 20 }, visible: { opacity: 1, y: 0 }, }; export default function Products() { const [allProducts, setAllProducts] = useState(null); const [selectedProduct, setSelectedProduct] = useState(null); useEffect(() => { const all = GET(); all && Array.isArray(all) && all.length > 0 ? setAllProducts(all) : setAllProducts([]); setAllProducts; }, []); const handleViewDetails = (slug: string) => { const product = allProducts.find((p: any) => p.slug === slug); if (product) { setSelectedProduct(product); } }; return (
{allProducts && allProducts.length > 0 ? (
{allProducts.map((product: any) => ( ))}
) : ( )} {/* Product Modal */} {selectedProduct && ( setSelectedProduct(null)} /> )}
); }