'use client'; import React, { useEffect, useRef, useState } from 'react'; import Image from 'next/image'; import { gsap } from 'gsap'; import { ScrollTrigger } from 'gsap/ScrollTrigger'; import { PhoneFrame, PhoneBottomNav, BellIcon, FlameIcon } from './PhoneMockup'; if (typeof window !== 'undefined') gsap.registerPlugin(ScrollTrigger); const feed = [ { store: 'Daily Login', pts: +50, time: '2m ago', type: 'earn' }, { store: 'Walking 5,000 steps', pts: +80, time: '1h ago', type: 'earn' }, { store: 'Spin Wheel Game', pts: +120, time: '3h ago', type: 'earn' }, { store: 'Selfie Booth', pts: +200, time: 'Yesterday', type: 'earn' }, ]; export default function EarnRewardsSection() { const [pts, setPts] = useState(0); const panelRef = useRef(null); const rafRef = useRef(0); const rowRefs = useRef<(HTMLDivElement | null)[]>([]); const activeRowRef = useRef(0); // Move the highlighted feed card as the section scrolls through the viewport useEffect(() => { if (typeof window === 'undefined') return; const el = panelRef.current; if (!el) return; const applyRow = (idx: number) => { if (idx === activeRowRef.current) return; activeRowRef.current = idx; rowRefs.current.forEach((row, i) => { if (!row) return; const active = i === idx; row.style.background = active ? '#f0fdf4' : 'transparent'; row.style.borderColor = active ? '#16a34a' : 'transparent'; row.style.transform = active ? 'translateX(4px) scale(1.02)' : 'translateX(0) scale(1)'; row.style.boxShadow = active ? '0 10px 24px -12px rgba(22,163,74,0.35)' : 'none'; const icon = row.querySelector('.feed-icon'); if (icon) { icon.style.background = active ? 'rgba(22,163,74,0.14)' : 'rgba(23,21,18,0.04)'; icon.style.borderColor = active ? '#16a34a' : 'rgba(23,21,18,0.08)'; icon.style.color = active ? '#16a34a' : '#9ca3af'; } const points = row.querySelector('.feed-pts'); if (points) { points.style.background = active ? 'rgba(22,163,74,0.14)' : 'rgba(22,163,74,0.08)'; } }); }; const st = ScrollTrigger.create({ trigger: el, start: 'top 65%', end: 'bottom 60%', onUpdate: (self) => { applyRow(Math.min(feed.length - 1, Math.floor(self.progress * feed.length))); }, }); return () => st.kill(); }, []); useEffect(() => { const el = panelRef.current; if (!el) return; const obs = new MutationObserver(() => { if (el.hasAttribute('data-active')) { const start = performance.now(); const tick = (now: number) => { const t = Math.min((now - start) / 1800, 1); setPts(Math.round((1 - Math.pow(1 - t, 3)) * 284)); if (t < 1) rafRef.current = requestAnimationFrame(tick); }; rafRef.current = requestAnimationFrame(tick); } }); obs.observe(el, { attributes: true, attributeFilter: ['data-active'] }); return () => { obs.disconnect(); cancelAnimationFrame(rafRef.current); }; }, []); return (
{/* Left — points + headline */}
{/* Live label */}
Live LYTs balance
{/* Giant gold number */}
{pts.toLocaleString()}
{/* Redeemable line */}
₹{pts.toLocaleString()} redeemable value
Earn04

Every step. Every game. Every day.

Earn LYTs (Loyaly Tokens) through daily app login, completing 5,000-step walking challenges, playing Maze, Spin Wheel, Scratch Card, and Match Master games, or visiting Selfie Booths at partner malls. Every activity adds more LYTs to your balance.

{/* Right — phone mockup, matches the in-app Earn / Home experience */}
{/* Amber header */}
Loyaly.AI
6-day streak · keep it going!
{/* Balance card */}
Total LYTs
284
≈ ₹284 redeemable
{/* Feed header */}
Activity feed LIVE
{/* Feed rows */}
{feed.map((tx, i) => (
{ rowRefs.current[i] = el; }} style={{ display: 'grid', gridTemplateColumns: '32px minmax(0,1fr) auto', alignItems: 'center', gap: 10, padding: '8px 8px', borderRadius: 12, background: i === 0 ? '#f0fdf4' : 'transparent', border: `1px solid ${i === 0 ? '#16a34a' : 'transparent'}`, transform: i === 0 ? 'translateX(4px) scale(1.02)' : 'translateX(0) scale(1)', boxShadow: i === 0 ? '0 10px 24px -12px rgba(22,163,74,0.35)' : 'none', transition: 'background 0.35s ease, border-color 0.35s ease, transform 0.35s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.35s ease', }}>
{tx.store}
{tx.time}
+{tx.pts}
))}
{/* Summary strip */}
{[ { label: 'Earned this month', val: '660 LYTs', color: '#16a34a', bg: '#f0fdf4', border: '#16a34a' }, { label: 'Redeemable value', val: '₹660', color: '#bc7122', bg: '#fff7e0', border: '#f4be28' }, ].map((s, i) => (
{s.label}
{s.val}
))}
); }