import React, { useState, useCallback } from 'react' import { View, Text, ScrollView, StyleSheet, RefreshControl } from 'react-native' import { useFocusEffect } from 'expo-router' import { COLORS } from '../../constants/Config' import { getKPIDashboard } from '../../services/api' interface KPICardProps { label: string; current: number; target: number; unit?: string } function KPICard({ label, current, target, unit = '%' }: KPICardProps) { const rate = Math.min(100, Math.round((current / target) * 100)) const color = rate >= 100 ? COLORS.success : rate >= 80 ? COLORS.warning : COLORS.danger return ( {label} {current}{unit} 목표: {target}{unit} 달성률 {rate}% ) } const k = StyleSheet.create({ card: { backgroundColor: '#fff', borderRadius: 10, padding: 16, marginBottom: 10, elevation: 1 }, label: { fontSize: 13, color: COLORS.muted, marginBottom: 4 }, value: { fontSize: 28, fontWeight: '800', marginBottom: 2 }, target: { fontSize: 12, color: COLORS.muted, marginBottom: 8 }, barBg: { height: 6, backgroundColor: COLORS.border, borderRadius: 3, marginBottom: 4 }, barFill:{ height: 6, borderRadius: 3 }, rate: { fontSize: 12, fontWeight: '600' }, }) export default function KPIDashboardScreen() { const [kpi, setKPI] = useState(null) const [loading, setLoading] = useState(false) const load = useCallback(async () => { setLoading(true) try { const r = await getKPIDashboard(); setKPI(r.data) } catch { setKPI(null) } finally { setLoading(false) } }, []) useFocusEffect(useCallback(() => { load() }, [load])) if (!kpi) return null return ( } contentContainerStyle={{ padding: 12 }}> {kpi.period ?? ''} KPI 전체 SR: {kpi.total_sr}건 · 완료: {kpi.completed_sr}건 · SLA위반: {kpi.sla_breach}건 ) } const s = StyleSheet.create({ container: { flex: 1, backgroundColor: COLORS.bg }, period: { fontSize: 13, color: COLORS.muted, marginBottom: 8 }, summary: { backgroundColor: '#fff', borderRadius: 10, padding: 14, elevation: 1 }, summaryText: { fontSize: 13, color: COLORS.text }, })