import React, { useState } from 'react'; import { Text, View, TouchableOpacity, ScrollView, Switch, Image, } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import Icon from 'react-native-vector-icons/Ionicons'; import { getStyles } from './profile.styles'; import { useTheme } from '../../theme'; import { ProfileInfoRow } from '@components'; import { useAppDispatch, useAppSelector, logout, RootState } from '@store'; export const ProfileScreen = () => { const navigation = useNavigation(); const { theme: colors, isDark, toggleTheme } = useTheme(); const styles = getStyles(colors); const dispatch = useAppDispatch(); const [pushEnabled, setPushEnabled] = useState(true); const userData = useAppSelector((state: RootState) => state.auth.user_data); const handleLogout = async () => { try { dispatch(logout()); } catch (e) { console.error(e); } navigation.reset({ index: 0, routes: [{ name: 'AuthStack' }], }); }; // Derive user info const fullName = userData?.full_name || `${userData?.firstname || ''} ${userData?.lastname || ''}`.trim() || 'User Profile'; const email = userData?.email || 'N/A'; const phone = userData?.phonenumber || 'N/A'; const staffId = userData?.staffid ? `#${userData.staffid}` : 'N/A'; const isAdmin = userData?.admin === '1'; const roleText = isAdmin ? 'Administrator' : 'Staff Member'; const isActive = userData?.active === '1'; const hasProfileImage = userData?.profile_image && userData.profile_image.startsWith('http'); // Derive initials const initials = fullName .split(' ') .filter(Boolean) .map(n => n[0]) .join('') .substring(0, 2) .toUpperCase() || 'U'; const hasSocials = Boolean(userData?.linkedin) || Boolean(userData?.facebook) || Boolean(userData?.skype); return ( {/* ── Header Card ── */} {hasProfileImage ? ( ) : ( {initials} )} {isActive && } {fullName} {email} {roleText} {/* ── Stats Summary Row ── */} {userData?.staffid || '—'} Staff ID {userData?.total_unfinished_todos ?? '0'} Pending Todos {userData?.total_unread_notifications ?? '0'} Unread Alerts {/* ── Personal Details ── */} Personal Details {/* ── System & Account ── */} System & Account {userData?.default_language ? ( ) : null} {/* ── Social Profiles ── */} {hasSocials && ( Social Profiles {userData?.linkedin ? ( ) : null} {userData?.facebook ? ( ) : null} {userData?.skype ? ( ) : null} )} {/* ── Preferences ── */} Preferences Dark Mode {/* Push Notifications */} Push Notifications {/* ── Sign Out ── */} Sign Out ); };