"use client"; import Image from "next/image"; import { useEffect, useRef, useState } from "react"; function ScrollRevealText({ text }: { text: string }) { const containerRef = useRef(null); const [progress, setProgress] = useState(0); useEffect(() => { const handleScroll = () => { if (!containerRef.current) return; const rect = containerRef.current.getBoundingClientRect(); const windowHeight = window.innerHeight; // Slower animation - more viewport range const startOffset = windowHeight * 0.9; const endOffset = windowHeight * 0.1; const totalDistance = startOffset - endOffset; const currentPosition = startOffset - rect.top; const newProgress = Math.max(0, Math.min(1, currentPosition / totalDistance)); setProgress(newProgress); }; window.addEventListener("scroll", handleScroll, { passive: true }); handleScroll(); // Initial check return () => window.removeEventListener("scroll", handleScroll); }, []); const words = text.split(" "); return (

{words.map((word, index) => { // Calculate blur and opacity based on scroll progress const appearProgress = progress * (words.length + 1); const wordAppearProgress = Math.max(0, Math.min(1, appearProgress - index)); const wordOpacity = wordAppearProgress; const wordBlur = (1 - wordAppearProgress) * 40; return ( {word} ); })}

); } const sideImages = [ { src: "/images/interior-view.png", alt: "Interior view with landscape", position: "left", }, { src: "/images/rusted-metal.png", alt: "Rusted metal texture", position: "right", }, ]; const textCycles = [ "Design & Sustainability.", "Passive Energy.", "Bio-sourced Construction.", ]; export function TechnologySection() { const sectionRef = useRef(null); const textSectionRef = useRef(null); const [scrollProgress, setScrollProgress] = useState(0); const [textProgress, setTextProgress] = useState(0); const descriptionText = "Passive architecture reimagining modern living. Triple glazing, reinforced insulation and natural ventilation combine with solar panels to create an energy-autonomous home. Bio-sourced materials like solid wood and hemp wool ensure healthy indoor air and minimal ecological footprint."; useEffect(() => { const handleScroll = () => { if (!sectionRef.current) return; const rect = sectionRef.current.getBoundingClientRect(); const scrollableHeight = window.innerHeight * 4; // Increased for 3 text cycles const scrolled = -rect.top; const progress = Math.max(0, Math.min(1, scrolled / scrollableHeight)); setScrollProgress(progress); // Text scroll progress if (textSectionRef.current) { const textRect = textSectionRef.current.getBoundingClientRect(); const windowHeight = window.innerHeight; const startOffset = windowHeight * 0.9; const endOffset = windowHeight * 0.1; const totalDistance = startOffset - endOffset; const currentPosition = startOffset - textRect.top; const newTextProgress = Math.max(0, Math.min(1, currentPosition / totalDistance)); setTextProgress(newTextProgress); } }; window.addEventListener("scroll", handleScroll, { passive: true }); handleScroll(); return () => { window.removeEventListener("scroll", handleScroll); }; }, []); // Title fades out first (0 to 0.2) const titleOpacity = Math.max(0, 1 - (scrollProgress / 0.2)); // Image transforms start after title fades (0.2 to 1) const imageProgress = Math.max(0, Math.min(1, (scrollProgress - 0.2) / 0.8)); // Smooth interpolations const centerWidth = 100 - (imageProgress * 58); // 100% to 42% const centerHeight = 100 - (imageProgress * 30); // 100% to 70% const sideWidth = imageProgress * 22; // 0% to 22% const sideOpacity = imageProgress; const sideTranslateLeft = -100 + (imageProgress * 100); // -100% to 0% const sideTranslateRight = 100 - (imageProgress * 100); // 100% to 0% const gap = imageProgress * 16; // 0px to 16px // Calculate grayscale for text section based on textProgress const grayscaleAmount = Math.round((1 - textProgress) * 100); return (
{/* Sticky container for scroll animation */}
{/* Bento Grid Container */}
{/* Left Column */}
{sideImages.filter(img => img.position === "left").map((img, idx) => ( {img.alt} ))}
{/* Main Center Image */}
{/* Layered Images - Progressive Fade In */} {/* Image 1 - Base layer - Sunrise/Sunset with sun rays */} Modern architecture at sunrise {/* Image 2 - Daytime scene - Fades in during first text cycle */} Modern architecture in daylight {/* Image 3 - Dusk/Evening - Fades in during second text cycle */} Modern architecture at dusk {/* Image 4 - Night with stars - Fades in during third text cycle */} Modern architecture at night
{/* Title Text - Cycles through 3 texts with blur effect */}
{textCycles.map((text, cycleIndex) => { // Each text cycle takes 1/3 of the scroll progress const cycleStart = cycleIndex / textCycles.length; const cycleEnd = (cycleIndex + 1) / textCycles.length; const cycleMid = (cycleStart + cycleEnd) / 2; const words = text.split(" "); return (

{words.map((word, wordIndex) => { let wordOpacity = 0; let wordBlur = 40; if (scrollProgress >= cycleStart && scrollProgress < cycleEnd) { const localProgress = (scrollProgress - cycleStart) / (cycleEnd - cycleStart); // First half: appear (blur 40→0, opacity 0→1) if (localProgress < 0.5) { const appearProgress = (localProgress / 0.5) * (words.length + 1); const wordAppearProgress = Math.max(0, Math.min(1, appearProgress - wordIndex)); wordOpacity = wordAppearProgress; wordBlur = (1 - wordAppearProgress) * 40; } // Second half: disappear (blur 0→40, opacity 1→0) else { const disappearProgress = ((localProgress - 0.5) / 0.5) * (words.length + 1); const wordDisappearProgress = Math.max(0, Math.min(1, disappearProgress - wordIndex)); wordOpacity = 1 - wordDisappearProgress; wordBlur = wordDisappearProgress * 40; } } return ( {word} ); })}

); })}
{/* Right Column */}
{sideImages.filter(img => img.position === "right").map((img, idx) => ( {img.alt} ))}
{/* Scroll space to enable animation - increased for 3 text cycles */}
{/* Description Section with Background Image and Scroll Reveal */}
{/* Gradient Overlay - Top to transparent */}
{/* Text Content */}
); }