'use client' import { useEffect, useRef, useState } from 'react' import { useTranslations } from 'next-intl' import { motion, useScroll, useTransform, useMotionValueEvent, useReducedMotion, } from 'framer-motion' import UnitRevealOverlay from './UnitRevealOverlay' const CDN = 'https://media.ayris.tech/t' const HERO_VIDEO = `${CDN}/vesta/hero/hero.mp4` // Scroll aralığına göre opacity döndüren helper function usePhaseOpacity( scrollYProgress: ReturnType['scrollYProgress'], inStart: number, inEnd: number, outStart: number, outEnd: number ) { return useTransform( scrollYProgress, [inStart, inEnd, outStart, outEnd], [0, 1, 1, 0] ) } export default function CloudRevealSection() { const t = useTranslations('hero') const prefersReducedMotion = useReducedMotion() const sectionRef = useRef(null) const canvasRef = useRef(null) const videoRef = useRef(null) const [loaded, setLoaded] = useState(false) const [activeUnit, setActiveUnit] = useState<{ id: string; label: string; sub: string } | null>(null) const { scrollYProgress } = useScroll({ target: sectionRef, offset: ['start start', 'end end'], }) // Progress bar const progressScaleX = useTransform(scrollYProgress, [0, 1], [0, 1]) // Logo: 0–8% görünür, sonra kaybolur const logoOpacity = useTransform(scrollYProgress, [0, 0.02, 0.08, 0.14], [0, 1, 1, 0]) const logoScale = useTransform(scrollYProgress, [0, 0.02], [0.92, 1]) // Phase 1: tagline (sol alt) const phase1Opacity = useTransform(scrollYProgress, [0, 0.05, 0.12, 0.18], [0, 1, 1, 0]) const phase1Y = useTransform(scrollYProgress, [0, 0.05], [20, 0]) // Phase 2: orta metin const phase2Opacity = useTransform(scrollYProgress, [0.20, 0.28, 0.40, 0.48], [0, 1, 1, 0]) const phase2Y = useTransform(scrollYProgress, [0.20, 0.28], [30, 0]) // Phase 3: stat rakamları const phase3Opacity = useTransform(scrollYProgress, [0.50, 0.57, 0.68, 0.75], [0, 1, 1, 0]) const phase3Y = useTransform(scrollYProgress, [0.50, 0.57], [30, 0]) // Phase 4: CTA const phase4Opacity = useTransform(scrollYProgress, [0.78, 0.85, 0.95, 1], [0, 1, 1, 0]) const phase4Y = useTransform(scrollYProgress, [0.78, 0.85], [30, 0]) // Video → canvas kurulumu useEffect(() => { if (prefersReducedMotion) return const video = videoRef.current const canvas = canvasRef.current if (!video || !canvas) return const ctx = canvas.getContext('2d') if (!ctx) return const drawVideoFrame = () => { if (video.readyState >= 2) { ctx.drawImage(video, 0, 0, canvas.width, canvas.height) } } video.addEventListener('seeked', drawVideoFrame) video.addEventListener('loadeddata', () => { setLoaded(true) drawVideoFrame() }) return () => video.removeEventListener('seeked', drawVideoFrame) }, [prefersReducedMotion]) // Scroll → video currentTime useMotionValueEvent(scrollYProgress, 'change', (progress) => { const video = videoRef.current if (!video || !video.duration) return video.currentTime = progress * video.duration }) // Scroll kilidi useEffect(() => { const lockScroll = () => { const section = sectionRef.current if (!section) return const maxY = section.offsetTop + section.offsetHeight - window.innerHeight if (window.scrollY > maxY) { window.scrollTo({ top: maxY, behavior: 'instant' }) } } window.addEventListener('scroll', lockScroll, { passive: true }) return () => window.removeEventListener('scroll', lockScroll) }, []) // Canvas boyutu useEffect(() => { const canvas = canvasRef.current if (!canvas) return const resize = () => { canvas.width = window.innerWidth canvas.height = window.innerHeight } resize() window.addEventListener('resize', resize) return () => window.removeEventListener('resize', resize) }, []) if (prefersReducedMotion) { return (

Vesta Muğla

{t('tagline')}

{t('subtitle')}

) } return ( <>
{/* Gizli video — sadece canvas'a kaynak */}