'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 { useLocale } 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 [prayers, setPrayers] = useState([]) const [openDialog, setOpenDialog] = useState(false) const [newPrayer, setNewPrayer] = useState({ title: '', description: '', category: 'personal', }) const [loading, setLoading] = useState(true) const categories = locale === 'en' ? [ { value: 'personal', label: 'Personal', color: 'primary' }, { value: 'family', label: 'Family', color: 'secondary' }, { value: 'health', label: 'Health', color: 'error' }, { value: 'work', label: 'Work', color: 'warning' }, { value: 'ministry', label: 'Ministry', color: 'success' }, { value: 'world', label: 'World', color: 'info' }, ] : [ { value: 'personal', label: 'Personal', color: 'primary' }, { value: 'family', label: 'Familie', color: 'secondary' }, { value: 'health', label: 'Sănătate', color: 'error' }, { value: 'work', label: 'Muncă', color: 'warning' }, { value: 'ministry', label: 'Serviciu', color: 'success' }, { value: 'world', label: 'Lume', color: 'info' }, ] // Sample data - in real app this would come from API useEffect(() => { // Simulate loading prayers setTimeout(() => { setPrayers( locale === 'en' ? [ { id: '1', title: 'Prayer for healing', description: 'Please pray for my father who is in the hospital. He needs God\'s healing.', category: 'health', author: 'Maria P.', timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000), prayerCount: 23, isPrayedFor: false, }, { id: '2', title: 'God\'s guidance in career', description: 'Seeking God\'s direction for the next step in my career. Please pray for clarity and peace.', category: 'work', author: 'Alex M.', timestamp: new Date(Date.now() - 5 * 60 * 60 * 1000), prayerCount: 15, isPrayedFor: true, }, { id: '3', title: 'Unity in our family', description: 'Please pray for restoration of relationships in our family and for mutual forgiveness.', category: 'family', author: 'Anonymous', timestamp: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), prayerCount: 41, isPrayedFor: false, }, ] : [ { id: '1', title: 'Rugăciune pentru vindecare', description: 'Te rog să te rogi pentru tatăl meu care se află în spital. Are nevoie de vindecarea lui Dumnezeu.', category: 'health', author: 'Maria P.', timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000), prayerCount: 23, isPrayedFor: false, }, { id: '2', title: 'Îndrumarea lui Dumnezeu în carieră', description: 'Caut direcția lui Dumnezeu pentru următorul pas în cariera mea. Te rog să te rogi pentru claritate și pace.', category: 'work', author: 'Alexandru M.', timestamp: new Date(Date.now() - 5 * 60 * 60 * 1000), prayerCount: 15, isPrayedFor: true, }, { id: '3', title: 'Unitatea în familia noastră', description: 'Rugați-vă pentru restaurarea relațiilor în familia noastră și pentru iertarea reciprocă.', category: 'family', author: 'Anonim', 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 hours = Math.floor(diff / (1000 * 60 * 60)) const days = Math.floor(hours / 24) if (locale === 'en') { if (days > 0) return `${days} day${days === 1 ? '' : 's'} ago` if (hours > 0) return `${hours} hour${hours === 1 ? '' : 's'} ago` return 'A few minutes ago' } if (days > 0) return `${days} zile în urmă` if (hours > 0) return `${hours} ore în urmă` return 'Acum câteva minute' } return ( {/* Header */} {locale === 'en' ? 'Prayer Wall' : 'Peretele de rugăciuni'} {locale === 'en' ? 'Share prayers and pray together with the community' : 'Partajează rugăciuni și roagă-te împreună cu comunitatea'} {/* Categories Filter */} {locale === 'en' ? 'Categories' : 'Categorii'} {categories.map((category) => ( ))} {locale === 'en' ? 'Statistics' : 'Statistici'} {locale === 'en' ? ( <> • {prayers.length} active requests
• {prayers.reduce((sum, p) => sum + p.prayerCount, 0)} total prayers
• {prayers.filter(p => p.isPrayedFor).length} requests you prayed for ) : ( <> • {prayers.length} cereri active
• {prayers.reduce((sum, p) => sum + p.prayerCount, 0)} rugăciuni totale
• {prayers.filter(p => p.isPrayedFor).length} cereri la care te-ai rugat )}
{/* 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} {locale === 'en' ? `${prayer.prayerCount} ${prayer.prayerCount === 1 ? 'prayer' : 'prayers'}` : `${prayer.prayerCount} ${prayer.prayerCount === 1 ? 'rugăciune' : 'rugăciuni'}`} ) })} )}
{/* Add Prayer FAB */} setOpenDialog(true)} > {/* Add Prayer Dialog */} setOpenDialog(false)} maxWidth="sm" fullWidth > {locale === 'en' ? 'Add a prayer request' : 'Adaugă o cerere de rugăciune'} 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={locale === 'en' ? 'Describe your prayer request...' : 'Descrie cererea ta de rugăciune...'} />
) }