import { Ionicons } from "@expo/vector-icons"; import { router } from "expo-router"; import { Image, Pressable, View } from "react-native"; import { AddButton } from "@/components/ui/Button"; import { Badge, Price, StockLabel } from "@/components/ui/Badge"; import { MetaTag } from "@/components/ui/Chip"; import { Text } from "@/components/ui/Text"; import { getDrugFacts } from "@/lib/data/clinical"; import type { Product } from "@/lib/data/products"; import { routes } from "@/lib/routes"; import { useCartStore } from "@/lib/stores/cartStore"; import { useFavoritesStore } from "@/lib/stores/favoritesStore"; import { colors, radii, shadows, space } from "@/lib/theme"; import { formatETB } from "@/lib/utils"; export const GRID_CARD_GAP = 12; function discount(product: Product) { if (!product.compareAt || product.compareAt <= product.price) return null; return `${Math.round(((product.compareAt - product.price) / product.compareAt) * 100)}% OFF`; } function useCardActions(product: Product) { const addProduct = useCartStore((s) => s.addProduct); return { open: () => router.push(routes.product(product.id)), add: () => addProduct(product, 1), }; } /** Grid tile used in shop, search results and category listings. */ export function ProductCard({ product, width, }: { product: Product; width?: number | `${number}%`; }) { const { open, add } = useCardActions(product); const facts = getDrugFacts(product); const off = discount(product); return ( [ { width, backgroundColor: colors.surface, borderRadius: radii.card, borderWidth: 1, borderColor: colors.line, padding: space.md, opacity: pressed ? 0.94 : 1, }, shadows.xs, ]} > {off ? ( ) : null} {product.requiresPrescription ? ( ) : null} {facts.useCase} {product.name} ); } /** Horizontal row used in "Most popular", favorites and list-view results. */ export function ProductRow({ product }: { product: Product }) { const { open, add } = useCardActions(product); const facts = getDrugFacts(product); return ( [ { flexDirection: "row", gap: space.md, backgroundColor: colors.surface, borderRadius: radii.card, borderWidth: 1, borderColor: colors.line, padding: space.md, alignItems: "center", opacity: pressed ? 0.94 : 1, }, shadows.xs, ]} > {facts.useCase} {product.name} ); } /** Compact tile for horizontal carousels on the home screen. */ export function ProductTile({ product }: { product: Product }) { const { open, add } = useCardActions(product); const liked = useFavoritesStore((s) => s.has(product.id)); const toggle = useFavoritesStore((s) => s.toggle); const off = discount(product); return ( [ { width: 158, backgroundColor: colors.surface, borderRadius: radii.card, borderWidth: 1, borderColor: colors.line, padding: space.md, opacity: pressed ? 0.94 : 1, }, shadows.xs, ]} > {off ? ( ) : null} toggle(product.id)} hitSlop={8} style={{ position: "absolute", top: 6, right: 6, width: 26, height: 26, borderRadius: 13, backgroundColor: colors.surface, alignItems: "center", justifyContent: "center", }} > {product.name} ); }