import { faHeart, faLocation, faLocationArrow, faLocationPin, faStar, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome"; import { useIsFocused, useNavigation } from "@react-navigation/native"; import React, { useEffect, useState } from "react"; import { Image, Platform, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import CheckBox from "expo-checkbox"; import nobg from "../../.././assets/bg-no-img-big.jpg"; const ProductCard = ({ product, vendor, index, productAll }) => { const navigation = useNavigation(); // console.log(product + "ProductCard" + "index: " + index); const [isChecked, setIsChecked] = useState(false); const [variablePrice, setvariablePrice] = useState(""); // console.log(product+"hh") const isFocused = useIsFocused(); // console.log(productAll) useEffect(() => { // setactiveProduct(product); const purch = productAll?.filter((item) => item?.parent_id === product._id); // setvariations(purch);asus console.log(product._id); function getLowestHighestPrice(variation) { let lowestPrice = Infinity; let highestPrice = -Infinity; let hasPrice = false; variation?.forEach((item) => { let price = null; // If sale_price is available and not an empty string, use it; otherwise, use regular_price if (item?.sale_price && item?.sale_price !== "") { price = parseFloat(item?.sale_price); } else if (item?.regular_price && item?.regular_price !== "") { price = parseFloat(item?.regular_price); } // Update lowest and highest prices if (price !== null) { hasPrice = true; lowestPrice = Math.min(lowestPrice, price); highestPrice = Math.max(highestPrice, price); } }); if (!hasPrice) { return null; } // If lowest and highest prices are the same, return that price alone if (lowestPrice === highestPrice) { return `${lowestPrice}`; } // Return the range of lowest to highest prices return `${lowestPrice}-${highestPrice}`; } const priceRange = getLowestHighestPrice(purch); setvariablePrice(priceRange); console.log("-----------------------Price Range:", priceRange); }, [isFocused]); return ( navigation.navigate("Product", { product })} > {/* like(index)} /> */} {product?.product_name} {product.product_type === "variable" ? ( {variablePrice ? ( " ₱" + parseFloat(variablePrice).toLocaleString('en-US') ) : ( Inquire for price )} ) : ( {product?.regular_price && product?.regular_price !== null ? ( "₱" + parseFloat(product?.regular_price).toLocaleString('en-US') ) : ( Inquire for price )} {product.sale_price ? ( {" "} {/* {(product.regular_price * (1 - product.promo / 100)).toFixed(2) }{" "} */} {parseFloat(product?.sale_price).toLocaleString('en-US')} {/* (-{product.promo}%) */} ) : null} )} {/* min. order: {product?.min} {product?.per} */} stock: {product.stock} {product?.sold} sold {/* min. order: {product?.min} {product?.per} */} {vendor.shipping_city} {product?.rate ? ( {product.rate} ({product?.raterTotal}) ) : null} ); }; const styles = StyleSheet.create({ container: { // flex: 1, // backgroundColor: "#ff3333", width: "95%", margin: 5, borderRadius: 6, borderColor: "#dddd", overflow: "hidden", }, wrapper: { width: "100%", // height: 200, alignItems: "center", justifyContent: "center", // backgroundColor: "#ffaa00", }, header: { fontSize: 14, fontWeight: "700", textTransform: "uppercase", }, upper: {}, heart: { position: "absolute", top: 10, right: 10, height: 20, width: 20, }, text: { fontSize: 13, fontWeight: "600", textTransform: "capitalize", color: "#333", letterSpacing: 0.5, }, priceCon: { flexDirection: "row", paddingVertical: 4, }, textPrice: { fontSize: 16, fontWeight: "600", textTransform: "capitalize", color: "#ffaa00", }, textPricePromo: { fontSize: 16, fontWeight: "600", textTransform: "capitalize", textDecorationLine: "line-through", color: "#ffaa00", }, textMin: { fontSize: 11, fontWeight: "600", // textTransform: "capitalize", color: "#bdbdbd", }, textMin1: { fontSize: 11, fontWeight: "600", // textTransform: "capitalize", color: "#bdbdbd", }, textSold: { fontSize: 11, fontWeight: "600", // textTransform: "capitalize", color: "#bdbdbd", }, rateCon: { flexDirection: "row", // justifyContent:'center', alignItems: "center", paddingVertical: 3, }, inquire: { fontSize: 16, fontWeight: "600", // textTransform: "capitalize", // textDecorationLine: "line-through", color: "#ffaa00", }, textRate: { fontSize: 12, color: "#838383", }, img: { width: 400, height: 200, resizeMode: "cover", margin: "auto", borderRadius: 10, // backgroundColor: "#ffaa00", }, footer: { flexDirection: "row", justifyContent: "space-between", }, footer1: { marginTop: 10, flexDirection: "row", justifyContent: "space-between", }, }); export default ProductCard;