import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, ActivityIndicator, TouchableOpacity, Alert, ScrollView, SafeAreaView, Modal } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useNavigation, useRoute } from '@react-navigation/native';
import apiService from '../../services/apiService';
import { COLORS } from '../../constants/colors';
import { StatusBar } from 'expo-status-bar';
import DateInput from '../../components/DateInput';
import { Linking } from 'react-native';
const DetailRow = ({ label, value, showBorder = true }) => (
{label}
{String(value)}
);
const CardTransactionOrderDetailsScreen = () => {
const navigation = useNavigation();
const route = useRoute();
const { orderId } = route.params || {};
const [loading, setLoading] = useState(true);
const [order, setOrder] = useState(null);
const [modalVisible, setModalVisible] = useState(false);
const [startDate, setStartDate] = useState('');
const [endDate, setEndDate] = useState('');
const [downloading, setDownloading] = useState(false);
const fetchDetails = async () => {
setLoading(true);
const res = await apiService.getCardTransactionOrder(orderId);
if (res.success) {
setOrder(res.data);
} else {
Alert.alert('Error', res.error || 'Could not fetch details');
}
setLoading(false);
};
useEffect(() => {
fetchDetails();
}, []);
const handleDelete = () => {
Alert.alert('Confirm', 'Are you sure you want to delete this order?', [
{ text: 'Cancel', style: 'cancel' },
{ text: 'Delete', style: 'destructive', onPress: deleteOrder },
]);
};
const deleteOrder = async () => {
const res = await apiService.deleteCardTransactionOrder(orderId);
if (res.success) {
Alert.alert('Deleted', res.message || 'Order deleted', [
{ text: 'OK', onPress: () => navigation.goBack() },
]);
} else {
Alert.alert('Error', res.error || 'Could not delete');
}
};
const openDownloadModal = () => {
setStartDate('');
setEndDate('');
setModalVisible(true);
};
const handleDownload = async () => {
if (!startDate || !endDate) {
Alert.alert('Error', 'Select both dates');
return;
}
setDownloading(true);
const res = await apiService.downloadCardTransactions(orderId, startDate, endDate);
setDownloading(false);
if (res.success && res.data?.url) {
Linking.openURL(res.data.url);
setModalVisible(false);
} else {
Alert.alert('Ýalňyşlyk', res.data.message || 'Näsazlyk ýüze çykdy');
}
};
if (loading) {
return (
);
}
if (!order) {
return (
No data
);
}
return (
navigation.goBack()}>
Kart hereketleri
{order.card_number && }
{order.card_month && order.card_year && }
{order.passport_serie && order.passport_id && }
Ýükle (PDF)
Poz
{/* Download modal */}
setModalVisible(false)}>
Sene aralygy
{downloading ? (
) : (
Ýükle
)}
setModalVisible(false)} style={{ marginTop: 16, alignItems: 'center' }}>
Ýap
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: COLORS.backgroundSecondary,
paddingTop: 40,
},
centered: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
backBtn: {
alignSelf: 'flex-end',
marginRight: 24,
marginBottom: 16,
},
title: {
fontSize: 24,
fontWeight: 'bold',
color: COLORS.textPrimary,
marginBottom: 24,
},
detailCard: {
backgroundColor: COLORS.white,
borderRadius: 12,
padding: 20,
marginBottom: 32,
},
detailRow: {
flexDirection: 'row',
justifyContent: 'space-between',
paddingVertical: 12,
},
detailRowBorder: {
borderBottomWidth: 1,
borderBottomColor: COLORS.border,
},
detailKey: {
fontWeight: '600',
color: COLORS.textSecondary,
},
detailValue: {
color: COLORS.textPrimary,
},
actionBtn: {
backgroundColor: COLORS.primary,
paddingVertical: 16,
borderRadius: 8,
alignItems: 'center',
marginBottom: 16,
},
actionText: {
color: COLORS.white,
fontSize: 16,
fontWeight: '600',
},
deleteBtn: {
backgroundColor: COLORS.error,
paddingVertical: 16,
borderRadius: 8,
alignItems: 'center',
},
deleteText: {
color: COLORS.white,
fontSize: 16,
fontWeight: '600',
},
modalBackdrop: {
flex: 1,
backgroundColor: 'rgba(0,0,0,0.25)',
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 24,
},
modalCard: {
backgroundColor: COLORS.white,
borderRadius: 12,
width: '100%',
padding: 24,
},
modalTitle: {
fontSize: 18,
fontWeight: 'bold',
color: COLORS.textPrimary,
marginBottom: 16,
},
submitBtn: {
marginTop: 8,
backgroundColor: COLORS.primary,
paddingVertical: 14,
borderRadius: 8,
alignItems: 'center',
},
submitText: {
color: COLORS.white,
fontSize: 16,
fontWeight: '600',
},
});
export default CardTransactionOrderDetailsScreen;