'use client'; import { useEffect, useRef } from 'react'; import Image from 'next/image'; import { useTranslations } from 'next-intl'; import RequestQuoteForm from '@/components/RequestQuoteForm'; interface ProductSidebarProps { productName: string; productImage?: string; datasheetPath?: string | null; } export default function ProductSidebar({ productName, productImage, datasheetPath }: ProductSidebarProps) { const t = useTranslations('Products'); const sidebarRef = useRef(null); useEffect(() => { const handleScroll = () => { if (!sidebarRef.current) return; const sidebar = sidebarRef.current; const container = sidebar.parentElement; if (!container) return; const containerRect = container.getBoundingClientRect(); const sidebarHeight = sidebar.offsetHeight; // Offset from top of viewport when sticky const stickyOffset = 128; // 8rem = top-32 let translateY = 0; // If the top of the container has scrolled past our sticky offset if (containerRect.top < stickyOffset) { translateY = stickyOffset - containerRect.top; } // Don't let it go past the bottom of the container const maxTranslateY = containerRect.height - sidebarHeight; if (translateY > maxTranslateY) { translateY = maxTranslateY; } // Ensure translateY is never negative if (translateY < 0) translateY = 0; sidebar.style.transform = `translateY(${translateY}px)`; }; let rafId: number; const onScroll = () => { rafId = requestAnimationFrame(handleScroll); }; window.addEventListener('scroll', onScroll, { passive: true }); window.addEventListener('resize', handleScroll); // Initial call handleScroll(); return () => { window.removeEventListener('scroll', onScroll); window.removeEventListener('resize', handleScroll); cancelAnimationFrame(rafId); }; }, []); return (
{/* Request Quote Form */}
{/* Product Thumbnail */} {productImage && (
)}

{t('requestQuote')}

{t('requestQuoteDesc')}

{/* Datasheet Download */} {datasheetPath && (

{t('downloadDatasheet')}

{t('downloadDatasheetDesc')}

)}
); }