'use client' import { useState, useEffect, useCallback } from 'react' import { useAuth } from '@/lib/AuthContext' import { useRouter } from 'next/navigation' import { Flame, CheckCircle2, RotateCcw } from 'lucide-react' const DHIKR_SEQUENCE = [ { arabic: 'سُبْحَانَ اللَّهِ', transliteration: 'SubhanAllah', meaning: 'Glory be to Allah', target: 33, ring: '#10b981', // emerald glow: 'rgba(16,185,129,0.25)', bg: 'rgba(16,185,129,0.08)', }, { arabic: 'الْحَمْدُ لِلَّهِ', transliteration: 'Alhamdulillah', meaning: 'All praise is for Allah', target: 33, ring: '#3b82f6', // blue glow: 'rgba(59,130,246,0.25)', bg: 'rgba(59,130,246,0.08)', }, { arabic: 'اللَّهُ أَكْبَرُ', transliteration: 'Allahu Akbar', meaning: 'Allah is the Greatest', target: 34, ring: '#D4AF37', // gold glow: 'rgba(212,175,55,0.3)', bg: 'rgba(212,175,55,0.08)', }, ] const TOTAL = DHIKR_SEQUENCE.reduce((s, d) => s + d.target, 0) export default function DhikrPage() { const { user, token } = useAuth() const router = useRouter() const [phase, setPhase] = useState(0) const [count, setCount] = useState(0) const [totalCount, setTotalCount] = useState(0) const [streak, setStreak] = useState(0) const [todayCompleted, setTodayCompleted] = useState(false) const [justFinished, setJustFinished] = useState(false) const [loading, setLoading] = useState(true) const [ripple, setRipple] = useState(false) const current = DHIKR_SEQUENCE[phase] useEffect(() => { if (!token) { setLoading(false); return } fetch('/api/dhikr/status', { headers: { Authorization: `Bearer ${token}` } }) .then(r => r.json()) .then(d => { setStreak(d.streak ?? 0) setTodayCompleted(d.todayCompleted ?? false) if (d.todayCompleted) setTotalCount(TOTAL) }) .catch(() => { }) .finally(() => setLoading(false)) }, [token]) const handleTap = useCallback(async () => { if (todayCompleted || justFinished) return if (typeof navigator !== 'undefined' && 'vibrate' in navigator) navigator.vibrate(10) setRipple(true) setTimeout(() => setRipple(false), 300) const newCount = count + 1 const newTotal = totalCount + 1 setCount(newCount) setTotalCount(newTotal) if (newCount >= current.target) { if (phase < DHIKR_SEQUENCE.length - 1) { setTimeout(() => { setPhase(p => p + 1); setCount(0) }, 350) } else { setJustFinished(true) setTodayCompleted(true) if (token) { try { const res = await fetch('/api/dhikr/complete', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, body: JSON.stringify({ count: TOTAL }), }) const data = await res.json() setStreak(data.streak ?? streak + 1) } catch { } } } } }, [count, totalCount, phase, current, token, todayCompleted, justFinished, streak]) const handleReset = () => { setPhase(0); setCount(0); setTotalCount(0) setJustFinished(false); setTodayCompleted(false) } const progress = current ? count / current.target : 1 const R = 58 const C = 2 * Math.PI * R const strokeDashoffset = C * (1 - progress) if (!user) { return (
📿

Daily Dhikr

Build a daily habit of remembrance. Sign in to track your streak.

) } if (loading) { return (
) } return (
{/* Header */}

Daily Dhikr

100 remembrances · after prayer

{streak}
{/* Phase progress dots */}
{DHIKR_SEQUENCE.map((d, i) => (
))}
{/* Completed today (not just-finished) */} {todayCompleted && !justFinished ? (

MashaAllah!

You've completed your daily dhikr

{streak} day streak
) : justFinished ? ( /* Completion screen */

SubhanAllah!

100 remembrances complete

{streak} day streak

“Whoever says SubhanAllah 33 times, Alhamdulillah 33 times, and Allahu Akbar 34 times after each prayer…”

— Sahih Muslim

) : ( /* Main counter */
{/* Ring counter */} {/* Dhikr text */}

{current.arabic}

{current.transliteration}

{current.meaning}

Tap to count

)} {/* Bottom progress */} {!justFinished && (
Total today {Math.min(totalCount, TOTAL)} / {TOTAL}
)}
) }