import React, { useState, useRef, useEffect } from 'react'; import { View, Text, StyleSheet, ScrollView, Pressable, Animated, KeyboardAvoidingView, Platform, } from 'react-native'; import { showAlert } from '../components/NovaAlert'; import ScreenWrapper from '../components/ScreenWrapper'; import Input from '../components/Input'; import Button from '../components/Button'; import useIdentityStore from '../store/useIdentityStore'; import useHabitStore from '../store/useHabitStore'; import { generateDailyReflection, saveDailyJournal } from '../services/journalService'; import { colors, fonts, spacing, borderRadius } from '../utils/theme'; const MOODS = [ { key: 'great', emoji: '😄', label: 'Great' }, { key: 'good', emoji: '🙂', label: 'Good' }, { key: 'okay', emoji: '😐', label: 'Okay' }, { key: 'bad', emoji: '😔', label: 'Bad' }, { key: 'terrible', emoji: '😞', label: 'Terrible' }, ]; const IDENTITY_OPTIONS = [ { key: 'yes', label: 'Yes', color: colors.success }, { key: 'almost', label: 'Almost', color: colors.warning }, { key: 'no', label: 'No', color: colors.error }, ]; export default function DailyJournalScreen({ navigation }) { const identity = useIdentityStore((s) => s.identity); const currentDay = useIdentityStore((s) => s.currentDay); const habits = useHabitStore((s) => s.habits); const habitLogs = useHabitStore((s) => s.habitLogs); const [mood, setMood] = useState(''); const [win, setWin] = useState(''); const [struggle, setStruggle] = useState(''); const [highlight, setHighlight] = useState(''); const [note, setNote] = useState(''); const [identityCheck, setIdentityCheck] = useState(''); const [saving, setSaving] = useState(false); const fadeAnim = useRef(new Animated.Value(0)).current; useEffect(() => { Animated.timing(fadeAnim, { toValue: 1, duration: 500, useNativeDriver: true }).start(); }, []); const habitsCompleted = Object.values(habitLogs).filter(Boolean).length; const handleSave = async () => { if (!mood) { showAlert('Mood', 'How are you feeling today?'); return; } if (!identityCheck) { showAlert('Identity Check', 'Did you embody your identity today?'); return; } setSaving(true); try { // Generate AI reflection const ai = await generateDailyReflection({ mood, win, struggle, highlight, note }); // Save everything await saveDailyJournal(identity.id, currentDay, { identityCheck, habitsCompleted, mood, win, struggle, highlight, note, aiTitle: ai.title, aiSummary: ai.summary, aiQuote: ai.quote, }); // Navigate to result navigation.navigate('JournalResult', { aiTitle: ai.title, aiSummary: ai.summary, aiQuote: ai.quote, source: ai.source, dayNumber: currentDay, date: new Date().toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' }), mood, identityTitle: identity?.title, }); } catch (e) { console.warn('Journal save error:', e); showAlert('Error', e?.message || 'Failed to save. Try again.'); } finally { setSaving(false); } }; return ( {/* Header */} Daily Journal Day {currentDay} — How was your day? {/* Mood */} How are you feeling? {MOODS.map((m) => ( setMood(m.key)} > {m.emoji} {m.label} ))} {/* Identity Check */} Did you embody "{identity?.title}"? {IDENTITY_OPTIONS.map((opt) => ( setIdentityCheck(opt.key)} > {opt.label} ))} {/* Habits summary */} {habitsCompleted}/{habits.length} habits completed today {/* Journal inputs */} {/* Save */}