eletrotupi / tcc/ frontend/components/history/MoodHistoryCard.tsxd09369f13e0c0517549a86d62451cfad5d8d5616
3.3 KB | 109 lines Raw
1
// components/history/cards/MoodHistoryCard.tsx
2
import { View, StyleSheet } from 'react-native';
3
import { Text } from '@/components/ui/Text';
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
        </View>
45
        <View style={styles.body}>
46
          <View style={styles.titleRow}>
47
            <Text style={styles.title}>{moodDef?.label ?? card.raw.selectedMood}</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
})