import { useState, useCallback, useMemo, useEffect } from "react"; import { LazyMotion, domAnimation, m } from "framer-motion"; import Section from "@/components/Section"; import { Image } from "@unpic/react"; const categories = [ "Bars", "Barks", "Pralines", "Spreads", "Dragees", "Gelatos", ]; const categoryLinks = [ "https://shop.mozimo.in/#bar", "https://shop.mozimo.in/#barks", "https://shop.mozimo.in/#pralines", "https://shop.mozimo.in/#spreads", "https://shop.mozimo.in/#dragees", "https://shop.mozimo.in/", ]; const categoryImages = [ "/categories/c1.svg", "/categories/c2.svg", "/categories/c3.svg", "/categories/c4.svg", "/categories/c5.svg", "/categories/c6.svg", ]; export default function ProductCategory() { const [currentCategory, setCurrentCategory] = useState(0); // Instant category change with no debouncing const handleCategoryChange = useCallback((idx: number) => { setCurrentCategory(idx); }, []); // Preload only neighbor images ✅ useEffect(() => { const next = (currentCategory + 1) % categoryImages.length; const prev = (currentCategory - 1 + categoryImages.length) % categoryImages.length; [next, prev].forEach((i) => { const img = new window.Image(); img.src = categoryImages[i]; }); }, [currentCategory]); const categoryButtons = useMemo(() => { return categories.map((category, idx) => { const isActive = idx === currentCategory; return (