All files / app/(tabs)/profile/components BadgeDetailModal.tsx

0% Statements 0/15
0% Branches 0/16
0% Functions 0/3
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
/**
 * 勋章详情弹窗
 *
 * 显示勋章的详细信息、获取条件等
 */
import { memo } from 'react';
import { Modal, ScrollView, TouchableOpacity, StyleSheet } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { LinearGradient } from 'expo-linear-gradient';
import { Card, Text, XStack, YStack, Separator } from 'tamagui';
import { Button } from '@/src/design-system/components';
import { IconSymbol } from '@/src/components/ui/IconSymbol';
import { BADGE_CONFIGS, RARITY_CONFIGS } from '@/src/constants/badges';
import { useThemeColors, useIsDarkMode } from '@/src/hooks/useThemeColors';
import type { DbUserBadge } from '@/src/lib/supabase/types/database';
 
interface BadgeDetailModalProps {
  visible: boolean;
  badge: DbUserBadge | null;
  onClose: () => void;
  onEquip?: (badgeId: number) => void;
  onUnequip?: (badgeId: number) => void;
}
 
export const BadgeDetailModal = memo(function BadgeDetailModal({
  visible,
  badge,
  onClose,
  onEquip,
  onUnequip,
}: BadgeDetailModalProps) {
  const insets = useSafeAreaInsets();
  const colors = useThemeColors();
  const isDark = useIsDarkMode();
 
  if (!badge || !badge.badge?.code) return null;
 
  const badgeConfig = BADGE_CONFIGS[badge.badge.code];
  if (!badgeConfig) return null;
 
  const rarityConfig = RARITY_CONFIGS[badgeConfig.rarity];
  const acquiredDate = new Date(badge.acquired_at).toLocaleDateString('zh-CN');
 
  return (
    <Modal visible={visible} animationType="fade" transparent statusBarTranslucent>
      <TouchableOpacity style={styles.overlay} activeOpacity={1} onPress={onClose}>
        <TouchableOpacity activeOpacity={1} style={styles.contentContainer}>
          <Card
            backgroundColor={colors.cardBackground as any}
            borderRadius={24}
            padding="$5"
            width="90%"
            maxWidth={400}
            maxHeight="85%"
          >
            <ScrollView showsVerticalScrollIndicator={false}>
              <YStack gap="$4">
                {/* 关闭按钮 */}
                <XStack justifyContent="flex-end">
                  <TouchableOpacity onPress={onClose} activeOpacity={0.7}>
                    <YStack
                      width={32}
                      height={32}
                      borderRadius={16}
                      backgroundColor={colors.backgroundMuted as any}
                      alignItems="center"
                      justifyContent="center"
                    >
                      <IconSymbol name="xmark" size={16} color={colors.textSecondary} />
                    </YStack>
                  </TouchableOpacity>
                </XStack>
 
                {/* 勋章展示 */}
                <YStack alignItems="center" gap="$3">
                  {/* 勋章图标 */}
                  <YStack
                    position="relative"
                    width={120}
                    height={120}
                    alignItems="center"
                    justifyContent="center"
                  >
                    {/* 光晕效果 */}
                    <YStack
                      position="absolute"
                      width={120}
                      height={120}
                      borderRadius={60}
                      style={{
                        backgroundColor: rarityConfig.glow,
                      }}
                    />
 
                    {/* 勋章主体 */}
                    <YStack
                      width={100}
                      height={100}
                      borderRadius={50}
                      alignItems="center"
                      justifyContent="center"
                      borderWidth={4}
                      borderColor={colors.cardBackground as any}
                      style={{
                        backgroundColor: badgeConfig.gradient
                          ? 'transparent'
                          : badgeConfig.color + '20',
                      }}
                    >
                      {badgeConfig.gradient ? (
                        <LinearGradient
                          colors={badgeConfig.gradient}
                          style={{
                            width: 92,
                            height: 92,
                            borderRadius: 46,
                            alignItems: 'center',
                            justifyContent: 'center',
                          }}
                        >
                          <IconSymbol name={badgeConfig.icon as any} size={50} color="white" />
                        </LinearGradient>
                      ) : (
                        <IconSymbol
                          name={badgeConfig.icon as any}
                          size={50}
                          color={badgeConfig.color}
                        />
                      )}
                    </YStack>
 
                    {/* 已装备标记 */}
                    {badge.is_equipped && (
                      <YStack
                        position="absolute"
                        top={8}
                        right={8}
                        paddingHorizontal="$2"
                        paddingVertical="$1"
                        borderRadius={12}
                        backgroundColor={badgeConfig.color as any}
                        borderWidth={2}
                        borderColor={colors.cardBackground as any}
                      >
                        <Text fontSize={10} fontWeight="700" color="white">
                          已装备
                        </Text>
                      </YStack>
                    )}
                  </YStack>
 
                  {/* 勋章名称 */}
                  <YStack alignItems="center" gap="$1">
                    <Text fontSize={24} fontWeight="800" color={colors.text as any}>
                      {badgeConfig.name}
                    </Text>
                    <XStack
                      alignItems="center"
                      gap="$1.5"
                      paddingHorizontal="$2.5"
                      paddingVertical="$1"
                      backgroundColor={(rarityConfig.color + '20') as any}
                      borderRadius={8}
                    >
                      <IconSymbol name="sparkles" size={12} color={rarityConfig.color} />
                      <Text fontSize={12} fontWeight="700" color={rarityConfig.color as any}>
                        {rarityConfig.name}
                      </Text>
                    </XStack>
                  </YStack>
                </YStack>
 
                <Separator borderColor={colors.borderMuted as any} />
 
                {/* 勋章描述 */}
                <YStack gap="$2">
                  <Text fontSize={14} fontWeight="600" color={colors.text as any}>
                    描述
                  </Text>
                  <Text fontSize={14} color={colors.textSecondary as any} lineHeight={20}>
                    {badgeConfig.description}
                  </Text>
                </YStack>
 
                {/* 获取条件 */}
                {badgeConfig.requirement && (
                  <YStack gap="$2">
                    <Text fontSize={14} fontWeight="600" color={colors.text as any}>
                      获取条件
                    </Text>
                    <YStack
                      backgroundColor={(badgeConfig.color + '10') as any}
                      padding="$3"
                      borderRadius={12}
                      borderWidth={1}
                      borderColor={(badgeConfig.color + '30') as any}
                    >
                      <XStack alignItems="center" gap="$2">
                        <IconSymbol name="info.circle.fill" size={16} color={badgeConfig.color} />
                        <Text
                          fontSize={13}
                          color={colors.textSecondary as any}
                          lineHeight={18}
                          flex={1}
                        >
                          {badgeConfig.requirement}
                        </Text>
                      </XStack>
                    </YStack>
                  </YStack>
                )}
 
                {/* 获取时间 */}
                <YStack gap="$2">
                  <Text fontSize={14} fontWeight="600" color={colors.text as any}>
                    获得时间
                  </Text>
                  <XStack alignItems="center" gap="$2">
                    <IconSymbol name="calendar" size={16} color={colors.textTertiary} />
                    <Text fontSize={14} color={colors.textSecondary as any}>
                      {acquiredDate}
                    </Text>
                  </XStack>
                </YStack>
 
                {/* 操作按钮 */}
                <YStack gap="$2" marginTop="$2">
                  {badge.is_equipped ? (
                    <Button
                      size="lg"
                      variant="outline"
                      onPress={() => onUnequip?.(badge.badge_id)}
                      leftIcon={
                        <IconSymbol name="minus.circle" size={20} color={badgeConfig.color} />
                      }
                    >
                      <Text fontSize={15} fontWeight="600" color={badgeConfig.color as any}>
                        取消装备
                      </Text>
                    </Button>
                  ) : (
                    <Button
                      size="lg"
                      variant="primary"
                      backgroundColor={badgeConfig.color as any}
                      onPress={() => onEquip?.(badge.badge_id)}
                      leftIcon={<IconSymbol name="checkmark.circle" size={20} color="white" />}
                    >
                      <Text fontSize={15} fontWeight="600" color="white">
                        装备勋章
                      </Text>
                    </Button>
                  )}
 
                  <Button
                    size="md"
                    variant="ghost"
                    color={colors.textSecondary as any}
                    onPress={onClose}
                  >
                    关闭
                  </Button>
                </YStack>
              </YStack>
            </ScrollView>
          </Card>
        </TouchableOpacity>
      </TouchableOpacity>
    </Modal>
  );
});
 
const styles = StyleSheet.create({
  overlay: {
    flex: 1,
    backgroundColor: 'rgba(0, 0, 0, 0.6)',
    justifyContent: 'center',
    alignItems: 'center',
  },
  contentContainer: {
    width: '100%',
    alignItems: 'center',
  },
});