import { useState, useRef, useMemo, useCallback, useEffect } from 'react' import { View, Text, StyleSheet, Pressable, useWindowDimensions, } from 'react-native' import { LinearGradient } from 'expo-linear-gradient' import { useSafeAreaInsets } from 'react-native-safe-area-context' import { useTranslation } from 'react-i18next' import BottomSheet, { BottomSheetView, BottomSheetBackdrop } from '@gorhom/bottom-sheet' import { CloseIcon } from '@/components/icon' import TopUpDrawer, { TopUpOption } from '@/components/drawer/TopUpDrawer' export interface PointsDrawerProps { /** * 是否显示抽屉 */ visible: boolean /** * 关闭回调 */ onClose: () => void /** * 当前积分总额 */ totalPoints?: number /** * 订阅积分 */ subscriptionPoints?: number /** * 额外充值积分 */ topUpPoints?: number } export default function PointsDrawer({ visible, onClose, totalPoints = 0, subscriptionPoints = 0, topUpPoints = 0, }: PointsDrawerProps) { const { t } = useTranslation() const insets = useSafeAreaInsets() const bottomSheetRef = useRef(null) const [topUpDrawerVisible, setTopUpDrawerVisible] = useState(false) const snapPoints = useMemo(() => [380], []) useEffect(() => { if (visible) { bottomSheetRef.current?.expand() } else { bottomSheetRef.current?.close() } }, [visible]) const handleSheetChanges = useCallback((index: number) => { if (index === -1) { onClose() } }, [onClose]) const renderBackdrop = useCallback( (props: any) => ( ), [] ) return ( {/* 顶部标题栏 */} {t('pointsDrawer.title')} {/* 积分总额 */} {totalPoints} {/* 积分类型细分 */} {t('pointsDrawer.subscriptionPoints')} {subscriptionPoints} {t('pointsDrawer.topUpPoints')} {topUpPoints} {/* 底部按钮 */} { onClose() }} > {t('pointsDrawer.subscribeForPoints')} { setTopUpDrawerVisible(true) }} > {t('pointsDrawer.topUpPointsButton')} {/* 充值抽屉 */} setTopUpDrawerVisible(false)} onNavigate={() => { setTopUpDrawerVisible(false) onClose() }} requiredPoints={100} remainingPoints={totalPoints} topUpTitle={t('topUp.title')} onConfirm={(option: TopUpOption) => { // 处理充值确认逻辑 console.log('确认充值:', option) setTopUpDrawerVisible(false) }} /> ) } const styles = StyleSheet.create({ bottomSheetBackground: { backgroundColor: '#090A0B', borderTopLeftRadius: 24, borderTopRightRadius: 24, }, container: { flex: 1, backgroundColor: '#090A0B', borderTopLeftRadius: 20, borderTopRightRadius: 20, overflow: 'hidden', }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingTop: 12, marginRight: 12, }, titleContainer: { paddingLeft: 20, marginTop: -4, }, title: { color: '#F5F5F5', fontSize: 12, fontWeight: '500', }, closeButton: { width: 24, height: 24, alignItems: 'center', justifyContent: 'center', }, balance: { marginBottom: 13, }, balanceValue: { color: '#F5F5F5', fontSize: 40, fontWeight: '500', }, breakdown: { flexDirection: 'row', gap: 16, marginBottom: 24, }, breakdownText: { color: '#ABABAB', fontSize: 12, fontWeight: '400', }, breakdownTextValue: { color: '#F5F5F5', fontSize: 12, fontWeight: '500', marginLeft: 6, }, breakdownTextSeparator: { width: 1, height: 14, backgroundColor: '#3A3A3A', marginTop: 2, }, footer: { paddingTop: 20, paddingHorizontal: 16, gap: 4, }, subscribeButton: { width: '100%', height: 48, borderRadius: 12, overflow: 'hidden', }, subscribeButtonGradient: { width: '100%', height: 48, alignItems: 'center', justifyContent: 'center', borderRadius: 12, }, subscribeButtonText: { color: '#F5F5F5', fontSize: 16, fontWeight: '500', }, topUpButton: { alignItems: 'center', justifyContent: 'center', paddingVertical: 12, }, topUpButtonText: { color: '#F5F5F5', fontSize: 12, fontWeight: '400', }, })