import React, { useMemo } from "react"; import { View, Text, StyleSheet, ViewStyle, TextStyle, ImageBackground, ImageSourcePropType, ImageStyle, FlatList, } from "react-native"; import RewardItem from "../UnlockRewards/RewardItem"; import Badge from "../Badges/Badge"; import { useTheme, ThemeType } from "../../theme"; import { LinearGradient } from "expo-linear-gradient"; import CloseIcon from "../CloseIcon/CloseIcon"; // Import the new component type Reward = { icon?: React.ReactNode; activeIcon?: React.ReactNode; title: string; description: string; isActive: boolean; status: string; statusBackgroundColor: string; statusTextColor: string; }; interface UnlockRewardsProps { title?: string; description?: string; rewards: Reward[]; activeIconStyle?: ViewStyle; inactiveIconStyle?: ViewStyle; onClose?: () => void; // Kept for passing to CloseIcon isRTL?: boolean; customTopBackground?: React.ReactNode; topBackgroundImage?: ImageSourcePropType; topBackgroundColor?: string; topBackgroundHeight?: number; topBackgroundImageStyle?: ImageStyle; topBackgroundStyle?: ViewStyle; topGradientColors?: string[]; topGradientStart?: { x: number; y: number }; topGradientEnd?: { x: number; y: number }; topGradientLocations?: number[]; modalOverlayStyle?: ViewStyle; cardContainerStyle?: ViewStyle; mainTitleStyle?: TextStyle; subtitleStyle?: TextStyle; rewardsContainerStyle?: ViewStyle; smallIconsRowStyle?: ViewStyle; rewardItemContainerStyle?: ViewStyle; rewardItemIconWrapperStyle?: ViewStyle; rewardItemTextContainerStyle?: ViewStyle; rewardItemTitleTextStyle?: TextStyle; rewardItemDescriptionTextStyle?: TextStyle; rewardItemStatusBadgeStyle?: ViewStyle; rewardItemStatusTextStyle?: TextStyle; showCloseIcon?: boolean; customCloseIcon?: React.ReactNode; closeIconVariant?: "floating" | "nested"; closeIconContainerStyle?: ViewStyle; closeIconStyle?: TextStyle; closeIconColor?: string; closeIconSize?: number; } const UnlockRewards: React.FC = ({ rewards, title, description, activeIconStyle, inactiveIconStyle, onClose, // Keep onClose isRTL, topBackgroundImage, topBackgroundColor: topBackgroundColorProp, topBackgroundHeight = 250, topBackgroundImageStyle, topBackgroundStyle, topGradientColors, topGradientStart, topGradientEnd, topGradientLocations, cardContainerStyle, mainTitleStyle, subtitleStyle, rewardsContainerStyle, smallIconsRowStyle, rewardItemContainerStyle, rewardItemIconWrapperStyle, rewardItemTextContainerStyle, rewardItemTitleTextStyle, rewardItemDescriptionTextStyle, rewardItemStatusBadgeStyle, rewardItemStatusTextStyle, showCloseIcon = true, customCloseIcon, closeIconVariant = "nested", closeIconContainerStyle, closeIconStyle, closeIconColor, closeIconSize = 28, customTopBackground, }) => { const { theme, isRTL: rtl } = useTheme(); isRTL = isRTL || rtl; const styles = useMemo(()=> themedStyles(theme), [ theme]); const topBackgroundColor = topBackgroundColorProp ?? theme.surface; const finalCardStyle = StyleSheet.flatten([ styles.cardContainer, cardContainerStyle, ]); const cardBorderRadius = finalCardStyle.borderRadius ?? 20; const topBackgroundBorderRadius = { borderTopLeftRadius: cardBorderRadius, borderTopRightRadius: cardBorderRadius, }; const topElementBaseStyle = [ styles.topBackgroundBase, topBackgroundBorderRadius, topBackgroundStyle, { height: topBackgroundHeight }, ]; return ( {/* --- CloseIcon component --- */} {/* --- End CloseIcon usage --- */} {/* --- Top Background Rendering --- */} {!customTopBackground ? ( topGradientColors && topGradientColors.length >= 2 ? ( ) : topBackgroundImage ? ( ) : ( ) ) : ( {customTopBackground} )} {/* --- End Top Background Rendering --- */} {title && {title}} {description && ( {description} )} {rewards.map((reward, index) => ( ))} `reward-${idx}`} showsVerticalScrollIndicator={false} renderItem={({ item, index }) => ( )} /> ); }; const themedStyles = (theme: ThemeType) => StyleSheet.create({ cardContainer: { backgroundColor: theme.surface, borderRadius: 20, padding: 20, paddingTop: 40, width: "100%", maxWidth: 400, alignItems: "center", shadowColor: "#000", shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.15, shadowRadius: 5, elevation: 5, position: "relative", borderWidth: 1, borderColor: theme.border, }, topBackgroundBase: { position: "absolute", top: 0, left: 0, right: 0, zIndex: 0, }, topBackgroundImageStyle: {}, closeIconContainer: { position: "absolute", zIndex: 10, }, mainTitle: { fontSize: 26, fontWeight: "bold", color: theme.text, marginBottom: 8, textAlign: "center", zIndex: 1, }, subtitle: { fontSize: 14, color: theme.helper, textAlign: "center", marginBottom: 25, paddingHorizontal: 10, zIndex: 1, }, rewardsContainer: { backgroundColor: theme.background, padding: 20, borderRadius: 20, width: "100%", zIndex: 1, borderWidth: 1, borderColor: theme.border, }, smallIconsRow: { flexDirection: "row", justifyContent: "space-around", alignItems: "center", marginBottom: 30, paddingVertical: 15, backgroundColor: theme.surface, borderRadius: 15, }, }); export default UnlockRewards;