import React, { useState } from 'react'; import { View, Pressable, ScrollView } from 'react-native'; import { Icon } from '../ui/Icon'; import { Text } from '../ui/Text'; import { Card, TextContent, FlashcardContent, QuizContent, MixedContent, } from '../../store/cardStore'; import { Button } from '../ui/Button'; import { useThemeColors } from '~/utils/themeUtils'; interface CardViewProps { card: Card; mode: 'view' | 'study' | 'edit' | 'preview'; onFlip?: () => void; onAnswerSelect?: (answerIndex: number) => void; onEdit?: () => void; showActions?: boolean; isFlipped?: boolean; selectedAnswer?: number; showFeedback?: boolean; } export const CardView: React.FC = ({ card, mode, onFlip, onAnswerSelect, onEdit, showActions = false, isFlipped = false, selectedAnswer, showFeedback = false, }) => { const [localFlipped, setLocalFlipped] = useState(false); const [showHint, setShowHint] = useState(false); const actuallyFlipped = isFlipped !== undefined ? isFlipped : localFlipped; const colors = useThemeColors(); const handleFlip = () => { if (onFlip) { onFlip(); } else { setLocalFlipped(!localFlipped); } }; const renderTextCard = (content: TextContent) => ( {card.title && {card.title}} {content.text} ); const renderFlashcard = (content: FlashcardContent) => ( {/* Main Content Area */} {!actuallyFlipped ? ( // Front side {content.front} {/* Hint Content - only if shown */} {content.hint && mode === 'study' && showHint && ( {content.hint} )} ) : ( // Back side {content.back} )} {/* Fixed Hint Bar at Bottom - only on front side */} {!actuallyFlipped && content.hint && mode === 'study' && ( setShowHint(!showHint)} style={({ pressed }) => ({ paddingVertical: 18, paddingHorizontal: 24, backgroundColor: showHint ? `${colors.accent}20` : 'transparent', opacity: pressed ? 0.7 : 1, })}> {showHint ? 'Hinweis ausblenden' : 'Hinweis anzeigen'} )} ); const renderQuizCard = (content: QuizContent) => ( {content.question} {content.options.map((option, index) => { const isSelected = selectedAnswer === index; const isCorrect = index === content.correct_answer; const showCorrect = showFeedback && isCorrect; const showIncorrect = showFeedback && isSelected && !isCorrect; const getBorderColor = () => { if (showCorrect) return 'rgb(34, 197, 94)'; // green-500 if (showIncorrect) return colors.destructive; if (isSelected && !showFeedback) return colors.primary; return colors.border; }; const getBackgroundColor = () => { if (showCorrect) return 'rgba(34, 197, 94, 0.1)'; if (showIncorrect) return `${colors.destructive}15`; if (isSelected && !showFeedback) return `${colors.primary}15`; return colors.surface; }; return ( onAnswerSelect?.(index)} disabled={showFeedback || mode !== 'study'} style={({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', borderRadius: 8, borderWidth: 2, padding: 12, borderColor: getBorderColor(), backgroundColor: getBackgroundColor(), opacity: pressed && !showFeedback && mode === 'study' ? 0.7 : 1, })}> {(isSelected || showCorrect) && ( )} {option} ); })} {showFeedback && content.explanation && ( Erklärung: {content.explanation} )} ); const renderMixedCard = (content: MixedContent) => ( {card.title && {card.title}} {content.blocks.map((block, index) => ( {block.type === 'text' && ( {block.data.text} )} {block.type === 'image' && ( Bild: {block.data.caption || 'Ohne Titel'} )} {block.type === 'quiz' && ( Quiz-Block {renderQuizCard({ ...block.data } as QuizContent)} )} {block.type === 'flashcard' && ( Flashcard-Block {renderFlashcard({ ...block.data } as FlashcardContent)} )} ))} ); const renderCardContent = () => { switch (card.card_type) { case 'text': return renderTextCard(card.content as TextContent); case 'flashcard': return renderFlashcard(card.content as FlashcardContent); case 'quiz': return renderQuizCard(card.content as QuizContent); case 'mixed': return renderMixedCard(card.content as MixedContent); default: return ( Unbekannter Kartentyp ); } }; return ( {/* Card Header */} {showActions && ( {card.card_type} {card.is_favorite && } {onEdit && ( pressed && { opacity: 0.7 }}> )} )} {/* Card Content */} {renderCardContent()} {/* Card Footer */} {mode === 'view' && ( Position {card.position} Version {card.version} )} ); };