import React, { ReactNode } from 'react'; import { Image as RNImage, StyleSheet, TextProps, View, ViewProps, } from 'react-native'; import { TouchableComponent } from '../TouchableComponent'; import { Box } from '../Box'; import { Text } from '../Text'; import { useTheme } from '../../theme/ThemeProvider'; import type { Theme } from '../../theme/theme'; import { createBox, createText } from '@shopify/restyle'; import { ImageSquare } from 'phosphor-react-native'; import CheckCircle from '../../icons/CheckCircle'; import XCircle from '../../icons/XCircle'; import WarningCircle from '../../icons/WarningCircle'; import { Badge, BadgeProps } from '../Badge'; type ProductProps = { image?: string; referenceName: string; brand: string; sku: number | string; packaging: string; quantity?: number; currentQuantity?: number; extraInfo?: string; ean14?: boolean; quantityBadge?: BadgeProps['variant']; }; type StyleAndLogicProps = { onPress?: () => void; onLongPress?: () => void; onPressImage?: () => void; onLongPressOnImage?: () => void; onChangeInput?: (text: string) => void; children?: ReactNode; icon?: 'approved' | 'rejected' | 'warn' | ReactNode; height?: number | string; rightContent?: ReactNode; titleLines?: number; borderRadius?: number; disabled?: boolean; disabledTooltipComponent?: ReactNode; }; type CardProps = ProductProps & StyleAndLogicProps; const ViewComponent = createBox( View ); const TextComponent = createText( Text ); const Image = ({ image, onPressImage, onLongPressOnImage, style, }: { image?: string; onPressImage?: () => void; onLongPressOnImage?: () => void; style?: object; }) => { if (onPressImage || onLongPressOnImage) { return ( ); } return ( {!image ? ( ) : ( )} ); }; export const ProductCard = ({ onPress, onLongPress, onPressImage, onLongPressOnImage, image, referenceName, brand, sku, packaging, quantity, currentQuantity, children, icon, height, rightContent, extraInfo, ean14 = false, borderRadius = 4, titleLines = 1, quantityBadge, disabled = false, disabledTooltipComponent, }: CardProps) => { const { fonts, colors } = useTheme(); const onPressOnImageAction = disabled ? undefined : onPressImage; const onLongPressOnImageAction = disabled ? undefined : onLongPressOnImage; const halfOpacityIfDisabled = disabled ? stylesProductCard.halfOpacity : stylesProductCard.fullOpaque; const Content = () => ( <> {referenceName} {disabledTooltipComponent && disabledTooltipComponent} {!!brand && ( {brand} )} {packaging} {sku} {!!extraInfo && ( {extraInfo} )} {!rightContent && (currentQuantity || quantity || icon || children) && ( {currentQuantity !== undefined ? currentQuantity : quantity} {quantityBadge && ( )} {currentQuantity === undefined || currentQuantity === quantity ? null : ( {quantity || currentQuantity} )} {!!children && children} {icon ? ( {icon === 'approved' ? ( ) : icon === 'rejected' ? ( ) : icon === 'warn' ? ( ) : ( icon )} ) : null} )} {rightContent} ); if ((onPress || onLongPress) && !disabled) { return ( ); } return ( ); }; const stylesProductCard = StyleSheet.create({ fullOpaque: { opacity: 1 }, halfOpacity: { opacity: 0.5 }, });