diff --git a/components/products/AddToCardLeftSection.jsx b/components/products/AddToCardLeftSection.jsx index 64f114a..9f2a818 100644 --- a/components/products/AddToCardLeftSection.jsx +++ b/components/products/AddToCardLeftSection.jsx @@ -1,5 +1,5 @@ "use client"; -import React, { useContext, useState } from "react"; +import React, { useContext, useState, useRef } from "react"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { ChevronLeft, ChevronRight, Award } from "lucide-react"; // Added Award icon @@ -9,8 +9,10 @@ import Image from "next/image"; const ProductGallery = ({ productId }) => { const { products } = useContext(ProductContext); - const [currentImageIndex, setCurrentImageIndex] = useState(0); + const [showZoom, setShowZoom] = useState(false); + const [zoomPosition, setZoomPosition] = useState({ x: 0, y: 0 }); + const imageContainerRef = useRef(null); const nextImage = () => { setCurrentImageIndex((prevIndex) => (prevIndex + 1) % productImages.length); @@ -22,6 +24,7 @@ const ProductGallery = ({ productId }) => { (prevIndex - 1 + productImages.length) % productImages.length ); }; + const product = products?.find((pr) => pr.id == productId); if (!product) { return null; @@ -30,6 +33,23 @@ const ProductGallery = ({ productId }) => { const productImages = product?.images?.map((img) => img.image) || []; const hasCertificate = product.certificate && product.certificate !== "NA"; + const handleMouseMove = (e) => { + if (!imageContainerRef.current) return; + + const { left, top, width, height } = imageContainerRef.current.getBoundingClientRect(); + + // Calculate position as percentage + const x = ((e.clientX - left) / width) * 100; + const y = ((e.clientY - top) / height) * 100; + + setZoomPosition({ x, y }); + setShowZoom(true); + }; + + const handleMouseLeave = () => { + setShowZoom(false); + }; + return (