eletrotupi / tcc/ frontend/components/history/MoodHistoryCard.tsx4db43b4346d1ef046417a8d12030155b577ed0c1
3.3 KB | 110 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

18
  return undefined
19
}
20

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

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

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

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

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

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