import { useEffect, useState } from 'react' import { View, Text, ScrollView, StyleSheet, TouchableOpacity, RefreshControl, ActivityIndicator } from 'react-native' import { COLORS, PRIORITY_COLOR } from '../../constants/Config' import { getDashboard, getLicenseStatus } from '../../services/api' import { useAuth } from '../../hooks/useAuth' interface Stats { total_tasks: number open_tasks: number in_progress_tasks: number completed_today: number critical_count: number pending_approvals: number recent_tasks?: any[] } function StatCard({ icon, label, value, color }: { icon: string; label: string; value: number | string; color: string }) { return ( {icon} {value} {label} ) } export default function Dashboard() { const { user } = useAuth() const [stats, setStats] = useState(null) const [license, setLicense] = useState(null) const [loading, setLoading] = useState(true) const [refresh, setRefresh] = useState(false) const load = async (isRefresh = false) => { if (isRefresh) setRefresh(true) else setLoading(true) try { const [d, l] = await Promise.allSettled([getDashboard(), getLicenseStatus()]) if (d.status === 'fulfilled') setStats(d.value.data) if (l.status === 'fulfilled') setLicense(l.value.data) } catch {} setLoading(false) setRefresh(false) } useEffect(() => { load() }, []) if (loading) return ( 로딩 중... ) return ( load(true)} />} > {/* 인사말 */} 안녕하세요, {user?.display_name ?? user?.username}님 👋 GUARDiA ITSM 현황을 확인하세요 {/* 라이선스 배너 */} {license?.upgrade_banner?.show && ( ⚠️ {license.upgrade_banner.message} )} {license?.valid && ( {license.edition} {license.days_remaining}일 남음 )} {/* 통계 카드 */} {/* 최근 SR */} {stats?.recent_tasks && stats.recent_tasks.length > 0 && ( 📋 최근 서비스 요청 {stats.recent_tasks.slice(0, 5).map((sr: any) => ( {sr.title} {sr.sr_id} · {sr.status} ))} )} {/* 빠른 실행 */} ⚡ 빠른 실행 {[ { icon: '📝', label: 'SR 등록' }, { icon: '🤖', label: 'AI 질문' }, { icon: '📊', label: '리포트' }, { icon: '🔒', label: '감사로그' }, ].map(q => ( {q.icon} {q.label} ))} ) } const s = StyleSheet.create({ scroll: { flex: 1, backgroundColor: COLORS.bg }, center: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: COLORS.bg }, header: { backgroundColor: COLORS.primary, padding: 24, paddingTop: 16 }, greeting: { fontSize: 20, fontWeight: '700', color: '#fff' }, subGreet: { fontSize: 13, color: '#aac4e8', marginTop: 4 }, licenseBanner: { backgroundColor: '#fff3cd', padding: 12, marginHorizontal: 16, marginTop: 12, borderRadius: 8, borderLeftWidth: 3, borderLeftColor: COLORS.warning }, licenseBannerText: { fontSize: 12, color: '#856404' }, licenseBar: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', backgroundColor: COLORS.light, marginHorizontal: 16, marginTop: 8, paddingHorizontal: 14, paddingVertical: 8, borderRadius: 8 }, licenseEdition: { fontSize: 12, fontWeight: '700', color: COLORS.accent }, licenseDays: { fontSize: 12, color: COLORS.muted }, statsGrid: { flexDirection: 'row', flexWrap: 'wrap', padding: 12, gap: 8 }, statCard: { width: '47%', backgroundColor: '#fff', borderRadius: 10, padding: 14, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: .06, shadowRadius: 6, elevation: 2 }, statIcon: { fontSize: 22, marginBottom: 6 }, statValue: { fontSize: 26, fontWeight: '800', color: COLORS.text }, statLabel: { fontSize: 11, color: COLORS.muted, marginTop: 2 }, section: { backgroundColor: '#fff', marginHorizontal: 16, marginTop: 12, borderRadius: 12, padding: 16, elevation: 1 }, sectionTitle: { fontSize: 14, fontWeight: '700', color: COLORS.text, marginBottom: 12 }, srItem: { flexDirection: 'row', alignItems: 'center', gap: 10, paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: '#f1f5f9' }, priorityDot: { width: 8, height: 8, borderRadius: 4 }, srTitle: { fontSize: 13, fontWeight: '500', color: COLORS.text }, srMeta: { fontSize: 11, color: COLORS.muted, marginTop: 2 }, quickRow: { flexDirection: 'row', justifyContent: 'space-around' }, quickBtn: { alignItems: 'center', padding: 12 }, quickIcon: { fontSize: 28, marginBottom: 4 }, quickLabel: { fontSize: 11, color: COLORS.muted }, })