import React, { useState, useRef, useMemo } from 'react'; import { View, StyleSheet, TouchableOpacity, Animated, Dimensions, } from 'react-native'; import { InsideHeader } from '../../components'; import { useFetchLiveTender, useFetchPurchaseTender, } from '../../Services/ApiCall/Hooks'; import { ShoppingCart, Lock, Radio, Package } from 'lucide-react-native'; import { useNavigation } from '@react-navigation/native'; import NavigationString from '../../Constant/NavigationString'; import { useSelector } from 'react-redux'; import LiveTender from './LiveTender'; import PurchaseTenderAllList from './PurchaseTenderAllList'; import { useTheme } from '../../Hooks/useTheme'; import AppText from '../../components/AppText'; const { width: SCREEN_WIDTH } = Dimensions.get('window'); const TAB_HEIGHT = 48; const HORIZONTAL_PADDING = 32; const SWITCH_INSETS = 3; const Tender = () => { const { colors, spacing, shadows } = useTheme(); const Navigation = useNavigation() as any; const { data: liveTenderData }: any = useFetchLiveTender(); const { data: purchaseTenderData }: any = useFetchPurchaseTender(); const SelectedPurchaseList = useSelector((state: any) => state?.selectPurchaseTender); const reduxToken = useSelector((state: any) => state.token?.token); const liveCount = liveTenderData?.pages?.[0]?.totalCount || 0; const purchaseCount = purchaseTenderData?.pages?.[0]?.totalCount || 0; const TAB_WIDTH = useMemo(() => { const availableWidth = SCREEN_WIDTH - HORIZONTAL_PADDING - SWITCH_INSETS * 2; return availableWidth / 2; }, []); const [selectedTab, setSelectedTab] = useState<'live' | 'purchase'>('purchase'); const translateX = useRef(new Animated.Value(TAB_WIDTH)).current; const onTabPress = (tab: 'live' | 'purchase', index: number) => { setSelectedTab(tab); Animated.spring(translateX, { toValue: index * TAB_WIDTH, useNativeDriver: true, friction: 8, }).start(); }; const isAuctionUser = reduxToken?.userType?.toLowerCase() === 'auction'; const cartCount = SelectedPurchaseList.length; const styles = makeStyles(colors, spacing, shadows, TAB_WIDTH, TAB_HEIGHT); if (isAuctionUser) { return ( {/* Double-ring Lock Icon */} Access Restricted You're logged in as an{' '} Auction user {'. '}Tender features are not available for your account type. Switch to a Tender account to access live & purchase tender features. Navigation.navigate(NavigationString.Login)} > Switch to Tender Login ); } return ( {/* Tab Row */} {/* Segmented Control */} {/* Sliding pill */} {/* Live Tab */} onTabPress('live', 0)} > Live {liveCount ? `(${liveCount})` : ''} {/* Purchase Tab */} onTabPress('purchase', 1)} > Purchased {purchaseCount ? `(${purchaseCount})` : ''} {/* Content */} {selectedTab === 'live' ? : } {/* Cart Floating Button */} Navigation.navigate(NavigationString.PurchaseTenderList)} > {cartCount > 0 && ( {cartCount} )} ); }; export default Tender; /* ─── Styles factory ─── */ const makeStyles = (colors: any, spacing: any, shadows: any, TAB_WIDTH: number, TAB_HEIGHT: number) => StyleSheet.create({ container: { flex: 1, backgroundColor: colors.background, }, /* ── Tab Row ── */ topRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', paddingHorizontal: spacing.m, paddingVertical: spacing.s + 2, }, switchWrapper: { flexDirection: 'row', backgroundColor: colors.surface, borderRadius: 16, padding: SWITCH_INSETS, height: TAB_HEIGHT, ...shadows.light, }, tab: { height: TAB_HEIGHT - SWITCH_INSETS * 2, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 5, zIndex: 2, }, tabText: { fontWeight: '600', letterSpacing: 0.3, } as any, activeTabText: { fontWeight: '700', } as any, activeTab: { position: 'absolute', top: SWITCH_INSETS, left: SWITCH_INSETS, height: TAB_HEIGHT - SWITCH_INSETS * 2, backgroundColor: colors.background, borderRadius: 13, ...shadows.medium, }, /* ── Cart Floating Button ── */ cartFloatingButton: { position: 'absolute', bottom: spacing.xl + 80, right: spacing.l, width: 56, height: 56, borderRadius: 28, backgroundColor: colors.primary, alignItems: 'center', justifyContent: 'center', ...shadows.strong, zIndex: 999, }, cartBadge: { position: 'absolute', top: 0, right: 0, minWidth: 20, height: 20, borderRadius: 10, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 4, borderWidth: 1.5, borderColor: colors.primary, }, cartBadgeText: { fontSize: 10, fontWeight: '800', lineHeight: 13, } as any, /* ── Restricted Access ── */ restrictedContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: spacing.l, backgroundColor: colors.background, }, restrictedCard: { backgroundColor: colors.surface, borderRadius: 28, padding: spacing.l, alignItems: 'center', width: '100%', maxWidth: 400, ...shadows.strong, }, lockRing: { width: 100, height: 100, borderRadius: 50, backgroundColor: `${colors.primary}12`, alignItems: 'center', justifyContent: 'center', marginBottom: spacing.l, borderWidth: 1.5, borderColor: `${colors.primary}25`, }, lockInner: { width: 72, height: 72, borderRadius: 36, backgroundColor: `${colors.primary}18`, alignItems: 'center', justifyContent: 'center', }, restrictedTitle: { marginBottom: spacing.s + 4, } as any, restrictedMessage: { marginBottom: spacing.s, lineHeight: 24, } as any, hintBox: { backgroundColor: colors.overlay, borderRadius: 14, paddingHorizontal: spacing.m, paddingVertical: spacing.s + 2, marginBottom: spacing.l, width: '100%', }, loginButton: { backgroundColor: colors.buttonPrimary, paddingHorizontal: spacing.l, paddingVertical: 14, borderRadius: 16, width: '100%', alignItems: 'center', ...shadows.medium, }, loginBtnText: { letterSpacing: 1.2, } as any, });