eletrotupi / tcc/ frontend/components/insights/MoodTrendWidget.tsxa0a4482072edfe23736af02ec22bbbf6e2c8d3b9
1.9 KB | 89 lines Raw
1
import React from "react";
2
import { StyleSheet, ActivityIndicator } from "react-native";
3
import { Text } from "@/components/ui/Text";
4
import { Card } from "@/components/ui/Cards";
5
import { useInsight } from "@/hooks/useInsights.queries";
6
import { Colors, Spacing, Typography } from "@/constants/theme";
7
import { InsightCard } from "./InsightCard";
8

9
export const MoodTrendWidget: React.FC = () => {
10
  const { data: insight, isLoading } = useInsight("MOOD_TREND");
11

12
  if (isLoading) {
13
    return (
14
      <Card style={styles.container}>
15
        <ActivityIndicator />
16
      </Card>
17
    );
18
  }
19

20
  if (!insight) {
21
    return (
22
      <InsightCard
23
        category="Humor"
24
        body={
25
          <Text style={styles.empty}>
26
            Registre seu humor com mais frequência para acompanhar suas
27
            tendências.
28
          </Text>
29
        }
30
        accent="neutral"
31
        metric="—"
32
      />
33
    );
34
  }
35

36
  const metadata = insight.metadata as {
37
    delta: number;
38
    dominantMood: string;
39
    avgEnergy: number;
40
  };
41

42
  const metric = metadata?.delta ? `${Math.round(metadata.delta)}%` : "N/A";
43

44
  const accent = metadata?.delta
45
    ? metadata.delta < 0
46
      ? "purple"
47
      : "green"
48
    : "green";
49

50
  return (
51
    <InsightCard
52
      category="Humor"
53
      body={insight.body}
54
      metric={metric}
55
      accent={accent}
56
      footnote="Compara a média de humor da primeira e segunda metade da semana (escala 1–5)."
57
    />
58
  );
59
};
60

61
const styles = StyleSheet.create({
62
  container: {
63
    flex: 1,
64
    padding: Spacing.cardGap,
65
  },
66
  header: {
67
    flexDirection: "row",
68
    alignItems: "center",
69
    gap: 4,
70
    marginBottom: 5,
71
  },
72
  label: {
73
    ...Typography.labelSm,
74
    opacity: 0.6,
75
  },
76
  value: {
77
    ...Typography.labelSm,
78
    fontWeight: "600" as const,
79
  },
80
  delta: {
81
    ...Typography.labelSm,
82
    opacity: 0.6,
83
    marginTop: 2,
84
  },
85
  empty: {
86
    color: Colors.light.lightSlateGray,
87
    marginTop: 4,
88
  },
89
});