"use client"; import { useRef, useState } from "react"; import { useRouter } from "next/navigation"; import FavoriteToggle from "./FavoriteToggle"; type WorkHeroGalleryProps = { gallery: string[]; title: string; workId: string; shareUrl?: string; }; export default function WorkHeroGallery({ gallery, title, workId, shareUrl }: WorkHeroGalleryProps) { const router = useRouter(); const galleryRef = useRef(null); const [activeIndex, setActiveIndex] = useState(0); function updateActiveSlide() { const galleryNode = galleryRef.current; if (!galleryNode) { return; } const nextIndex = Math.round(galleryNode.scrollLeft / Math.max(galleryNode.clientWidth, 1)); setActiveIndex(Math.min(Math.max(nextIndex, 0), gallery.length - 1)); } function goBack() { if (typeof window !== "undefined" && window.history.length > 1) { router.back(); return; } router.push("/discover"); } async function shareWork() { const url = shareUrl || (typeof window !== "undefined" ? window.location.href : ""); if (!url) { return; } if (typeof navigator !== "undefined" && navigator.share) { await navigator.share({ title, text: `Mira este trabajo que encontre en Makers3D: ${title}`, url }).catch(() => undefined); return; } await navigator.clipboard?.writeText(url).catch(() => undefined); } return (
{gallery.map((image, index) => (
{`${title}
))}
{gallery.length > 1 ? ( ) : null}
{activeIndex + 1}/{gallery.length}
); }