import React from "react"; import { View, Text, ScrollView, TouchableOpacity, Switch, Modal, useColorScheme, } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { Ionicons } from "@expo/vector-icons"; import { useAuth } from "../context/AuthContext"; import AuthGate from "./AuthGate"; // ─── Sub-components ──────────────────────────────────────────────────────── type SettingRowProps = { icon: any; label: string; value?: string; toggle?: boolean; toggleValue?: boolean; onToggle?: (v: boolean) => void; onPress?: () => void; accent?: string; }; function SettingRow({ icon, label, value, toggle, toggleValue, onToggle, onPress, accent }: SettingRowProps) { const dark = useColorScheme() === "dark"; const iconColor = accent ?? (dark ? "#706D67" : "#8A8278"); return ( {label} {toggle ? ( ) : value ? ( {value} ) : ( )} ); } function SectionLabel({ title }: { title: string }) { const dark = useColorScheme() === "dark"; return ( {title} ); } // ─── Guest profile (logged out) ──────────────────────────────────────────── function GuestProfile({ onSignIn }: { onSignIn: () => void }) { const dark = useColorScheme() === "dark"; const accent = dark ? "#E07B45" : "#C4622D"; return ( {/* Avatar block */} {/* Anonymous avatar */} Guest Sign in to sync your reading {/* Settings available to guests */} {}} /> {}} /> {/* Sign in / Register CTA */} Sign in / Register You can still browse and save locally without an account. ); } // ─── Authenticated profile (logged in) ──────────────────────────────────── function AuthenticatedProfile({ onSignOut }: { onSignOut: () => void }) { const dark = useColorScheme() === "dark"; const { user } = useAuth(); const [notifications, setNotifications] = React.useState(true); const [digest, setDigest] = React.useState(false); return ( {/* Avatar + name block */} 📰 {user?.email?.split("@")[0] ?? "Reader"} {user?.email} {/* Stats row */} {[ { label: "Subscribed", value: "5" }, { label: "Read", value: "128" }, { label: "Saved", value: "34" }, ].map((stat) => ( {stat.value} {stat.label} ))} {/* Settings sections */} {}} accent={dark ? "#4EC992" : "#2E9E6B"} /> {}} /> {}} /> {/* Sign out */} Sign out ); } // ─── Root export ─────────────────────────────────────────────────────────── export default function Profile() { const dark = useColorScheme() === "dark"; const { user, logout } = useAuth(); const [showAuth, setShowAuth] = React.useState(false); return ( {user ? : setShowAuth(true)} /> } {/* Login / Register modal */} setShowAuth(false)} > {/* Close handle */} {/* AuthGate auto-closes the modal on success because user becomes non-null */} setShowAuth(false)} /> ); }