import { FlatList, View } from "react-native" import { Button, List, Text } from "react-native-paper" import { useMemo, useState } from "react" import { useRouter } from "expo-router" import type { GoalFrequency } from "@/domain/entities/Goal" import { GOAL_FREQUENCIES } from "@/domain/entities/Goal" import type { HabitsTracker } from "@/domain/entities/HabitsTracker" import { capitalize } from "@/presentation/presenters/utils/strings" import { HabitHistory } from "./HabitHistory" export interface HabitsHistoryProps { habitsTracker: HabitsTracker } export const HabitsHistory: React.FC = (props) => { const { habitsTracker } = props const router = useRouter() const habitsByFrequency = useMemo(() => { return GOAL_FREQUENCIES.filter((frequency) => { return habitsTracker.habitsHistory[frequency].length > 0 }) }, [habitsTracker]) const [accordionExpanded, setAccordionExpanded] = useState<{ [key in GoalFrequency]: boolean }>({ daily: true, weekly: true, monthly: true, }) if (habitsByFrequency.length <= 0) { return ( {"Let's begin by adding habits! 🤩"} ) } return ( {habitsByFrequency.map((frequency) => { return ( { setAccordionExpanded((old) => { return { ...old, [frequency]: !old[frequency], } }) }} key={frequency} title={capitalize(frequency)} titleStyle={[ { fontSize: 26, }, ]} > { return }} /> ) })} ) }