import React, { useState } 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";
import ManageSubscriptions from "@/screens/ManageSubscriptions";
import EditProfile from "@/screens/EditProfile";
import HelpSupport from "@/screens/HelpSupport";
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}
);
}
function GuestProfile({ onSignIn }: { onSignIn: () => void }) {
const dark = useColorScheme() === "dark";
const accent = dark ? "#E07B45" : "#C4622D";
const [showHelp, setShowHelp] = useState(false);
return (
<>
{/* Avatar block */}
Guest
Sign in to sync your reading
{/* Settings available to guests */}
setShowHelp(true)}
/>
setShowHelp(true)}
/>
{/* Sign in / Register CTA */}
Sign in / Register
You can still browse and save locally without an account.
setShowHelp(false)}
>
setShowHelp(false)} />
>
);
}
function AuthenticatedProfile({ onSignOut }: { onSignOut: () => void }) {
const [showSubs, setShowSubs] = useState(false);
const dark = useColorScheme() === "dark";
const { user } = useAuth();
const [notifications, setNotifications] = React.useState(true);
const [digest, setDigest] = React.useState(false);
const [showEdit, setShowEdit] = useState(false);
const [showHelp, setShowHelp] = useState(false);
return (
<>
{/* Avatar + name block */}
📰
{user?.email?.split("@")[0] ?? "Reader"}
{user?.email}
{/* Stats row */}
{user?.subscribedSubjectIds?.length ?? 0}
Subscribed
{/* Settings sections */}
setShowSubs(true)}
accent={dark ? "#4EC992" : "#2E9E6B"}
/>
setShowEdit(true)} />
setShowHelp(true)} />
{/* Sign out */}
Sign out
setShowEdit(false)}>
setShowEdit(false)} />
setShowHelp(false)}>
setShowHelp(false)} />
setShowSubs(false)}
>
setShowSubs(false)} />
>
);
}
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)} />
);
}