import React, { useState, useCallback } from 'react'; import { View, Text, StyleSheet, FlatList, ActivityIndicator, TouchableOpacity, RefreshControl, SafeAreaView } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useNavigation, useFocusEffect } from '@react-navigation/native'; import { StatusBar } from 'expo-status-bar'; import apiService from '../../services/apiService'; import { COLORS } from '../../constants/colors'; import { useBaseEnums } from '../../contexts/BaseEnumsContext'; const CARD_BG = '#F1F9F1'; const CIRCLE_BG = '#A2E4A4'; const CardPinOrdersScreen = () => { const navigation = useNavigation(); const [orders, setOrders] = useState([]); const { getLabel } = useBaseEnums(); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const fetchOrders = async () => { try { const res = await apiService.getCardPinOrders(); if (res.success) { setOrders(Array.isArray(res.data) ? res.data : []); } else { console.warn(res.error); } } catch (e) { console.warn(e.message); } finally { setLoading(false); setRefreshing(false); } }; useFocusEffect( useCallback(() => { fetchOrders(); }, []) ); const onRefresh = () => { setRefreshing(true); fetchOrders(); }; const handleItemPress = (item) => { navigation.navigate('CardPinOrderDetails', { orderId: item.id }); }; const renderItem = ({ item }) => { const masked = item.card_number ? `${item.card_number.slice(0,6)}******${item.card_number.slice(-4)}` : ''; const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : ''; const typeLabel = getLabel('card_types', item.card_type_id); const passportLine = item.passport_serie && item.passport_id ? `${item.passport_serie} ${item.passport_id}` : ''; return ( handleItemPress(item)}> {item.id} {masked} {typeLabel && {typeLabel}} {passportLine !== '' && {passportLine}} {created} ); }; if (loading) { return ( ); } return ( navigation.goBack()} style={{ paddingRight: 12 }}> Kart pin bukjalar item.id?.toString()} renderItem={renderItem} contentContainerStyle={orders.length === 0 && styles.emptyContainer} refreshControl={} ListEmptyComponent={Heniz sargyt ýok} /> navigation.navigate('CreateCardPinOrder')}> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: COLORS.backgroundSecondary }, centered: { flex: 1, alignItems: 'center', justifyContent: 'center' }, header: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 24, paddingVertical: 16 }, headerTitle: { fontSize: 20, fontWeight: 'bold', color: COLORS.textPrimary }, card: { flexDirection: 'row', backgroundColor: CARD_BG, marginHorizontal: 24, marginTop: 16, borderRadius: 12, padding: 16, alignItems: 'center' }, circle: { width: 40, height: 40, borderRadius: 20, backgroundColor: CIRCLE_BG, alignItems: 'center', justifyContent: 'center', marginRight: 16 }, circleText: { color: COLORS.white, fontWeight: '600' }, cardContent: { flex: 1 }, cardNumber: { fontWeight: '700', color: COLORS.textPrimary, marginBottom: 4 }, dateText: { color: COLORS.textSecondary, fontSize: 12 }, emptyContainer: { flex: 1, justifyContent: 'center', alignItems: 'center' }, emptyText: { fontSize: 16, color: COLORS.textSecondary }, fab: { position: 'absolute', bottom: 32, right: 32, backgroundColor: COLORS.primary, width: 56, height: 56, borderRadius: 28, alignItems: 'center', justifyContent: 'center', elevation: 4 }, typeText:{color:COLORS.textSecondary,fontSize:14}, passportText:{color:COLORS.textSecondary,fontSize:12}, }); export default CardPinOrdersScreen;