"use client"; import React, { useEffect, useRef, useState } from "react"; import Image from "next/image"; import Drift from "drift-zoom"; import PhotoSwipeLightbox from "photoswipe/lightbox"; import { Swiper, SwiperSlide } from "swiper/react"; import { FreeMode, Thumbs } from "swiper/modules"; import { useContextElement } from "@/context/Context"; const colorOptions = [ { id: "blue-sapphire", label: "Blue Sapphire", price: null, defaultChecked: false, }, { id: "seafoam-green", label: "Seafoam Green", price: "79.99", defaultChecked: true, }, { id: "dusty-rose", label: "Dusty Rose", price: "89.99", defaultChecked: false, }, { id: "light-gray", label: "Light Gray", price: "59.99", defaultChecked: false, }, ]; export default function ShopDetails({ product }) { const { addProductToCart, isAddedToCartProducts } = useContextElement(); const [value, setValue] = useState(1); const slides = [ { color: "blue-sapphire", image: product.imgSrc, }, { color: "dusty-rose", image: "/images/shop/thumbs-main-2.jpg", }, { color: "light-gray", image: "/images/shop/thumbs-main-3.jpg", }, { color: "seafoam-green", image: "/images/shop/thumbs-main-4.jpg", }, ]; const [activeColor, setActiveColor] = useState( colorOptions.find((opt) => opt.defaultChecked)?.id || "" ); const [swiperThumb, setSwiperThumb] = useState(null); const lightboxRef = useRef(null); useEffect(() => { // Initialize PhotoSwipeLightbox const lightbox = new PhotoSwipeLightbox({ gallery: "#gallery-swiper-started", children: ".item", pswpModule: () => import("photoswipe"), }); lightbox.init(); // Store the lightbox instance in the ref for later use lightboxRef.current = lightbox; // Cleanup: destroy the lightbox when the component unmounts return () => { lightbox.destroy(); }; }, []); useEffect(() => { // Function to initialize Drift // Function to check window width const checkWindowSize = () => window.innerWidth >= 1200; // Only proceed if window is wide enough if (!checkWindowSize()) return; const imageZoom = () => { const driftAll = document.querySelectorAll(".tf-image-zoom"); const pane = document.querySelector(".tf-zoom-main"); driftAll.forEach((el) => { new Drift(el, { zoomFactor: 2, paneContainer: pane, inlinePane: false, handleTouch: false, hoverBoundingBox: true, containInline: true, }); }); }; imageZoom(); const zoomElements = document.querySelectorAll(".tf-image-zoom"); const handleMouseOver = (event) => { const parent = event.target.closest(".section-image-zoom"); if (parent) { parent.classList.add("zoom-active"); } }; const handleMouseLeave = (event) => { const parent = event.target.closest(".section-image-zoom"); if (parent) { parent.classList.remove("zoom-active"); } }; zoomElements.forEach((element) => { element.addEventListener("mouseover", handleMouseOver); element.addEventListener("mouseleave", handleMouseLeave); }); // Cleanup event listeners on component unmount return () => { zoomElements.forEach((element) => { element.removeEventListener("mouseover", handleMouseOver); element.removeEventListener("mouseleave", handleMouseLeave); }); }; }, []); // Empty dependency array to run only once on mount return (
{slides.map((slide, index) => ( ))} {slides.map((elm, i) => (
))}

{product.title}

3 Review

${product.price.toFixed(2)}

{product.oldPrice && (

${product.oldPrice.toFixed(2)}

)}
Select Color
{colorOptions.map((color) => { const inputId = `values-${color.id}`; const isActive = activeColor === color.id; return ( setActiveColor(color.id)} /> ); })}
  • Condition: Machine Body. + 143W Power Supply
  • Display : 24" 4.5K (4480x2520) , 500 nits , wide color P3
  • CPU: Apple M3 8-Core CPU 4.0Ghz
  • GPU: 8-Core GPU ,16-Core Neural Engine
  • RAM: 8GB of onboard " Unified "
  • Storage: 256GB PCIe
  • Connect : x2 Thunderbolt 3 | USB 4 ports , Jack 3.5, Weight : 4,43kg
  • Accessory : Mouse,Keyboard, Power Adapter, Cable C to lightning.
QTY
setValue((pre) => (pre == 1 ? 1 : pre - 1)) } className="btn-quantity btn-decrease" > - setValue((pre) => pre + 1)} className="btn-quantity btn-increase" > +
); }