import React from 'react'; import { View, Text, Image, TouchableOpacity, StyleProp, ViewStyle, } from 'react-native'; import { getStyles } from './productCard.styles'; import { useAppTheme } from '@theme'; import { getFullUrl } from '@utils'; export interface ProductCardProps { id: string; name: string; imageUrl: string; price: string; compareAtPrice?: string; brand?: string | null; currency?: string; onPress?: () => void; onAddPress?: () => void; style?: StyleProp; } export const getDiscountPercentage = (price: string, comparePrice?: string) => { if (!comparePrice || !price) return null; const p = parseFloat(price); const c = parseFloat(comparePrice); if (c <= p || c <= 0) return null; const discount = Math.round(((c - p) / c) * 100); return discount > 0 ? `${discount}% OFF` : null; }; export const formatPrice = (price: string, currency: string = '₹') => { const num = parseFloat(price); return isNaN(num) ? price : `${currency}${num.toFixed(0)}`; }; export const ProductCard: React.FC = ({ id, name, imageUrl, price, compareAtPrice, brand, currency = '₹', onPress, onAddPress, style, }) => { const { colors } = useAppTheme(); const styles = getStyles(colors); const discountText = getDiscountPercentage(price, compareAtPrice); return ( {discountText && ( {discountText} )} 🤍 {brand && ( {brand} )} {name} {formatPrice(price, currency)} {compareAtPrice && parseFloat(compareAtPrice) > parseFloat(price) && ( {formatPrice(compareAtPrice, currency)} )} {/* + ADD */} ); };