import { useMemo, useState } from "react" import { FlatList, Pressable, Text, View } from "react-native" import { router } from "expo-router" import { useSafeAreaInsets } from "react-native-safe-area-context" import { Image } from "expo-image" import { useAuthContext } from "@/hooks/use-auth-context" import { useNotes } from "@/src/notes/NotesContext" import SignOutButton from '@/components/social-auth-buttons/sign-out-button' import { useAppTheme } from "@/src/theme/AppThemeProvider" import { homeScreenStyles as styles } from "@/src/styles/app-styles" type TabKey = "my-notes" | "work-notes" export default function HomeScreen() { const { claims } = useAuthContext() const { errorMessage, isLoading, notes } = useNotes() const [activeTab, setActiveTab] = useState("my-notes") const insets = useSafeAreaInsets() const { colorScheme, palette } = useAppTheme() const userId = claims?.sub const filteredNotes = useMemo( () => notes.filter((note) => activeTab === "my-notes" ? note.createdBy === userId : note.createdBy !== userId ), [activeTab, notes, userId] ) const emptyText = activeTab === "my-notes" ? "No personal notes yet. Create your first note." : "No work notes yet." const formatTimestamp = (value: string) => { const parsed = new Date(value) if (Number.isNaN(parsed.getTime())) { return "Unknown" } return parsed.toLocaleString() } return ( FastNotes setActiveTab("my-notes")} style={[ styles.tabButton, { backgroundColor: palette.elevated, borderColor: palette.border }, activeTab === "my-notes" ? styles.tabButtonActive : null, ]} > My Notes setActiveTab("work-notes")} style={[ styles.tabButton, { backgroundColor: palette.elevated, borderColor: palette.border }, activeTab === "work-notes" ? styles.tabButtonActive : null, ]} > Work Notes {errorMessage ? {errorMessage} : null} n.id} contentContainerStyle={[styles.list, { paddingBottom: 120 }]} ListEmptyComponent={ {isLoading ? "Loading notes..." : emptyText} } renderItem={({ item }) => ( router.push({ pathname: "/detail", params: { id: item.id }, }) } > {item.title} {item.content} Created by {item.creatorLabel} Last changed {formatTimestamp(item.lastChangedAt)} {item.imageUrl ? ( ) : null} )} /> {activeTab === "my-notes" ? ( router.push("/newNote")} > + ) : null} ) }