'use client' import { Container, Grid, Card, CardContent, Typography, Box, TextField, Button, Paper, Avatar, Chip, IconButton, Dialog, DialogTitle, DialogContent, DialogActions, Fab, List, ListItem, ListItemAvatar, ListItemText, MenuItem, useTheme, CircularProgress, Skeleton, } from '@mui/material' import { Favorite, Add, Close, Person, AccessTime, FavoriteBorder, Share, MoreVert, } from '@mui/icons-material' import { useState, useEffect } from 'react' import { useTranslations, useLocale, useFormatter } from 'next-intl' interface PrayerRequest { id: string title: string description: string category: string author: string timestamp: Date prayerCount: number isPrayedFor: boolean } export default function PrayersPage() { const theme = useTheme() const locale = useLocale() const t = useTranslations('pages.prayers') const tc = useTranslations('common') const f = useFormatter() const [prayers, setPrayers] = useState([]) const [openDialog, setOpenDialog] = useState(false) const [newPrayer, setNewPrayer] = useState({ title: '', description: '', category: 'personal', }) const [loading, setLoading] = useState(true) const categories = [ { value: 'personal', label: t('categories.personal'), color: 'primary' }, { value: 'family', label: t('categories.family'), color: 'secondary' }, { value: 'health', label: t('categories.health'), color: 'error' }, { value: 'work', label: t('categories.work'), color: 'warning' }, { value: 'ministry', label: t('categories.ministry'), color: 'success' }, { value: 'world', label: t('categories.world'), color: 'info' }, ] // Sample data - in real app this would come from API useEffect(() => { // Simulate loading prayers setTimeout(() => { setPrayers([ { id: '1', title: t('samples.item1.title'), description: t('samples.item1.description'), category: 'health', author: t('samples.item1.author'), timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000), prayerCount: 23, isPrayedFor: false, }, { id: '2', title: t('samples.item2.title'), description: t('samples.item2.description'), category: 'work', author: t('samples.item2.author'), timestamp: new Date(Date.now() - 5 * 60 * 60 * 1000), prayerCount: 15, isPrayedFor: true, }, { id: '3', title: t('samples.item3.title'), description: t('samples.item3.description'), category: 'family', author: t('samples.item3.author'), timestamp: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), prayerCount: 41, isPrayedFor: false, }, ]) setLoading(false) }, 1000) }, [locale]) const handleSubmitPrayer = async () => { if (!newPrayer.title.trim() || !newPrayer.description.trim()) return const prayer: PrayerRequest = { id: Date.now().toString(), title: newPrayer.title, description: newPrayer.description, category: newPrayer.category, author: locale === 'en' ? 'You' : 'Tu', // In real app, get from auth timestamp: new Date(), prayerCount: 0, isPrayedFor: false, } setPrayers([prayer, ...prayers]) setNewPrayer({ title: '', description: '', category: 'personal' }) setOpenDialog(false) // In real app, send to API try { await fetch('/api/prayers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(prayer), }) } catch (error) { console.error('Error submitting prayer:', error) } } const handlePrayFor = async (prayerId: string) => { setPrayers(prayers.map(prayer => prayer.id === prayerId ? { ...prayer, prayerCount: prayer.prayerCount + 1, isPrayedFor: true } : prayer )) // In real app, send to API try { await fetch(`/api/prayers/${prayerId}/pray`, { method: 'POST' }) } catch (error) { console.error('Error updating prayer count:', error) } } const getCategoryInfo = (category: string) => { return categories.find(cat => cat.value === category) || categories[0] } const formatTimestamp = (timestamp: Date) => { const now = new Date() const diff = now.getTime() - timestamp.getTime() const minutes = Math.floor(diff / (1000 * 60)) const hours = Math.floor(minutes / 60) const days = Math.floor(hours / 24) if (days > 0) return f.relativeTime(-days, 'day', { now }) if (hours > 0) return f.relativeTime(-hours, 'hour', { now }) if (minutes > 0) return f.relativeTime(-minutes, 'minute', { now }) return f.relativeTime(0, 'second', { now }) } return ( {/* Header */} {t('title')} {t('subtitle')} {/* Categories Filter */} {t('categories.title')} {categories.map((category) => ( ))} {t('stats.title')} • {t('stats.activeRequests', { count: prayers.length })}
• {t('stats.totalPrayers', { count: prayers.reduce((sum, p) => sum + p.prayerCount, 0) })}
• {t('stats.youPrayed', { count: prayers.filter(p => p.isPrayedFor).length })}
{/* Prayer Requests */} {loading ? ( {Array.from({ length: 3 }).map((_, index) => ( ))} ) : ( {prayers.map((prayer) => { const categoryInfo = getCategoryInfo(prayer.category) return ( {prayer.title} {prayer.author} {formatTimestamp(prayer.timestamp)} {prayer.description} {t('stats.totalPrayers', { count: prayer.prayerCount })} ) })} )}
{/* Add Prayer FAB */} setOpenDialog(true)} > {/* Add Prayer Dialog */} setOpenDialog(false)} maxWidth="sm" fullWidth > {t('dialog.title')} setOpenDialog(false)} size="small"> setNewPrayer({ ...newPrayer, title: e.target.value })} sx={{ mb: 2, mt: 1 }} /> setNewPrayer({ ...newPrayer, category: e.target.value })} sx={{ mb: 2 }} > {categories.map((option) => ( {option.label} ))} setNewPrayer({ ...newPrayer, description: e.target.value })} placeholder={t('dialog.placeholder')} />
) }