import { Image, Text, TouchableOpacity, View } from "react-native-ui-lib"; import React, { useEffect, useState } from "react"; import { ProfileType, useAuthContext } from "@/contexts/AuthContext"; import { StyleSheet } from "react-native"; import { colorMap } from "@/constants/colorMap"; import { useAtom, useSetAtom } from "jotai"; import { isFamilyViewAtom, settingsPageIndex } from "../pages/calendar/atoms"; import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers"; import { UserProfile } from "@/hooks/firebase/types/profileTypes"; import CachedImage from "expo-cached-image"; import { router } from "expo-router"; const HeaderTemplate = (props: { message: string; isWelcome: boolean; children?: React.ReactNode; link?: React.ReactNode; isCalendar?: boolean; isToDos?: boolean; isBrainDump?: boolean; isGroceries?: boolean; }) => { const { user, profileData } = useAuthContext(); const { data: members, refetch } = useGetFamilyMembers(); const [children, setChildren] = useState([]); const [isFamilyView] = useAtom(isFamilyViewAtom); const setSettingsPageIndexAtom = useSetAtom(settingsPageIndex); const headerHeight: number = (props.isCalendar && 65.54) || (props.isToDos && 84) || (props.isGroceries && 72.09) || 65.54; const handlePfpPress = () => { setSettingsPageIndexAtom(1); router.push("/settings"); }; const styles = StyleSheet.create({ pfp: { height: headerHeight, aspectRatio: 1, borderRadius: 22, overflow: "hidden", marginRight: 20, backgroundColor: profileData?.eventColor ?? colorMap.pink, zIndex: 100, }, pfpTxt: { fontFamily: "Manrope_500Medium", fontSize: 30, color: "white", }, childrenPfpArr: { width: 65.54, position: "absolute", bottom: -12.44, left: (children.length > 3 && -9) || 0, height: 27.32, }, childrenPfp: { aspectRatio: 1, width: 27.32, backgroundColor: "#fd1575", borderRadius: 50, position: "absolute", borderWidth: 2, borderColor: "#f2f2f2", }, bottomMarg: { marginBottom: isFamilyView ? 30 : 15, }, }); useEffect(() => { if (members) { const childrenMembers = members.filter( (member) => member.userType === ProfileType.CHILD || member.userType === ProfileType.CAREGIVER || member.userType === ProfileType.PARENT ); setChildren(childrenMembers); } }, []); return ( {profileData?.pfp ? ( {isFamilyView && props.isCalendar && children.length > 0 && ( {children.slice(0, 3).map((child, index) => { const bgColor: string = child.eventColor || colorMap.pink; return child.pfp ? ( ) : ( {child?.firstName?.at(0)} {child?.firstName?.at(1)} ); })} {children?.length > 3 && ( +{children.length - 3} )} )} ) : ( <> {profileData?.firstName?.at(0)} {profileData?.lastName?.at(0)} {isFamilyView && props.isCalendar && children.length > 0 && ( {children.slice(0, 3).map((child, index) => { const bgColor: string = child.eventColor || colorMap.pink; return child.pfp ? ( ) : ( {child?.firstName?.at(0)} {child?.firstName?.at(1)} ); })} {children?.length > 3 && ( +{children.length - 3} )} )} )} {props.isWelcome && ( Welcome, {profileData?.firstName}! )} {props.message} {props.children && {props.children}} {props.link && {props.link}} ); }; export default HeaderTemplate;