import { StyleSheet, Text, View, ScrollView, StatusBar, TouchableOpacity, RefreshControl, ActivityIndicator, Platform } from 'react-native' import React, { useCallback, useEffect } from 'react' import { InsideHeader } from '../../Component/Index' import colors from '../../Constant/Color' import { useFocusEffect, useNavigation, useRoute } from '@react-navigation/native' import { useFetchTenderById, useProceedToBid } from '../../Services/BBPS/Hooks' const ProceedToBidDetail = () => { // Sample data based on your JSON const route = useRoute(); const tenderDataId = route.params?.tender; const { data, refetch, isRefetching } = useProceedToBid(tenderDataId?.tenderId); const { data: tenderResponse, refetch: tenderRefetch }: any = useFetchTenderById(tenderDataId?.tenderId); const tenderData = tenderResponse?.data; console.log("dataopop",tenderData) const [refreshing, setRefreshing] = React.useState(false); const [loading, setLoading] = React.useState(false); // console.log("proceed to bid tender detail : ", tenderDataId) // console.log("proceed to data detail : ", data) // console.log("tender data for updated : ", tenderData) const navigation = useNavigation() // Format date from array const handleStartBidding = () => { setLoading(true); try { setLoading(true); navigation.navigate('TenderBidding', { tenderId: tenderDataId.tenderId }); } catch (error) { console.log("Error in starting bidding: ", error); } finally { setLoading(false); } } const formatDate = (dateArray: any[]) => { if (!dateArray || dateArray.length < 3) return "N/A"; const [year, month, day, hour = 0, minute = 0] = dateArray; return `${day.toString().padStart(2, '0')}/${month.toString().padStart(2, '0')}/${year} ${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`; }; // Status indicator component const StatusIndicator = ({ status, label }: { status: boolean; label: string }) => ( {label}: {status ? "Submitted" : "Not Submitted"} ); // Envelope log card component const EnvelopeLogCard = ({ log, title }: { log: any; title: string }) => ( {title} {log?.envelope} Activity: {log?.activity} Date & Time: {log?.dateTime} System Info: {log?.osName} / {log?.browserName} IP Address: {log?.ipAddress} Status Message: {log?.logMessage} {log?.headingMsg && ( Heading: {log?.headingMsg} )} ); // Information row component const InfoRow = ({ label, value, isHighlighted = false }: { label: string; value: string; isHighlighted?: boolean }) => ( {label}: {value} ); // Feature chip component const FeatureChip = ({ label, enabled }: { label: string; enabled: boolean }) => ( {label} {enabled ? '✓' : '✗'} ); const onRefresh = async () => { try { setRefreshing(true); await refetch(); } finally { setRefreshing(false); } }; useFocusEffect( useCallback(() => { tenderRefetch(); }, [tenderData?.tenderId]) ); return ( }> {/* Tender Header Section */} {tenderData?.tenderNumber} ID: {tenderData?.tenderId} {tenderData?.biddingStatus ? "Active" : "Inactive"} {tenderData?.nameofWork} NIT No. {tenderData?.nitNo} EMD Amount ₹{tenderData?.emdInFig} {/* Envelope Submission Status */} Envelope Submission Status {tenderData?.showEB &&} {tenderData?.showEC &&} {/* Envelope Logs */} {tenderData?.envelopeA_Logs && ( Submission Logs {tenderData?.envelopeA_Logs && } {tenderData?.envelopeB_Logs && } {tenderData?.envelopeC_Logs && } )} {/* Tender Details */} Tender Details {/* Time Period */} Submission Time Period Starts On: {formatDate(tenderData?.submittedStartDate)} Ends On: {formatDate(tenderData?.submittedEndDate)} {/* Feature Flags Available Features */} {/* Final Status */} Overall Status All Envelopes Submitted: {tenderData?.envelopeASubmittStatus && tenderData?.envelopeBSubmittStatus && tenderData?.envelopeCSubmittStatus ? "COMPLETED" : "PENDING"} Bidding Status: {tenderData?.biddingStatus ? "ACTIVE" : "CLOSED"} { tenderData?.proceedtoBid && !tenderData?.viewBid && tenderData?.biddingStatus && tenderData?.bidWithdrawStatus === false ? ( {loading ? : 'Start Bidding'} ) : One time bidding is completed } ) } export default ProceedToBidDetail const styles = StyleSheet.create({ container: { flex: 1, padding: 16, marginBottom: 60, }, headerCard: { backgroundColor: colors.primaryLight, borderRadius: 12, padding: 20, marginBottom: 20, borderLeftWidth: 4, borderLeftColor: colors.primary, }, tenderHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, }, tenderNumber: { fontSize: 22, fontWeight: 'bold', color: colors.primary, }, tenderId: { fontSize: 14, color: colors.darkGray, marginTop: 4, }, statusBadge: { paddingHorizontal: 12, paddingVertical: 6, borderRadius: 20, }, statusBadgeText: { color: colors.white, fontWeight: '600', fontSize: 12, }, workDescription: { fontSize: 16, color: colors.darkText, lineHeight: 22, marginBottom: 16, }, headerInfoRow: { flexDirection: 'row', alignItems: 'center', backgroundColor: colors.white, borderRadius: 8, padding: 12, }, headerInfoItem: { flex: 1, alignItems: 'center', }, headerInfoLabel: { fontSize: 12, color: colors.darkGray, marginBottom: 4, }, headerInfoValue: { fontSize: 16, fontWeight: '600', color: colors.primary, }, separator: { width: 1, height: 30, backgroundColor: colors.lightGray, }, section: { marginBottom: 20, }, sectionTitle: { fontSize: 18, fontWeight: '600', color: colors.primary, marginBottom: 12, paddingLeft: 4, }, statusGrid: { backgroundColor: colors.white, borderRadius: 12, padding: 16, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 3, }, statusContainer: { flexDirection: 'row', alignItems: 'center', marginBottom: 12, }, statusDot: { width: 12, height: 12, borderRadius: 6, marginRight: 10, }, statusText: { fontSize: 15, fontWeight: '500', }, envelopeCard: { backgroundColor: colors.white, borderRadius: 12, padding: 16, marginBottom: 12, borderWidth: 1, borderColor: colors.lightGray, }, cardHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, }, cardTitle: { fontSize: 16, fontWeight: '600', color: colors.primary, }, envelopeBadge: { paddingHorizontal: 10, paddingVertical: 4, borderRadius: 12, }, envelopeBadgeText: { color: colors.white, fontWeight: 'bold', fontSize: 12, }, logDetailRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8, }, label: { fontSize: 14, color: colors.darkGray, flex: 1, }, value: { fontSize: 14, color: colors.darkText, fontWeight: '500', flex: 2, textAlign: 'right', }, successText: { color: colors.success, fontWeight: '600', }, detailsCard: { backgroundColor: colors.white, borderRadius: 12, padding: 16, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 3, }, infoRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingVertical: 10, borderBottomWidth: 1, borderBottomColor: colors.lightestGray, }, infoLabel: { fontSize: 14, color: colors.darkGray, }, infoValue: { fontSize: 15, fontWeight: '500', color: colors.darkText, }, highlightedValue: { color: colors.success, fontWeight: '600', }, timeCard: { backgroundColor: colors.white, borderRadius: 12, padding: 16, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 3, }, timeRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingVertical: 12, borderBottomWidth: 1, borderBottomColor: colors.lightestGray, }, timeLabel: { fontSize: 15, color: colors.darkGray, fontWeight: '500', }, timeValue: { fontSize: 15, color: colors.primary, fontWeight: '600', }, chipsContainer: { flexDirection: 'row', flexWrap: 'wrap', gap: 10, }, chip: { paddingHorizontal: 16, paddingVertical: 8, borderRadius: 20, marginBottom: 8, }, chipText: { fontSize: 14, fontWeight: '500', }, finalStatusCard: { backgroundColor: colors.primaryLight, borderRadius: 12, padding: 20, marginTop: 10, borderWidth: 2, borderColor: colors.primary, }, finalStatusTitle: { fontSize: 18, fontWeight: 'bold', color: colors.primary, marginBottom: 16, textAlign: 'center', }, finalStatusRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: 'rgba(0, 0, 0, 0.1)', }, finalStatusLabel: { fontSize: 16, color: colors.darkText, fontWeight: '500', }, finalStatusValue: { fontSize: 16, fontWeight: 'bold', }, footerSpace: { height: 30, }, success: { color: colors.success, }, error: { color: colors.error, }, primary: { color: colors.primary, }, warning: { color: colors.warning, }, successLight: { backgroundColor: colors.successLight, }, lightGray: { backgroundColor: colors.lightGray, }, footer: { position: 'absolute', bottom: 0, left: 0, right: 0, backgroundColor: colors.white, padding: 16, borderTopWidth: 1, borderTopColor: colors.lightGray, elevation: 10, }, proceedButton: { backgroundColor: colors.primary, paddingVertical: 14, borderRadius: 30, alignItems: 'center', }, proceedButtonText: { color: colors.white, fontSize: 16, fontWeight: '600', }, footerText: { textAlign: 'center', color: colors.darkGray, fontSize: 14, }, actionButton: { width: '100%', height: 48, borderRadius: 12, justifyContent: 'center', alignItems: 'center', ...Platform.select({ ios: { shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, }, }), }, });