import React, { useState } from 'react'; import { View, StyleSheet, TouchableOpacity, Dimensions } from 'react-native'; import { Image } from 'expo-image'; import { Blurhash } from 'react-native-blurhash'; import Text from '../atoms/Text'; import Icon from '../atoms/Icon'; import { LinearGradient } from 'expo-linear-gradient'; interface CharacterCardProps { character: { id: string; name: string; original_description?: string; image_url?: string; total_vote_score?: number; stories_count?: number; share_code?: string; sharing_preference?: string; }; onPress?: () => void; onVote?: (voteType: 'like' | 'love' | 'star') => void; onClone?: () => void; showVoteCount?: boolean; voteCount?: number; showCloneButton?: boolean; style?: any; } export default function CharacterCard({ character, onPress, onVote, onClone, showVoteCount = false, voteCount = 0, showCloneButton = false, style, }: CharacterCardProps) { const cardWidth = style?.width || 160; const cardHeight = cardWidth * 1.3; const [imageLoaded, setImageLoaded] = useState(false); const blurHash = (character as any).blur_hash || 'LEHV6nWB2yk8pyo0adR*.7kCMdnj'; return ( {character.image_url ? ( <> {/* BlurHash Placeholder */} {!imageLoaded && ( )} {/* Actual Image */} setImageLoaded(true)} /> ) : ( )} {showVoteCount && ( {voteCount} )} {character.sharing_preference === 'commons' && ( Commons )} {character.name} {character.original_description && ( {character.original_description} )} {character.stories_count !== undefined && ( {character.stories_count} )} {character.share_code && ( {character.share_code.slice(0, 6)} )} {(showCloneButton || onVote) && ( {onVote && ( { e.stopPropagation(); onVote('like'); }} > { e.stopPropagation(); onVote('star'); }} > )} {showCloneButton && onClone && ( { e.stopPropagation(); onClone(); }} > )} )} ); } const styles = StyleSheet.create({ container: { backgroundColor: '#2C2C2C', borderRadius: 12, overflow: 'hidden', shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5, borderWidth: 1, borderColor: 'rgba(255, 255, 255, 0.1)', }, imageContainer: { flex: 1, position: 'relative', }, image: { width: '100%', height: '100%', }, blurHashPlaceholder: { width: '100%', height: '100%', position: 'absolute', zIndex: 1, }, hiddenImage: { opacity: 0, }, placeholderGradient: { width: '100%', height: '100%', justifyContent: 'center', alignItems: 'center', }, voteContainer: { position: 'absolute', top: 8, right: 8, flexDirection: 'row', alignItems: 'center', backgroundColor: 'rgba(0, 0, 0, 0.7)', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12, gap: 4, }, voteCount: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', }, badge: { position: 'absolute', top: 8, left: 8, backgroundColor: 'rgba(255, 203, 0, 0.9)', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 8, }, badgeText: { color: '#000000', fontSize: 10, fontWeight: '600', }, contentContainer: { padding: 12, }, name: { color: '#FFFFFF', fontSize: 16, fontWeight: '600', marginBottom: 4, }, description: { color: '#999999', fontSize: 12, lineHeight: 16, marginBottom: 8, }, statsContainer: { flexDirection: 'row', gap: 12, marginBottom: 8, }, stat: { flexDirection: 'row', alignItems: 'center', gap: 4, }, statText: { color: '#999999', fontSize: 11, }, actionContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginTop: 8, }, voteButtons: { flexDirection: 'row', gap: 8, }, actionButton: { padding: 6, borderRadius: 8, backgroundColor: 'rgba(255, 255, 255, 0.05)', }, cloneButton: { padding: 6, borderRadius: 8, backgroundColor: 'rgba(255, 255, 255, 0.1)', }, });