eletrotupi / tcc/ frontend/components/history/MoodHistoryCard.tsx3213901cb6f40e18df4c191a91f7a34b28de7a6d
3.4 KB | 111 lines Raw
1
// components/history/cards/MoodHistoryCard.tsx
2
import { View, Text, StyleSheet } from 'react-native';
3
import { MaterialIcons } from '@expo/vector-icons';
4
import { Card } from '@/components/ui/Cards';
5
import { Badge } from '@/components/ui/Badge';
6
import type { HistoryCard } from '@/lib/history/types';
7
import type { MoodEntry } from '@/lib/api';
8
import { Spacing } from '@/constants/theme';
9
import { getMood } from '@/constants/moods';
10
import { format } from 'date-fns';
11
import { router } from 'expo-router';
12

13
function inferBadge(anxiety: number, stress: number, energy: number) {
14
  if (anxiety >= 7) return { label: 'Ansiedade alta', variant: 'red'    } as const
15
  if (stress  >= 7) return { label: 'Estresse alto',  variant: 'orange' } as const
16
  if (energy  <= 3) return { label: 'Energia baixa',  variant: 'yellow' } as const
17
  if (energy  >= 7) return { label: 'Energia alta', variant: 'green' } as const
18

19
  return undefined
20
}
21

22
// TODO: Perhaps we could move these into the constants instead and use it everywhere?
23
const MOOD_META: Record<string, { color: string; bg: string }> = {
24
  GREAT:   { color: '#16a34a', bg: '#dcfce7' },
25
  GOOD:    { color: '#2563eb', bg: '#dbeafe' },
26
  NEUTRAL: { color: '#d97706', bg: '#fef3c7' },
27
  SAD:     { color: '#7c3aed', bg: '#ede9fe' },
28
  ANGRY:   { color: '#dc2626', bg: '#fee2e2' },
29
}
30

31
type Props = { card: HistoryCard & { raw: MoodEntry } }
32

33
export function MoodHistoryCard({ card }: Props) {
34
  const meta = MOOD_META[card.raw.selectedMood] ?? MOOD_META.NEUTRAL
35
  const badge = inferBadge(card.raw.anxietyLevel, card.raw.stressLevel, card.raw.energyLevel)
36
  const time = format(card.timestamp, 'HH:mm')
37
  const moodDef = getMood(card.raw.selectedMood.toLowerCase());
38

39
  return (
40
    <Card style={styles.card} onPress={() => router.push(`/entry/${card.raw.id}`)}>
41
      <View style={styles.row}>
42
        <View style={[styles.iconWrap, { backgroundColor: meta.bg }]}>
43
          <Text style={styles.moodIconEmoji}>{moodDef?.icon ?? '😐'}</Text>
44

45
          {false && (<MaterialIcons name={meta.icon} size={22} color={meta.color} />)}
46
        </View>
47
        <View style={styles.body}>
48
          <View style={styles.titleRow}>
49
            <Text style={styles.title}>{moodDef.label}</Text>
50
            <Text style={styles.time}>{time}</Text>
51
          </View>
52
          {card.raw.annotation ? (
53
            <Text style={styles.summary} numberOfLines={2}>
54
              {card.raw.annotation?.trim()}
55
            </Text>
56
          ) : null}
57
          {(badge ? (<Badge label={badge.label} variant={badge.variant} style={styles.badge}/>) : null)}
58
        </View>
59
      </View>
60
    </Card>
61
  )
62
}
63

64
const styles = StyleSheet.create({
65
  card: {
66
    padding: Spacing.cardGap
67
  },
68
  row: {
69
    flexDirection: 'row',
70
    alignItems: 'flex-start',
71
    gap: 12
72
  },
73
  iconWrap: {
74
    width: 40,
75
    height: 40,
76
    borderRadius: 20,
77
    alignItems: 'center',
78
    justifyContent: 'center',
79
    marginTop: 1
80
  },
81
  body: { flex: 1 },
82
  titleRow: {
83
    flexDirection: 'row',
84
    justifyContent: 'space-between',
85
    alignItems: 'center',
86
    marginBottom: 2
87
  },
88
  title: {
89
    fontSize: 15,
90
    fontWeight: '600'
91
  },
92
  moodIconEmoji: {
93
    fontSize: 26,
94
  },
95
  time: {
96
    fontSize: 13,
97
    opacity: 0.45
98
  },
99
  summary: {
100
    fontSize: 13,
101
    opacity: 0.6,
102
    lineHeight: 18,
103
    marginBottom: 6,
104
    fontStyle: 'italic'
105
  },
106
  badge: {
107
    alignSelf: 'flex-start',
108
    marginTop: 4,
109
    maxWidth: '50%'
110
  }
111
})