import React, { useState } from 'react'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Share, Alert } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'; import { ColorPalette, IdentificationResult } from '../types'; import { useColors } from '../constants/Colors'; import { SafeImage } from './SafeImage'; interface ResultCardProps { result: IdentificationResult; imageUri: string; onSave: () => void; onClose: () => void; t: any; isDark: boolean; colorPalette: ColorPalette; isGuest?: boolean; } export const ResultCard: React.FC = ({ result, imageUri, onSave, onClose, t, isDark, colorPalette, isGuest = false, }) => { const colors = useColors(isDark, colorPalette); const insets = useSafeAreaInsets(); const [showDetails, setShowDetails] = useState(false); const handleShare = async () => { try { await Share.share({ message: `I just identified a ${result.name} (${result.botanicalName}) with ${Math.round(result.confidence * 100)}% confidence using GreenLens!`, }); } catch (error: any) { Alert.alert('Error', error.message); } }; return ( {/* Header */} {t.result} {/* Hero Image */} {Math.round(result.confidence * 100)}% {t.match} {/* Info */} {result.name} {result.botanicalName} {result.description || t.noDescription} {/* Care Check */} {t.careCheck} setShowDetails(!showDetails)}> {showDetails ? t.hideDetails : t.showDetails} {[ { icon: 'water' as const, label: t.water, value: result.careInfo.waterIntervalDays <= 7 ? t.waterModerate : t.waterLittle, color: colors.info, bg: colors.infoSoft }, { icon: 'sunny' as const, label: t.light, value: result.careInfo.light, color: colors.warning, bg: colors.warningSoft }, { icon: 'thermometer' as const, label: t.temp, value: result.careInfo.temp, color: colors.danger, bg: colors.dangerSoft }, ].map((item) => ( {item.label} {item.value} ))} {showDetails && ( {t.detailedCare} {[ { text: t.careTextWater.replace('{0}', result.careInfo.waterIntervalDays.toString()), color: colors.success }, { text: t.careTextLight.replace('{0}', result.careInfo.light), color: colors.warning }, { text: t.careTextTemp.replace('{0}', result.careInfo.temp), color: colors.danger }, ].map((item, i) => ( {item.text} ))} )} {/* Save */} {t.dataSavedLocally} {isGuest ? t.registerToSave : t.addToPlants} ); }; const styles = StyleSheet.create({ container: { flex: 1 }, header: { position: 'absolute', top: 0, left: 0, right: 0, zIndex: 10, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 20, }, headerBtn: { borderRadius: 20, padding: 8, borderWidth: 1, }, headerBadge: { borderRadius: 20, paddingHorizontal: 12, paddingVertical: 4, borderWidth: 1, }, headerBadgeText: { fontWeight: '700', fontSize: 13 }, scrollContent: { paddingHorizontal: 16 }, heroContainer: { width: '100%', aspectRatio: 4 / 3, borderRadius: 24, overflow: 'hidden', marginBottom: 20, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.15, shadowRadius: 8, elevation: 6, }, heroImage: { width: '100%', height: '100%', resizeMode: 'cover' }, confidenceBadge: { position: 'absolute', bottom: 14, left: 14, borderRadius: 20, paddingHorizontal: 10, paddingVertical: 6, flexDirection: 'row', alignItems: 'center', gap: 4, }, confidenceText: { fontSize: 11, fontWeight: '700' }, plantName: { fontSize: 28, fontWeight: '700', marginBottom: 2 }, botanical: { fontSize: 13, fontStyle: 'italic', marginBottom: 14 }, description: { fontSize: 13, lineHeight: 20, marginBottom: 24 }, careHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 12, }, sectionTitle: { fontSize: 16, fontWeight: '700' }, detailsToggle: { fontSize: 10, fontWeight: '700', textTransform: 'uppercase', letterSpacing: 0.5 }, careGrid: { flexDirection: 'row', gap: 10, marginBottom: 20 }, careCard: { flex: 1, alignItems: 'center', padding: 12, borderRadius: 18, borderWidth: 1, gap: 6, }, careIcon: { width: 32, height: 32, borderRadius: 16, justifyContent: 'center', alignItems: 'center' }, careLabel: { fontSize: 10, fontWeight: '500' }, careValue: { width: '100%', fontSize: 11, lineHeight: 14, fontWeight: '700', textAlign: 'center', flexShrink: 1, }, detailsBox: { borderRadius: 18, borderWidth: 1, padding: 16, marginBottom: 20, gap: 10, }, detailsTitle: { fontSize: 11, fontWeight: '700', textTransform: 'uppercase', letterSpacing: 0.5 }, detailRow: { flexDirection: 'row', alignItems: 'flex-start', gap: 10 }, detailDot: { width: 6, height: 6, borderRadius: 3, marginTop: 6 }, detailText: { fontSize: 13, flex: 1 }, localInfo: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', gap: 6, marginBottom: 12 }, localIcon: { width: 12, height: 12, borderRadius: 2, borderWidth: 1, borderColor: '#d6d3d1' }, localText: { fontSize: 11 }, saveBtn: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', gap: 8, backgroundColor: '#4ade80', paddingVertical: 16, borderRadius: 14, shadowColor: '#4ade80', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 8, elevation: 6, }, saveBtnText: { fontWeight: '700', fontSize: 14 }, });