'use client'; import React, { useState, useRef } from 'react'; import { CarouselCore } from '@theme/components/carousel-core'; import { Icon } from '@theme/components'; import { Product } from '@akinon/next/types'; import { Image } from '@akinon/next/components/image'; import useFavButton from '../../hooks/use-fav-button'; import { twMerge } from 'tailwind-merge'; import PluginModule, { Component } from '@akinon/next/components/plugin-module'; type ProductSliderItem = { product: Product; }; export default function ProductInfoSlider({ product }: ProductSliderItem) { const { FavButton } = useFavButton(product.pk); const carouselRef = useRef(null); const [activeIndex, setActiveIndex] = useState(0); const goToPrev = () => { const newIndex = activeIndex === 0 ? product?.productimage_set?.length - 1 : activeIndex - 1; setActiveIndex(newIndex); carouselRef.current?.previous(); }; const goToNext = () => { const newIndex = activeIndex === product?.productimage_set?.length - 1 ? 0 : activeIndex + 1; setActiveIndex(newIndex); carouselRef.current?.next(); }; const handleThumbnailClick = (index) => { setActiveIndex(index); carouselRef.current?.goToSlide(index); }; return (
{product?.productimage_set?.map((item, index) => ( {`Thumbnail handleThumbnailClick(index)} /> ))}
{ setActiveIndex(currentSlide); }} containerAspectRatio={{ mobile: 520 / 798, desktop: 484 / 726 }} > {product?.productimage_set?.map((item, i) => ( {product.name} ))}
); }