import { faArrowLeft, faCheck } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import { useNavigation, useRoute } from "@react-navigation/native";
import React, { useState } from "react";
import {
  Dimensions,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from "react-native";
import Accordion from "../../components/checkout/Accordion";
const width = Dimensions.get("window").width;

const ShippingOptionMulti = () => {
  const navigation = useNavigation();
  const [selected, setselected] = useState("J&T Express");
  const route = useRoute();
  const { product, shipMethod, payMethod, address,orderId } = route.params;
  const shippingMethods = [
    {
      type: "J&T Express",
      eta: "Sept.22 - 23",
      price: 55,
    },
    {
      type: "Flash Express",
      eta: "Sept.22 - 25",
      price: 25,
    },
  ];
  return (
    <View style={styles.container}>
      <View style={styles.header}>
        <TouchableOpacity
          onPress={() =>
            navigation.navigate("CheckOutMultiple", {
              shipMethod: shipMethod,
              product,
              payMethod,
              address,
              orderId:orderId

            })
          }
          style={styles.backIcon}
        >
          <FontAwesomeIcon icon={faArrowLeft} color={"#d4c600"} size={25} />
        </TouchableOpacity>
        <Text style={styles.headerText}>Shipping Options</Text>
      </View>
      <View style={styles.wrapper}>
        {shippingMethods?.map((shippingMethod, i) => (
          <TouchableOpacity
            key={i}
            style={styles.listItem}
            onPress={() => setselected(shippingMethod.type)}
          >
            <View style={styles.listleft}>
              <View style={styles.listtop}>
                <Text style={styles.listItemText}> {shippingMethod.type}</Text>
                <Text style={styles.listItemTextPrice}>
                  {" "}
                  ₱{shippingMethod.price}
                </Text>
              </View>
              <Text style={styles.listItemTexteta}> {shippingMethod.eta}</Text>
            </View>
            {selected === shippingMethod.type ? (
              <FontAwesomeIcon icon={faCheck} color={"#d4c600"} size={25} />
            ) : null}
          </TouchableOpacity>
        ))}
      </View>
      <View style={styles.footer}>
        <TouchableOpacity
          style={styles.footerBtn}
          onPress={() =>
            navigation.navigate("CheckOutMultiple", {
              shipMethod: selected ? selected : shipMethod,
              product,
              payMethod,
              address,
              orderId:orderId

            })
          }
        >
          <Text style={styles.footerBtnText}>Confirm</Text>
        </TouchableOpacity>
      </View>
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    backgroundColor: "#fafafa",
    height: "100%",
    width: width,
  },
  header: {
    alignItems: "center",
    width: "100%",
    top: 0,
    paddingLeft: 15,
    backgroundColor: "#ffffff",
    flexDirection: "row",
    borderColor: "#ddd",
    paddingBottom: 15,
    borderBottomWidth: 1,
  },
  headerText: {
    fontSize: 16,
    fontWeight: "600",
    marginLeft: 25,
  },
  headerWrap: {
    justifyContent: "center",
    alignItems: "center",
    width: "100%",
    height: "100%",
    // flexDirection: "row",
  },
  footer: {
    position: "absolute",
    bottom: 0,
    width: "100%",
    justifyContent: "center",
    alignItems: "center",
    paddingVertical: 10,
  },
  footerBtn: {
    backgroundColor: "#ff5e00",
    width: "90%",
    paddingVertical: 10,
    justifyContent: "center",
    alignItems: "center",
    borderRadius:20,

  },
  footerBtnText: {
    color: "#fff",
    fontSize: 16,
  },
  wrapper: {
    // height: "85%",
    paddingTop: 25,
    width: "100%",
    // justifyContent: "center",
    alignItems: "center",
    // height: "100%",
  },
  content: {
    width: "100%",
    justifyContent: "center",
    alignItems: "center",
  },
  listItem: {
    backgroundColor: "#ffffff",

    width: "100%",
    borderWidth: 1,
    borderColor: "#ececec",
    padding: 15,
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
  },
  listleft: {},
  listtop: {
    flexDirection: "row",
  },
  listItemText: {
    fontSize: 16,

    fontWeight: "600",
  },
  listItemTextPrice: {
    fontSize: 16,
    fontWeight: "600",
    color: "#ffaa00",
    marginLeft: 10,
  },
  listItemTexteta: {
    fontSize: 14,
    marginTop: 5,
    fontWeight: "500",
    color: "#9c9c9c",
    marginLeft: 10,
  },
});

export default ShippingOptionMulti;
