'use client'; import { useState, useEffect, useMemo } from 'react'; import { useLocale } from './LocaleProvider'; import { ts } from '@/lib/i18n'; import { getMoonPhaseInfo, getNextFullMoon, FULL_MOON_NAMES } from '@/lib/lunar'; function computeCountdown(target: Date) { const now = new Date(); const totalMs = target.getTime() - now.getTime(); if (totalMs <= 0) return { days: 0, hours: 0, minutes: 0, seconds: 0 }; return { days: Math.floor(totalMs / (1000 * 60 * 60 * 24)), hours: Math.floor((totalMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)), minutes: Math.floor((totalMs % (1000 * 60 * 60)) / (1000 * 60)), seconds: Math.floor((totalMs % (1000 * 60)) / 1000), }; } export default function HeroSection() { const { locale } = useLocale(); const nextFull = useMemo(() => getNextFullMoon(), []); const currentPhase = useMemo(() => getMoonPhaseInfo(new Date()), []); const [countdown, setCountdown] = useState(() => computeCountdown(nextFull)); const [mounted, setMounted] = useState(false); useEffect(() => { const mountTimer = setTimeout(() => setMounted(true), 0); const updateCountdown = () => { setCountdown(computeCountdown(nextFull)); }; const timer = setInterval(updateCountdown, 1000); return () => { clearTimeout(mountTimer); clearInterval(timer); }; }, [nextFull]); const nextFullName = FULL_MOON_NAMES[nextFull.getUTCMonth() + 1]?.[locale as keyof typeof FULL_MOON_NAMES[1]] || FULL_MOON_NAMES[nextFull.getUTCMonth() + 1]?.en; const formatDate = (d: Date) => { try { return d.toLocaleDateString(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); } catch { return d.toLocaleDateString('en', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); } }; return (
{/* Moon glow */}
{/* Current phase display */}
{currentPhase.emoji} {ts('current_phase', locale)}: {ts(currentPhase.phaseName, locale)} — {currentPhase.illumination}%

{ts('hero_title', locale)}

{ts('hero_subtitle', locale)}

{/* Next Full Moon Card */}

{ts('next_full_moon', locale)}

🌕
<>

{nextFullName}

{mounted ? formatDate(nextFull) : ''}

{/* Countdown */}
{[ { value: countdown.days, label: ts('countdown_days', locale) }, { value: countdown.hours, label: ts('countdown_hours', locale) }, { value: countdown.minutes, label: ts('countdown_minutes', locale) }, { value: countdown.seconds, label: ts('countdown_seconds', locale) }, ].map((item, i) => (
{mounted ? String(item.value).padStart(2, '0') : '--'} {item.label}
))}
{/* CTA */} {ts('explore', locale)} ↓
); }