import React, { useState, useCallback } from 'react' import { View, Text, FlatList, StyleSheet, RefreshControl, TouchableOpacity, Alert } from 'react-native' import { useFocusEffect } from 'expo-router' import { COLORS } from '../../constants/Config' import client from '../../services/api' export default function CitizenRequestsScreen() { const [items, setItems] = useState([]) const [loading, setLoading] = useState(false) const load = useCallback(async () => { setLoading(true) try { const r = await client.get('/api/citizen/requests'); setItems(r.data?.requests ?? r.data?.items ?? []) } catch { setItems([]) } finally { setLoading(false) } }, []) useFocusEffect(useCallback(() => { load() }, [load])) const assign = async (item: any) => { try { await client.post('/api/tasks', { title: `[민원] ${item.title ?? item.subject}`, description: item.description ?? item.content, priority: 'HIGH', sr_type: 'REQUEST', source: 'citizen_portal' }) Alert.alert('완료', 'SR로 전환됐습니다.') load() } catch { Alert.alert('오류', '전환에 실패했습니다.') } } return ( String(i)} refreshControl={} ListEmptyComponent={민원 접수 내역이 없습니다.} style={{ backgroundColor: COLORS.bg }} contentContainerStyle={{ padding: 12 }} ListHeaderComponent={시민 민원 접수 현황} renderItem={({ item }) => ( {item.title ?? item.subject} {item.citizen_name ?? '익명'} · {item.created_at?.slice(0, 16) ?? ''} {item.status === 'pending' ? '대기' : '처리중'} {item.description ?? item.content ?? ''} {item.status === 'pending' && ( assign(item)}> SR 전환 )} )} /> ) } const s = StyleSheet.create({ header: { fontSize: 16, fontWeight: '800', color: COLORS.text, marginBottom: 12 }, card: { backgroundColor: '#fff', borderRadius: 10, padding: 14, marginBottom: 8, elevation: 1 }, row: { flexDirection: 'row', alignItems: 'center', gap: 8, marginBottom: 6 }, title: { fontSize: 13, fontWeight: '700', color: COLORS.text }, meta: { fontSize: 11, color: COLORS.muted, marginTop: 2 }, statusBadge: { borderRadius: 4, paddingHorizontal: 8, paddingVertical: 3 }, statusText: { fontSize: 11, fontWeight: '700' }, desc: { fontSize: 12, color: COLORS.muted, marginBottom: 10 }, srBtn: { backgroundColor: COLORS.blue + '15', borderRadius: 6, padding: 8, alignItems: 'center' }, srText: { color: COLORS.blue, fontSize: 12, fontWeight: '700' }, empty: { textAlign: 'center', color: COLORS.muted, marginTop: 40 }, })