import { useCallback, useState } from 'react' import { View, Text, ScrollView, StyleSheet, TouchableOpacity } from 'react-native' import { router, useFocusEffect } from 'expo-router' import { Feather } from '@expo/vector-icons' import { useTheme } from '../../constants/ThemeContext' import { type PrefMode } from '../../constants/ThemeContext' import { type ThemeTokens } from '../../constants/ItmsTheme' import { Card, Row, SectionTitle, Btn } from '../../components/ui' import { API_BASE, ITMS_ENV } from '../../constants/Config' import { itmsProfile, clearItmsSession, type ItmsProfile } from '../itmsApi' /* * 내 정보 — 토큰에서 도출한 프로필(userName·roles·email·org) + 테마 모드 + 로그아웃. * ITMS 백엔드에는 preferences API 가 없어 테마는 로컬 저장만. */ export default function Me() { const { t, mode, setMode } = useTheme() const s = makeStyles(t) const [me, setMe] = useState(null) useFocusEffect(useCallback(() => { let alive = true itmsProfile().then((p) => { if (alive) setMe(p) }).catch(() => { /* noop */ }) return () => { alive = false } }, [])) const logout = async () => { await clearItmsSession() router.replace('/login') } const modes: { key: PrefMode; label: string; icon: keyof typeof Feather.glyphMap }[] = [ { key: 'light', label: '라이트', icon: 'sun' }, { key: 'dark', label: '다크', icon: 'moon' }, { key: 'system', label: '시스템', icon: 'smartphone' }, ] return ( {(me?.userNm || 'I').slice(0, 1)} {me?.userNm || '-'} {me?.userId ? `@${me.userId}` : ''} {me?.roles && me.roles.length > 0 && ( {me.roles.map((r) => ( {r.replace(/^ROLE_/, '')} ))} )} 계정 정보 화면 테마 {modes.map((m) => { const on = mode === m.key return ( setMode(m.key)}> {m.label} ) })} 앱 정보 ) } const makeStyles = (t: ThemeTokens) => StyleSheet.create({ wrap: { flex: 1, backgroundColor: t.bg }, content: { padding: 16 }, profileHead: { alignItems: 'center', paddingVertical: 20 }, avatar: { width: 72, height: 72, borderRadius: 36, backgroundColor: t.brand, justifyContent: 'center', alignItems: 'center' }, avatarText: { color: t.onBrand, fontSize: 30, fontWeight: '900' }, name: { color: t.text, fontSize: 20, fontWeight: '900', marginTop: 12 }, sub: { color: t.muted, fontSize: 13, marginTop: 2 }, roleRow: { flexDirection: 'row', flexWrap: 'wrap', gap: 6, marginTop: 10, justifyContent: 'center' }, roleBadge: { backgroundColor: t.brand + '1a', borderRadius: 8, paddingHorizontal: 10, paddingVertical: 4 }, roleText: { color: t.brand, fontSize: 11, fontWeight: '800' }, mt: { marginTop: 22 }, modeRow: { flexDirection: 'row', gap: 10 }, modeCell: { flex: 1, backgroundColor: t.card, borderRadius: 12, borderWidth: 1, borderColor: t.border, paddingVertical: 16, alignItems: 'center', gap: 6 }, modeLbl: { fontSize: 12, fontWeight: '700' }, })