"use client"; import Image from "next/image"; import { useEffect, useRef, useState, useCallback } from "react"; export function GallerySection() { const galleryRef = useRef(null); const [scrollProgress, setScrollProgress] = useState(0); const rafRef = useRef(null); const images = [ { src: "/images/mono-1.png", alt: "Modern architecture at sunrise" }, { src: "/images/mono-2.png", alt: "Modern architecture in daylight" }, { src: "/images/mono-3.png", alt: "Modern architecture at dusk" }, { src: "/images/mono-4.png", alt: "Modern architecture at night" }, ]; const updateTransform = useCallback(() => { if (!galleryRef.current) return; const rect = galleryRef.current.getBoundingClientRect(); const windowHeight = window.innerHeight; const sectionHeight = galleryRef.current.offsetHeight; // Calculate scroll progress through the section const scrollableRange = sectionHeight - windowHeight; const scrolled = -rect.top; const progress = Math.max(0, Math.min(1, scrolled / scrollableRange)); setScrollProgress(progress); }, []); useEffect(() => { const handleScroll = () => { if (rafRef.current) { cancelAnimationFrame(rafRef.current); } rafRef.current = requestAnimationFrame(updateTransform); }; window.addEventListener("scroll", handleScroll, { passive: true }); updateTransform(); return () => { window.removeEventListener("scroll", handleScroll); if (rafRef.current) { cancelAnimationFrame(rafRef.current); } }; }, [updateTransform]); const isLastImage = images.length - 1; // Calculate fullscreen progress for the last image - more gradual // Start expanding when last image is 80% stacked, finish at end of section const fullscreenStartProgress = 0.6; // Start earlier for smoother transition const fullscreenProgress = Math.max(0, Math.min(1, (scrollProgress - fullscreenStartProgress) / (1 - fullscreenStartProgress))); // Ease out cubic for smoother animation const easedFullscreenProgress = 1 - Math.pow(1 - fullscreenProgress, 3); return ( ); }