"use client"; import "photoswipe/style.css"; import PhotoSwipeLightbox from "photoswipe/lightbox"; import { useCallback, useEffect, useId, useRef, useState } from "react"; import { Rating } from "@/components/shadcnblocks/rating"; import { AspectRatio } from "@/components/ui/aspect-ratio"; import { badgeVariants } from "@/components/ui/badge"; import { Button, buttonVariants } from "@/components/ui/button"; import { Carousel, type CarouselApi, CarouselContent, CarouselItem, } from "@/components/ui/carousel"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { cn } from "@/lib/utils"; type ImageType = { src: string; width: number; height: number; alt?: string; }; type ReviewType = { rate: number; author?: string; verifiedBuyer?: boolean; country?: { name: string; code: string; }; date: string; title: string; comment: string; images?: ImageType[]; }; type ReplyType = { title: string; comment: string; date: string; }; type ReviewWithOptionalReply = ReviewType & { reply?: ReplyType; }; interface Reviews18Props { reviews?: ReviewWithOptionalReply[]; pageAmmount?: string; className?: string; } type ReviewProps = ReviewWithOptionalReply; const REVIEWS: ReviewWithOptionalReply[] = [ { rate: 5, author: "جواد حسینی", verifiedBuyer: true, country: { name: "کانادا", code: "CA", }, date: "۲ ماه پیش", title: "ساعت زیبا با کیفیت عالی", comment: "واقعاً این ساعت را دوست دارم! حس لوکس دارد، روی مچ راحت است و حضوری حتی بهتر از عکس به نظر می‌رسد. جزئیاتش چشمگیر است و هم با استایل روزمره و هم رسمی جور درمی‌آید. سریع رسید و بسته‌بندی محکم بود. از وقتی رسیده تقریباً هر روز بسته‌ام قطعاً پیشنهاد می‌کنم.", images: [ { src: "/block-media/shadcnblocks/block/ecommerce/accessories/Elegant-Watch-on-Womans-Wrist-2.png", width: 1200, height: 1200, alt: "ساعت روی مچ", }, ], }, { rate: 5, author: "ناشناس", verifiedBuyer: true, country: { name: "ایالات متحده", code: "US", }, date: "۲ ماه پیش", title: "جواهرات خیره‌کننده", comment: "کیفیت ساخت فوق‌العاده است. جواهرات ظریف و زیر نور زیبا می‌درخشد. دقیقاً همان چیزی بود که می‌خواستم سبک، راحت و بسیار شیک. حس برند لوکس دارد و در جعبه زیبایی رسید که تجربه خرید را بهتر کرد. تا حالا چندین تعریف شنیده‌ام.", images: [ { src: "/block-media/shadcnblocks/block/ecommerce/accessories/Elegant-Jewelry-Portrait-1.png", width: 349, height: 640, alt: "پرتره با جواهرات", }, ], }, { rate: 5, author: "ناشناس", verifiedBuyer: true, country: { name: "ایالات متحده", code: "US", }, date: "۲ ماه پیش", title: "اندازه دقیق و طراحی شیک", comment: "کیفیت پارچه عالی است نرم، فیت مناسب و رنگ‌هایی که حضوری هم مثل عکس‌ها جذاب‌اند. هر دو قطعه بادوام و راحت‌اند و دوختشان دقیق است. اندازه‌ها هم دقیقاً مطابق راهنما بود. حتماً دوباره از این فروشگاه سفارش می‌دهم چون ارزش خرید واقعاً بالاست.", images: [ { src: "/block-media/shadcnblocks/block/ecommerce/clothes/pexels-429124762-19881454-1.jpg", width: 640, height: 853, alt: "تصویر نظر مشتری لباس ۱", }, { src: "/block-media/shadcnblocks/block/ecommerce/clothes/pexels-429124762-19881457-1.jpg", width: 640, height: 853, alt: "تصویر نظر مشتری لباس ۲", }, ], }, { rate: 5, author: "ناشناس", verifiedBuyer: true, country: { name: "ایالات متحده", code: "US", }, date: "۲ ماه پیش", title: "کیفیت شگفت‌انگیز", comment: "از کیفیت کلی و بسته‌بندی خیلی راضی‌ام. همه‌چیز لوکس و بادوام است، از جنس تا جزئیات پرداخت. ارسال سریع بود و کالا سالم رسید. این برند از انتظارم بالاتر رفت و همین الان دنبال خرید بعدی‌ام.", }, { rate: 5, author: "ناشناس", verifiedBuyer: true, country: { name: "استرالیا", code: "AU", }, date: "۲ ماه پیش", title: "کاملاً پیشنهاد می‌کنم", comment: "در همه جنبه‌ها از انتظارم فراتر رفت. جنس‌ها لوکس‌اند، ساخت عالی است و رنگ‌ها حضوری فوق‌العاده‌اند. وقتی درباره سایز سوال داشتم، پشتیبانی هم بسیار مفید بود. ارسال سریع، بسته‌بندی زیبا و تجربه خرید عالی از خریدم کاملاً راضی‌ام.", }, ]; const sortOptions = [ { value: "featured", label: "برگزیده" }, { value: "highest_rating", label: "بیشترین امتیاز" }, { value: "lowest_rating", label: "کمترین امتیاز" }, ] as const; const Reviews18 = ({ reviews = REVIEWS, pageAmmount = "۱ تا ۲۰ از ۲۲۵ نظر", className, }: Reviews18Props) => { return (

{pageAmmount}

{reviews.map((item, index) => ( ))}
); }; const Review = ({ title, comment, images, rate, author, verifiedBuyer, country, date, }: ReviewProps) => { return (

{author}

{verifiedBuyer && (

خریدار تأییدشده

)}
{country && (
{`پرچم {country.name}، {date}
)}

{title}

{comment}

); }; const ReviewCarousel = ({ images, galleryID, }: { images?: ImageType[]; galleryID?: string; }) => { const [api, setApi] = useState(); const [current, setCurrent] = useState(0); const lightboxRef = useRef(null); const generatedGalleryID = useId(); const PhotoSwipeID = galleryID?.trim() ?? generatedGalleryID; useEffect(() => { const lightbox = new PhotoSwipeLightbox({ gallery: "#" + PhotoSwipeID, children: "a", bgOpacity: 1, wheelToZoom: true, arrowPrev: false, arrowNext: false, close: false, zoom: false, counter: false, mainClass: "[&>div:first-child]:!bg-background", pswpModule: () => import("photoswipe"), }); lightbox.init(); lightboxRef.current = lightbox; const buttonClassName = cn( buttonVariants({ variant: "outline", size: "icon", className: "rounded-full", }), ); const indicatorClassName = cn(badgeVariants({ variant: "secondary" })); lightbox.on("uiRegister", () => { if (lightbox?.pswp?.ui) { lightbox.pswp.ui.registerElement({ name: "custom-close-btn", order: 10, isButton: false, appendTo: "root", className: "absolute top-5 end-5", html: ` `, onInit: (el, pswp) => { el.querySelector("#pswp-close")?.addEventListener("click", () => pswp.close(), ); }, }); } if (lightbox?.pswp?.ui) { lightbox.pswp.ui.registerElement({ name: "custom-indicator-btn", order: 10, isButton: false, appendTo: "root", className: "absolute top-5 start-5", html: `
`, onInit: (el, pswp) => { const indicatorElem = el.querySelector("#pswp-indicator"); let prevIndex = -1; pswp.on("change", () => { prevIndex = pswp.currIndex; if (indicatorElem) { const current = (prevIndex + 1).toLocaleString("fa-IR"); const total = pswp.getNumItems().toLocaleString("fa-IR"); indicatorElem.innerHTML = `${current} / ${total}`; } }); }, }); } if (lightbox?.pswp?.ui) { lightbox.pswp.ui.registerElement({ name: "custom-next-prev-btns", order: 10, isButton: false, appendTo: "root", className: "absolute top-1/2 inset-x-0 -translate-y-1/2", html: images && images.length < 2 ? "" : `
`, onInit: (el, pswp) => { el.querySelector("#pswp-prev")?.addEventListener("click", () => pswp.next(), ); el.querySelector("#pswp-next")?.addEventListener("click", () => pswp.prev(), ); }, }); } }); return () => lightbox.destroy(); }, [PhotoSwipeID, images]); const onSelect = useCallback((carouselApi: CarouselApi) => { if (!carouselApi) return; setCurrent(carouselApi.selectedScrollSnap() + 1); }, []); useEffect(() => { if (!api) return; api.on("reInit", onSelect); api.on("select", onSelect); onSelect(api); return () => { api.off("select", onSelect); }; }, [api, onSelect]); useEffect(() => { if (lightboxRef.current && api) { lightboxRef.current.on("change", () => { api.scrollTo(lightboxRef.current?.pswp?.currIndex || 0); }); } }, [api, current]); if (!images?.length) return null; return (
{images.map((img, index) => ( {img.alt ))}
); }; export { Reviews18 };