import { PlusOutlined } from "@ant-design/icons"; import { Badge, Button, Card, Grid } from "antd"; import ArabicPrice from "components/ArabicPrice"; import HeartIcon from "components/Icons/HeartIcon"; import ImageWithFallback from "components/ImageWithFallback"; import { ItemDescriptionIcons } from "components/ItemDescriptionIcons/ItemDescriptionIcons"; import ProText from "components/ProText"; import { addItem, selectCartItems } from "features/order/orderSlice"; import { useCallback } from "react"; import { useTranslation } from "react-i18next"; import { Link, useParams } from "react-router-dom"; import { useAppDispatch, useAppSelector } from "redux/hooks"; import { colors } from "ThemeConstants"; import { Product } from "utils/types/appTypes"; import styles from "../MenuList/MenuList.module.css"; const { useBreakpoint } = Grid; interface ProductCardProps { products: Product[]; } export function ProductCard({ products }: ProductCardProps) { const { id } = useParams(); const { isRTL, locale } = useAppSelector((state) => state.locale); const { sm, md } = useBreakpoint(); const isMobile = !sm; const isTablet = sm && !md; const { themeName } = useAppSelector((state) => state.theme); const dispatch = useAppDispatch(); const cartItems = useAppSelector(selectCartItems); const getItemQuantity = (id: number | string) => { const item = cartItems.find((i) => i.id === id); return item ? item.quantity : 0; }; const { t } = useTranslation(); // Memoized handlers for better performance const handleQuickAdd = useCallback( (item: Product) => { dispatch( addItem({ item: { id: item.id, name: item.name, price: item.price, image: item.image, description: item.description, variant: "None", extras: [], extrasgroup: [], }, quantity: 1, }) ); }, [dispatch] ); const getMenuItemCardStyle = useCallback( (itemDescription: string) => { if (isMobile) { return { height: itemDescription?.length > 0 ? 160 : 130, padding: "12px 12px 12px 16px", }; } else if (isTablet) { return { height: 160, padding: "16px", }; } else { return { height: 180, padding: "20px", }; } }, [isMobile, isTablet] ); const getMenuItemImageStyle = useCallback(() => { if (isMobile) { return { width: 90, height: 95, }; } else if (isTablet) { return { width: 120, height: 120, }; } else { return { width: 140, height: 140, }; } }, [isMobile, isTablet]); return ( <> {products?.map((item) => (
{locale == "ar" ? item.nameOther : item.name} {item.description}
{/* Cart quantity badge - shows current quantity in cart */} {getItemQuantity(item.id) > 0 && ( )}
))} ); }