import { faStar } from "@fortawesome/free-solid-svg-icons";
import { faMessage } from "@fortawesome/free-regular-svg-icons";

import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import { 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";

const ShopCard = ({ product, like, index, liked, all, prods }) => {
  const navigation = useNavigation();
  const [shopProd, setshopProd] = useState([]);

  useEffect(() => {
    const purch = prods?.filter((item) => item.vendor_api_id === product._id);
    setshopProd(purch.slice(0, 3));
  }, []);
  return (
    <TouchableOpacity
      activeOpacity={0.7}
      style={styles.container}
      onPress={() => navigation.navigate("Shop", { product })}
    >
      <View style={styles.top}>
        <View style={styles.heart}>
          <Checkbox
            value={liked.includes(index) || all === true}
            onValueChange={() => like(index)}
          />
        </View>
        <View style={styles.imgWrap}>
          <Image
            style={{ width: 80, height: 80, resizeMode: "cover" }}
            source={{
              uri: product?.vendor_image
                ? product.vendor_image
                : "https://wkdonlinedogtraining.com/wp-content/themes/wkd-wp/build/images/bg-no-img-big.jpg",
            }}
          />
        </View>
        <View style={styles.details}>
          <Text style={styles.text} numberOfLines={2}>
            {product?.user_login}
          </Text>
          {/* {product?.rate ? ( */}
            <View style={styles.rateCon}>
              <Text style={styles.textHead}>Rating: </Text>
              {product?.rate ? (
                <>
                  <FontAwesomeIcon icon={faStar} color={"#eede00"} size={15} />
                  <Text style={styles.textRate}>
                    {product?.rate} ({product?.raterTotal})
                  </Text>
                </>
              ) : (
                <Text> </Text>
              )}
            </View>
          {/* ) : null} */}
          {/* {product?.respoTime ? ( */}
            <View style={styles.rateCon}>
              <Text style={styles.textHead}>Average Response Time: </Text>
              {product?.respoTime ? (
                <>
                  <Text style={styles.textRate}>{product?.respoTime}hrs</Text>
                </>
              ) : (
                <Text></Text> 
              )}
            </View>
          {/* ) : null} */}

          {product?.respoTime ? (
            <View style={styles.rateCon}>
              <Text style={styles.textHead}>Main Products: </Text>
              {product?.respoTime ? (
                <>
                  {/* {product?.tags.map((e, i) => (
                  <Text style={styles.textRate} key={i}>
                    {e},{" "}
                  </Text>
                ))} */}
                </>
              ) : (
                <Text> </Text>
              )}
            </View>
          ) : null}
        </View>
        <View style={styles.btnWrap}>
          <TouchableOpacity style={styles.btnmess}>
            <FontAwesomeIcon icon={faMessage} color={"#00C85C"} size={25} />
          </TouchableOpacity>
        </View>
      </View>

      <View style={styles.bot}>
        <View style={styles.botWrap}>
          {shopProd?.map((e, i) => (
            <Image
              key={i}
              style={{
                width: 100,
                height: 100,
                resizeMode: "cover",
                borderWidth: 1,
                borderColor: "#ddd",
                borderRadius: 10,
              }}
              source={{ uri: e.product_image }}
            />
          ))}
        </View>
      </View>
    </TouchableOpacity>
  );
};
const styles = StyleSheet.create({
  container: {
    width: "98%",
    margin: 5,
    borderRadius: 6,
    borderColor: "#dddd",
    overflow: "hidden",
  },
  wrapper: {
    width: "100%",
    alignItems: "center",
    justifyContent: "center",
  },
  top: {
    width: "100%",
    justifyContent: "space-between",
    alignItems: "center",
    height: 150,
    flexDirection: "row",
    backgroundColor: "#FFFFFF",
  },
  heart: {
    marginLeft: 10,
  },
  imgWrap: {
    width: 100,
    height: 80,
    alignItems: "center",
    justifyContent: "center",
    marginLeft: 10,
  },
  btnWrap: {
    width: 80,
    height: 80,
    // backgroundColor: "#ffaa00",
    alignItems: "center",
    justifyContent: "center",
  },
  btnmess: {
    backgroundColor: "#74fab2",
    padding: 15,
    borderRadius: 10,
  },
  details: {
    height: "100%",
    width: "45%",
    justifyContent: "center",
    // alignItems:'center'
  },
  header: {
    fontSize: 14,
    fontWeight: "700",
    textTransform: "uppercase",
  },
  text: {
    fontSize: 15,
    fontWeight: "900",
    textTransform: "uppercase",
    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",
    color: "#bdbdbd",
  },
  textSold: {
    fontSize: 11,
    fontWeight: "600",
    color: "#bdbdbd",
  },
  rateCon: {
    flexDirection: "row",
    alignItems: "center",
    paddingVertical: 3,
  },
  textHead: {
    fontSize: 11,
    color: "#292929",
  },
  textRate: {
    fontSize: 12,
    color: "#838383",
    textTransform: "capitalize",
  },
  img: {
    width: 400,
    height: 200,
    resizeMode: "cover",
    margin: "auto",
    borderRadius: 10,
  },
  bot: {
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#fff",
    paddingVertical: 10,
  },
  botWrap: {
    width: "100%",
    flexDirection: "row",
    justifyContent: "space-around",
  },
  footer: {
    flexDirection: "row",
    justifyContent: "space-between",
  },
});
export default ShopCard;
