import React, { useEffect, useState } from 'react'; import { View, useWindowDimensions, type ImageSourcePropType } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useAuth } from '@/hooks/use-auth'; import { useProfileData } from '@/hooks/use-profile-data'; import { createStats, deriveAvatarSource, deriveDisplayName, deriveNumericValue } from '@/utils/profile-data'; import { StyleSheet } from 'react-native'; import { ContentGallery } from './content-gallery'; import { ContentTabs } from './content-tabs'; import { Divider } from './divider'; import { ProfileEditModal } from './profile-edit-modal'; import { ProfileEmptyState } from './profile-empty-state'; import { ProfileErrorState } from './profile-error-state'; import { ProfileHeader } from './profile-header'; import { ProfileIdentity } from './profile-identity'; import { ProfileLoadingState } from './profile-loading-state'; import { ContentSkeleton } from './content-skeleton'; type TabKey = 'all' | 'image' | 'video'; type BillingMode = 'monthly' | 'lifetime'; export function ProfileScreen() { const { user } = useAuth(); const { width } = useWindowDimensions(); const insets = useSafeAreaInsets(); const [billingMode, setBillingMode] = useState('monthly'); const [activeTab, setActiveTab] = useState('all'); const displayNameFromUser = deriveDisplayName(user) ?? 'prairie_pufferfish_the'; const [presentedDisplayName, setPresentedDisplayName] = useState(displayNameFromUser); const [isEditingIdentity, setIsEditingIdentity] = useState(false); const { generations, isLoading, error, isRefreshing, isLoadingMore, hasMore, handleRefresh, handleLoadMore, } = useProfileData(activeTab); const horizontalPadding = width < 400 ? 20 : 24; const avatarSize = width < 400 ? 74 : 82; const avatarSource = deriveAvatarSource(user); const creditBalance = deriveNumericValue((user as Record)?.credits); const stats = createStats(user); const [presentedAvatar, setPresentedAvatar] = useState(avatarSource); useEffect(() => { setPresentedDisplayName(displayNameFromUser); }, [displayNameFromUser]); useEffect(() => { setPresentedAvatar(avatarSource); }, [avatarSource]); if (isLoading) { return ( {insets.top > 0 && } ); } if (error) { return ( {insets.top > 0 && } ); } return ( {insets.top > 0 && } setIsEditingIdentity(true)} /> 0} /> {isLoading && generations.length === 0 ? ( ) : generations.length === 0 ? ( ) : ( )} setIsEditingIdentity(false)} onSave={({ name, avatar }) => { setPresentedDisplayName(name); if (avatar) { setPresentedAvatar(avatar); } setIsEditingIdentity(false); }} /> ); } const stylesVars = { background: '#050505', paddingBottom: 96, }; const styles = StyleSheet.create({ screen: { flex: 1, }, galleryContainer: { paddingTop: 8, }, }); export default ProfileScreen;