import React, { useEffect, useState } from "react"; import { ImageSourcePropType, StyleProp, ViewStyle, View, TextStyle, DimensionValue, StyleSheet, Image, ImageURISource, I18nManager, } from "react-native"; import Card from "../Card"; import { useTheme } from "../../../theme/ThemeContext"; import { ThemeType } from "../../../theme"; import { LockOverlay } from "../../LockOverlay"; import { ThemedText as Text } from "../../ui"; interface SelaDealCardProps { variant: "horizontal" | "vertical"; backgroundImage: ImageURISource; label?: string; labelStyle?: StyleProp; labelContainerStyle?: StyleProp; providerName?: string; providerNameStyle?: StyleProp; description?: string; descriptionStyle?: StyleProp; price?: string; priceStyle?: StyleProp; priceContainerStyle?: StyleProp; onPress?: () => void; style?: StyleProp; // Overall card style width?: DimensionValue; height?: DimensionValue; isRTL?: boolean; borderRadius?: number; contentColor?: string; // For text like providerName, description on the image labelBackgroundColor?: string; labelTextColor?: string; priceContainerBlur?: number; priceBackgroundColor?: string; priceTextColor?: string; darkOverlayEnabled?: boolean; // New prop darkOverlayColor?: string; // New prop for custom overlay color lockOverlay?: boolean; showGrayscale?: boolean; lockIcon?: React.ReactNode; itemId?: string; gestureHandler?: boolean } const SelaDealCard: React.FC = ({ variant, backgroundImage, label, labelStyle, labelContainerStyle, providerName, providerNameStyle, description, descriptionStyle, price, priceStyle, priceContainerStyle, itemId, onPress, style, width = "100%", height, isRTL: propIsRTL, borderRadius = 12, // Default based on images darkOverlayEnabled = true, darkOverlayColor = "rgba(0, 0, 0, 0.3)", lockOverlay = false, lockIcon, priceContainerBlur, showGrayscale = false, gestureHandler = false }) => { const { theme, isRTL: themeIsRTL } = useTheme(); const isRTL = propIsRTL !== undefined ? propIsRTL : themeIsRTL; const styles = getStyles(theme, isRTL); const [dynamicHeight, setDynamicHeight] = useState(); useEffect(() => { if ( height === undefined && typeof width == "number" && width && backgroundImage && backgroundImage.uri ) { Image.getSize(backgroundImage.uri, (imgWidth, imgHeight) => { if (imgWidth > 0 && imgHeight > 0) { const aspectRatio = imgHeight / imgWidth; setDynamicHeight(width * aspectRatio); } else { setDynamicHeight(200); } }); } else if (height !== undefined) { setDynamicHeight(undefined); } }, [backgroundImage, height, width]); const finalLabelContainerStyle: StyleProp = [ styles.labelContainerBase, labelContainerStyle, ]; const finalLabelStyle: StyleProp = [ styles.labelTextBase, labelStyle, ]; const finalPriceContainerStyle: StyleProp = [ styles.priceContainerBase, variant === "horizontal" ? styles.priceContainerHorizontal : styles.priceContainerVertical, priceContainerStyle, ]; const finalPriceStyle: StyleProp = [ styles.priceTextBase, priceStyle, ]; const providerTextStyle: StyleProp = [ styles.providerNameBase, { color: theme.onSurface}, providerNameStyle, ]; const descriptionTextStyle: StyleProp = [ styles.descriptionBase, { color: theme.onSurface}, descriptionStyle, ]; return ( {darkOverlayEnabled && ( )} {label && ( {label} )} {variant === "horizontal" ? ( {providerName && ( {providerName} )} {description && ( {description} )} {price && ( {price} )} ) : ( {providerName && ( {providerName} )} {description && ( {description} )} {price && !priceContainerBlur && ( {price} )} )} ); }; const getStyles = (theme: ThemeType, isRTL: boolean) => StyleSheet.create({ cardBase: { overflow: "hidden", position: "relative", }, overlayContainer: { flex: 1, padding: 16, justifyContent: "space-between", }, topSection: { flexDirection:"row", }, labelContainerBase: { paddingVertical: 6, paddingHorizontal: 12, borderRadius: 8, backgroundColor: theme.background, }, labelTextBase: { fontWeight: "600", fontSize: 13, color: theme.onBackground, }, providerNameBase: { fontSize: 20, marginBottom: 2, color: theme.secondary, }, descriptionBase: { fontSize: 14, color: theme.helper, }, priceContainerBase: { paddingVertical: 8, paddingHorizontal: 16, borderRadius: 10, overflow: "hidden", backgroundColor: theme.primary, }, priceTextBase: { fontSize: 16, color: theme.onPrimary, }, bottomContentHorizontal: { flexDirection: "row", alignItems: "flex-end", }, textBlockHorizontal: { flex: 1, alignItems:"flex-start", marginRight: 10, }, priceContainerHorizontal: {}, bottomContentVertical: { flexDirection: "column", }, textBlockVertical: { marginBottom: 12, alignItems:"flex-start" }, priceContainerVertical: { alignSelf: "stretch", alignItems: "center", }, }); export default SelaDealCard;