'use client' import { useState, useEffect, useMemo, useCallback } from 'react' import Link from 'next/link' import { Heart, MessageCircle, Share2, RotateCcw, Bell, Clock } from 'lucide-react' /* ─── Types & Constants ─────────────────────────────────────── */ type PrayerName = 'Fajr' | 'Dhuhr' | 'Asr' | 'Maghrib' | 'Isha' const PRAYERS: PrayerName[] = ['Fajr', 'Dhuhr', 'Asr', 'Maghrib', 'Isha'] interface Timings { Fajr: string Sunrise: string Dhuhr: string Asr: string Maghrib: string Isha: string } const AYATUL_KURSI = { arabic: 'ٱللَّهُ لَآ إِلَـٰهَ إِلَّا هُوَ ٱلْحَىُّ ٱلْقَيُّومُ ۚ لَا تَأْخُذُهُۥ سِنَةٌ وَلَا نَوْمٌ ۚ لَّهُۥ مَا فِى ٱلسَّمَـٰوَٰتِ وَمَا فِى ٱلْأَرْضِ ۗ مَن ذَا ٱلَّذِى يَشْفَعُ عِندَهُۥٓ إِلَّا بِإِذْنِهِۦ ۚ يَعْلَمُ مَا بَيْنَ أَيْدِيهِمْ وَمَا خَلْفَهُمْ ۖ وَلَا يُحِيطُونَ بِشَىْءٍ مِّنْ عِلْمِهِۦٓ إِلَّا بِمَا شَآءَ ۚ وَسِعَ كُرْسِيُّهُ ٱلسَّمَـٰوَٰتِ وَٱلْأَرْضَ ۖ وَلَا يَـُٔودُهُۥ حِفْظُهُمَا ۚ وَهُوَ ٱلْعَلِىُّ ٱلْعَظِيمُ', translation: 'Allah! There is no god but Him, the Ever-Living, the Sustainer of existence. Neither drowsiness nor sleep overtakes Him. To Him belongs whatever is in the heavens and whatever is on the earth. Who is it that can intercede with Him except by His permission? He knows what is before them and what will be after them, and they encompass nothing of His knowledge except what He wills. His Kursi extends over the heavens and the earth, and their preservation tires Him not. And He is the Most High, the Most Great.', surah: 'Surah Al-Baqarah (2:255)', } const DHIKR_ITEMS = [ { arabic: 'سُبْحَانَ ٱللَّٰهِ', latin: 'SubhanAllah', target: 33, color: '#D4AF37' }, { arabic: 'ٱلْحَمْدُ لِلَّٰهِ', latin: 'Alhamdulillah', target: 33, color: '#10B981' }, { arabic: 'ٱللَّٰهُ أَكْبَرُ', latin: 'Allahu Akbar', target: 34, color: '#D4AF37' }, ] const POSTS = [ { id: 1, name: 'Ahmad R.', avatar: 'AR', content: 'Alhamdulillah, completed my first full month of Fajr prayer on time! ☀️ The early morning blessings are real.', likes: 24, comments: 5, }, { id: 2, name: 'Fatima Z.', avatar: 'FZ', content: 'Just finished reading Surah Al-Kahf. The story of the people of the cave never gets old. SubhanAllah how Allah protects the believers! 📖', likes: 42, comments: 8, }, { id: 3, name: 'Omar H.', avatar: 'OH', content: 'Anyone looking for a good tafsir of Juz Amma? I highly recommend "The Clear Quran" by Dr. Mustafa Khattab. Very accessible English. 🤲', likes: 18, comments: 12, }, ] /* ─── Helpers ────────────────────────────────────────────────── */ const RING_R = 40 const RING_CIRCUMFERENCE = 2 * Math.PI * RING_R const DHIKR_R = 22 const DHIKR_CIRCUMFERENCE = 2 * Math.PI * DHIKR_R function toMins(t: string): number { const [h, m] = t.split(':').map(Number) return h * 60 + m } function fmtCountdown(mins: number): string { if (mins <= 0) return 'Now' const h = Math.floor(mins / 60) const m = mins % 60 if (h === 0) return `${m}m` if (m === 0) return `${h}h` return `${h}h ${m}m` } function getGreeting(h: number): string { if (h < 5) return 'Late Night Reflection' if (h < 12) return 'Good Morning' if (h < 17) return 'Good Afternoon' if (h < 20) return 'Good Evening' return 'Night Reflection' } /* ─── Sub-components ─────────────────────────────────────────── */ function DhikrCard({ item, count, onTap, onReset, }: { item: (typeof DHIKR_ITEMS)[number] count: number onTap: () => void onReset: () => void }) { const progress = Math.min(count / item.target, 1) const dashoffset = DHIKR_CIRCUMFERENCE * (1 - progress) const isComplete = count >= item.target return (
{/* Circular ring + count display */} {/* Label */}
{item.arabic} {item.latin} / {item.target}
{/* Reset */} {count > 0 && ( )}
) } function PostCard({ post }: { post: (typeof POSTS)[number] }) { const [liked, setLiked] = useState(false) const [likeCount, setLikeCount] = useState(post.likes) const handleLike = () => { setLiked((p) => !p) setLikeCount((p) => (liked ? p - 1 : p + 1)) } return (
{/* Author row */}
{post.avatar}

{post.name}

Just now

{/* Content */}

{post.content}

{/* Action bar */}
) } /* ─── Home Page ──────────────────────────────────────────────── */ export default function HomePage() { const [now, setNow] = useState(new Date()) const [timings, setTimings] = useState(null) const [nextPrayer, setNextPrayer] = useState<{ name: PrayerName time: string minsLeft: number progress: number } | null>(null) // Dhikr counters const [dhikrCounts, setDhikrCounts] = useState([0, 0, 0]) // Tick every 30s useEffect(() => { const id = setInterval(() => setNow(new Date()), 30000) return () => clearInterval(id) }, []) // Fetch prayer times useEffect(() => { fetch( 'https://api.aladhan.com/v1/timingsByCity?city=Makkah&country=SaudiArabia&method=4' ) .then((r) => r.json()) .then((d) => { if (d.data?.timings) { setTimings(d.data.timings as Timings) } }) .catch(() => { // Hardcoded fallback — approximate Makkah times for the demo setTimings({ Fajr: '04:30', Sunrise: '05:45', Dhuhr: '12:20', Asr: '15:45', Maghrib: '18:55', Isha: '20:15', }) }) }, []) // Compute next prayer + ring progress useEffect(() => { if (!timings) return const nowMins = now.getHours() * 60 + now.getMinutes() for (let i = 0; i < PRAYERS.length; i++) { const pm = toMins(timings[PRAYERS[i]]) if (pm > nowMins) { // Found the next prayer const prevPrayer = i > 0 ? PRAYERS[i - 1] : PRAYERS[PRAYERS.length - 1] const prevMins = toMins(timings[prevPrayer]) const windowMinutes = pm - prevMins const elapsed = nowMins - prevMins const progress = Math.min(Math.max(elapsed / windowMinutes, 0), 1) setNextPrayer({ name: PRAYERS[i], time: timings[PRAYERS[i]], minsLeft: pm - nowMins, progress, }) return } } // After Isha — next is Fajr (next day) const fajrMins = toMins(timings.Fajr) + 24 * 60 const ishaMins = toMins(timings.Isha) const windowMinutes = fajrMins - ishaMins const elapsed = nowMins - ishaMins const progress = Math.min(Math.max(elapsed / windowMinutes, 0), 1) setNextPrayer({ name: 'Fajr', time: timings.Fajr, minsLeft: fajrMins - nowMins, progress, }) }, [timings, now]) const ringDashoffset = nextPrayer ? RING_CIRCUMFERENCE * (1 - nextPrayer.progress) : RING_CIRCUMFERENCE const greeting = useMemo(() => getGreeting(now.getHours()), [now]) // Dhikr handlers const handleDhikrTap = useCallback((idx: number) => { setDhikrCounts((prev) => { const copy = [...prev] if (copy[idx] < DHIKR_ITEMS[idx].target) { copy[idx] = copy[idx] + 1 } return copy }) }, []) const handleDhikrReset = useCallback((idx: number) => { setDhikrCounts((prev) => { const copy = [...prev] copy[idx] = 0 return copy }) }, []) const allDhikrComplete = dhikrCounts.every( (c, i) => c >= DHIKR_ITEMS[i].target ) return (
{/* ═══ Scrollable content ═══ */}
{/* ── Header ── */}

{greeting}

Assalamualaikum

Welcome to Falah

{/* ─── 1. Prayer Countdown Ring ─── */}
{/* SVG Ring */}
{/* Center emoji icon */}
🕌
{/* Next prayer info */}

Next Prayer

{nextPrayer ? ( <>

{nextPrayer.name}

{nextPrayer.time}

{fmtCountdown(nextPrayer.minsLeft)} remaining
) : (

Loading prayer times...

)}
{/* ─── 2. AI Morning Briefing ─── */}
{/* Decorative glow */}
🌙 Morning Briefing

Assalamualaikum! 🌙 Your spiritual briefing for today...

Today is a new opportunity to grow closer to Allah. Remember that every good deed, no matter how small, is multiplied by the Most Generous. Start your day with intention, pray Fajr on time, and carry that light through the hours ahead.

Chat with NurBuddy →
{/* ─── 3. Verse of the Day ─── */}
{/* Gold header bar */}
Verse of the Day {AYATUL_KURSI.surah}

{AYATUL_KURSI.arabic}

“{AYATUL_KURSI.translation}”

{/* ─── 4. Quick Dhikr ─── */}
📿 Quick Dhikr
{allDhikrComplete && ( ✅ Completed )}
{DHIKR_ITEMS.map((item, idx) => ( handleDhikrTap(idx)} onReset={() => handleDhikrReset(idx)} /> ))}
{/* ─── 5. Community Feed ─── */}
💬 Community
{POSTS.map((post) => ( ))}
{/* Bottom spacer */}
) }