eletrotupi / tcc/ frontend/components/history/MoodHistoryCard.tsx8285983ad71045e275851b9ddbc14e82c92164e0
3.2 KB | 109 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

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

17
  return undefined
18
}
19

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

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

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

37
  return (
38
    <Card style={styles.card}>
39
      <View style={styles.row}>
40
        <View style={[styles.iconWrap, { backgroundColor: meta.bg }]}>
41
          <Text style={styles.moodIconEmoji}>{moodDef?.icon ?? '😐'}</Text>
42

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

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