import { router } from 'expo-router';
import { Image } from 'expo-image';
import React from 'react';
import { Pressable, ScrollView, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import type { LucideIcon } from 'lucide-react-native';
import {
ChevronRight,
Download,
Globe,
HelpCircle,
Info,
LogOut,
MessageCircle,
Moon,
Pencil,
Trash2,
Type,
User,
} from 'lucide-react-native';
import { Icon } from '@/components/ui/icon';
import { Switch } from '@/components/ui/switch';
import { Text } from '@/components/ui/text';
import { resolveApiMediaUrl } from '@/core/api/media-url';
import { useAppSettings } from '@/hooks/use-app-settings';
import { useSession, useLogout } from '@/features/auth/hooks';
import { useCurrentPlan } from '@/features/profile/hooks';
function SectionCard({
title,
icon: SectionIcon,
children,
}: {
title: string;
icon: LucideIcon;
children: React.ReactNode;
}) {
return (
{title}
{children}
);
}
function RowButton({
icon: RowIcon,
label,
onPress,
}: {
icon: LucideIcon;
label: string;
onPress?: () => void;
}) {
return (
{label}
);
}
function LanguageRow({
label,
description,
currentLabel,
onPress,
}: {
label: string;
description: string;
currentLabel: string;
onPress: () => void;
}) {
return (
{label}
{description}
{currentLabel}
);
}
function SettingRow({
icon: SettingIcon,
label,
description,
value,
onValueChange,
}: {
icon: LucideIcon;
label: string;
description: string;
value: boolean;
onValueChange: (value: boolean) => void;
}) {
return (
{label}
{description}
);
}
function planDisplayName(
subscriptionType: string | undefined,
planName?: string,
) {
if (planName) return planName;
switch (subscriptionType) {
case 'free':
return 'Free';
case 'pro':
case 'premium':
return 'Pro';
case 'pro_plus':
return 'Pro+';
default:
return 'Free';
}
}
export default function ProfileScreen() {
const { t } = useTranslation('profile');
const { t: tApp } = useTranslation('app');
const { user } = useSession();
const logout = useLogout();
const { data: currentPlan } = useCurrentPlan();
const {
ready: settingsReady,
language,
hasLanguageOverride,
languageOptions,
themeName,
themeOptions,
largeText,
changeLargeText,
darkMode,
changeDarkMode,
} = useAppSettings();
const tierLabel =
currentPlan?.plan_name ?? planDisplayName(user?.subscription_type);
const currentLanguageLabel =
hasLanguageOverride && language
? (languageOptions.find((o) => o.code === language)?.label ?? language)
: tApp('languages.system');
const currentThemeLabel =
themeOptions.find((o) => o.value === themeName)?.label ??
tApp('theme.default');
const avatarUri = resolveApiMediaUrl(user?.avatar_url ?? null);
return (
{/* Profile header */}
{avatarUri ? (
) : (
)}
router.push('/(main)/personal-info')}
>
{user?.nickname ?? t('userNamePlaceholder')}
{t('userTier', { tier: tierLabel })}
{/* App Experience */}
{settingsReady && (
router.push('/(main)/language')}
/>
)}
{settingsReady && (
router.push('/(main)/theme')}
/>
)}
{/* Data & Privacy */}
router.push('/(main)/export-data')}
/>
router.push('/(main)/delete-data')}
/>
{/* Help & Support */}
router.push('/(main)/faq')}
/>
router.push('/(main)/feedback')}
/>
{/* About */}
router.push('/(main)/about')}
/>
{/* Sign out */}
logout.mutate()}
disabled={logout.isPending}
>
{logout.isPending ? t('signingOut') : t('signOut')}
);
}