// import { Dimensions, Image, Platform, RefreshControl, ScrollView, TouchableOpacity, View } from "react-native";
// import { ActivityIndicator, Avatar, Button, Card, Colors, IconButton, Modal, Surface, Text, TextInput, TouchableRipple } from "react-native-paper";
// import { useDispatch, useSelector } from "react-redux";
// import React, { useEffect, useState } from "react";
// import Header from "./header/header";
// import ImageCarousel from "../../components/custom/image-carousel";
// import { getBiddingProductDetails, getbiddingpartnerProductsAction, getbiddingUserReviewsbyIdAction, addbiddingProductReviewAction, getProductsImageAction } from "../../state/actions/bidding/biddingproductActions";
// import isEmpty from "../../state/validations/is-empty";
// import ESIbiddingCommentModel from "./biddingcomments";
// import { useToast } from "../../components/custom/react-native-paper-toast/src";
// import { Rating } from "react-native-ratings";
// import RenderHTML from "react-native-render-html";


// export default function BidProductDetails(props: any) {
//   const EmailID = useSelector(state => state.auth.user?.Email_Id);
//   const ID = useSelector(state => state.auth.user?.Partner_Details_Id)
//   const isAuthenticated = useSelector(state => state?.auth?.isAuthenticated);
//   console.log(isAuthenticated,"ddddddddddddd")
//   const dimensions = Dimensions.get('window');
//   const { height, width } = dimensions;
//   const { navigation } = props;
//   const dispatch = useDispatch();
//   const [loading, setLoading] = useState(false);
//   const [product, setProduct] = useState({});
//   console.log(product, "product")
//   const [addData, setDataChat] = useState({});
//   const [chatvisible, setChatVisible] = React.useState(false);
//   const [partnerproductss, setPartnerproduct] = useState({});
//   const [review, setReview] = useState({});
//   let partnerproduct = useSelector((state) => state.comment.biddingpartnerproducts.all);
//   console.log(partnerproduct, "ggggggggggg")
//   let productImage = useSelector((state) => state.comment.biddingproductImages.all);
//   let productReviews = useSelector((state) => state.comment.biddingquoteReviews.all);
//   console.log(productReviews, "reviews")
//   const hideModal = () => setChatVisible(false);
//   const Product_Id = props?.route?.params?.id;
//   const containerStyle = { backgroundColor: 'white', padding: 20, flex: 1, width: 350, maxWidth: 500, minWidth: 300, minHeight: 350, maxHeight: 400, borderRadius: 10, alignSelf: "center" };
//   const [productLoading, setProductLoading] = useState(false);
//   const [id, setID] = useState();
//   const [commenterror, setCommentError] = useState("")
//   const [ratingerror, setRatingError] = useState("")
//   const [comment, setComment] = useState("");
//   const [rating, setRating] = useState(0);
//   const toast = useToast();
//   const [error, setError] = useState("")
//   const [isModalVisible, setModalVisible] = React.useState(false);
//   const [isReviewModalVisible, setReviewModalVisible] = React.useState(false);
//   const [size, setSize] = useState({ size: "", quantity: "" })
//   const [modalIsOpen, setModalIsOpen] = React.useState(false);
//   const [PartnerDetails, setPartnerDetails] = useState();
//   const [selected, setSelected] = useState(false);
//   const [visible, setVisible] = useState(2);
//   let quoteid =partnerproduct.B2B_Partner_Bidding_Quote_Id
//   let existcomment;
//   const addReviewModal = () => {
//     if (!isEmpty(comment) && rating > 0) {
//       setCommentError("")
//       setRatingError("")
//       let formData = {
//         B2B_User_Products_Bidding_Id: Product_Id,
//         User_Review_For_Partner: comment,
//       }
//       let formValues = JSON.parse(JSON.stringify(formData));
//       dispatch(addbiddingProductReviewAction(formValues, Product_Id, responseFunction));
//     } else {
//       if (isEmpty(comment)) {
//         setCommentError("Comment is required.")
//       }
//       if (isEmpty(rating)) {
//         setRatingError("Rating is required.")
//       }
//     }

//   }

//   const responseFunction = (status, message) => {
//     toast.show({ message: message, type: 'info', duration: 3000, position: 'top' });
//     setReviewModalVisible(!isReviewModalVisible);
//     setComment("");
//     setRating("");
//   }

//   const toggleModal = () => {
//     if (isAuthenticated) {
//       setReviewModalVisible(!isReviewModalVisible);
//     }
//     else {
//       setModalVisible(true);
//     }
//   };
//   // Comment validations

//   const handleOnChange = (value) => {
//     if (existcomment > 0) {
//       setError("You have already added review.")
//     }
//     if (value === "") {
//       setError("")
//     }
//   }
//   const onCloseModal = () => {
//     setSize({ size: "", quantity: "" })
//     setModalIsOpen(false);
//     setSelected(false)
//     // setPartnerDetails()
//     setComment("")
//     setRating("")
//   };

//   const [reviewId, setData] = useState()
//   let Id = [];
//   let multiID;
//   const callBackGetData = (data) => {
//     if (data) {
//       setProduct(data);
//       setPartnerproduct(data);
//       setReview(data);
//       getreviews(data);
//       setID(Product_Id)
//     }
//   };

//   let image = []
//   if (productImage) {
//     if (productImage[0]) {
//       if (productImage[0].Product_Image) {
//         let data = productImage[0].Product_Image
//         for (var i = 0; i < data.length; i++) {
//           image.push({ imageuri: data[i].Product_Image })
//         }
//       }
//     }
//   }
//   useEffect(() => {
//     if (Product_Id != product?.Bidding_Product_Id) {
//       setProductLoading(true);
//       setProduct({});
//       dispatch(getBiddingProductDetails(Product_Id, callBackGetData, ID));
//       dispatch(getbiddingpartnerProductsAction(Product_Id, ID));
//       // dispatch(getbiddingUserReviewsbyIdAction(Product_Id));
//       dispatch(getProductsImageAction(Product_Id));
//     }
//   }, [Product_Id]);
//   const getreviews = () => {
//     setReview({})
//     dispatch(getbiddingUserReviewsbyIdAction(quoteid));

//   }
//   if (productReviews) {
//     existcomment = productReviews.filter(review => review.User_Email_Id === EmailID).length
//   }

//   return (
//     <Surface style={{ flex: 1 }}>
//       <Header {...props} />
//       <View>
//         {navigation.canGoBack() &&
//           <IconButton
//             icon="arrow-left"
//             size={27}
//             color={"#27B6CC"}
//             style={{ marginTop: -2, marginLeft: 1 }}
//             onPress={() => props.navigation.goBack()}
//           />}
//       </View>
//       {product ?
//         <ScrollView style={{ maxHeight: dimensions.height - 20 }}>
//           <View>
//             <ImageCarousel image={image} dimensions={dimensions} />
//             <Text style={{ textAlign: 'center', fontSize: 15, color: 'black', fontWeight: 'bold' }}>{product[0]?.Product_Name}</Text>
//             <Text >Status: {product[0]?.Status}</Text>
//             <Text >Quantity: {product[0]?.Quantity}</Text>
//             <Text >Pincode: {product[0]?.User_Pincode}</Text>
//             <Text >Advance Amount: {product[0]?.Total_Advance_Amount}</Text>
//             <Text >Remaining Amount: {product[0]?.Partner_Balance_Amount}</Text>

//           </View>
//           <View>
//             <TouchableOpacity
//               style={{
//                 alignItems: "center",
//                 backgroundColor: "#27b6cc",
//                 padding: 10,
//                 margin: 'auto',
//                 borderRadius: 8
//               }}
//               onPress={() => {

//                 payNow();

//               }}
//             >
//               <Text style={{ color: 'white' }} >Pay </Text>
//             </TouchableOpacity>
//             <View>
//               <Text style={{ fontSize: 15, color: 'black' }}>Description:{product[0]?.Description}</Text>
//             </View>
//           </View>
//           <ScrollView
//             horizontal
//             showsHorizontalScrollIndicator={false}>
//             <View >
//               {!isEmpty(partnerproduct) ? (
//                 partnerproduct.Is_Data_Exist === "0" ? (
//                   <NoDataFound text={partnerproduct.UI_Display_Message} />
//                 ) : typeof partnerproduct === "object" ? (
//                   partnerproduct.map((data, index) => (

//                     <View style={{ alignItems: 'flex-start', flexDirection: 'column' }} >

//                       <Card key={data, index} style={{
//                         shadowColor: '#0E9EAD',
//                         shadowOffset: { width: -2, height: 4 },
//                         shadowOpacity: 0.2,
//                         shadowRadius: 3,
//                         marginHorizontal: 2, borderRadius: 10, padding: 2, backgroundColor: 'white', marginTop: (Platform.OS === 'web' ? 10 : 10), flexDirection: 'column',
//                         elevation: 10,
//                         maxWidth: (Platform.OS === 'web' ? 650 : 550),
//                         minWidth: (Platform.OS === 'web' ? '30%' : '95%'),
//                         maxHeight: height > 250 ? 250 : 90,
//                         minHeight: 100,
//                         borderColor: 'grey',
//                         borderWidth: 0.5,
//                       }}>
//                         <View style={{ flex: 3, alignContent: 'center', marginLeft: 10 }} >
//                           <Image style={{ width: 45, height: 50, borderRadius: 20, marginLeft: 20 }} source={{ uri: data.Product_Image }} />
//                         </View>
//                         <View style={{ flex: 6, flexDirection: 'column' }}  >
//                           <Text style={{ fontSize: 14, paddingTop: 10, fontWeight: 'bold', fontFamily: 'system-ui' }}>{data?.Partner_Name}</Text>
//                           <Text style={{ fontSize: 12, fontFamily: 'system-ui' }}>Quantity: {data?.Quantity} {data?.Measurement_Type}</Text>
//                           <Text style={{ fontSize: 12, fontFamily: 'system-ui' }}>Advance Amount : {data?.Advance_Amount}</Text>
//                           <Text style={{ fontSize: 12, fontFamily: 'system-ui' }}>Balance Amount : {data?.Total_Amount}</Text>
//                         </View>
//                       </Card>
//                     </View>

//                   ))) : (
//                   typeof partnerproduct
//                 )
//               ) : (
//                 <View style={{ marginBottom: 20, paddingLeft: 15 }}>
//                   <Text style={{ color: 'black', fontWeight: 'bold' }}>Oops!!! No Partner Products found.</Text>
//                 </View>
//               )}
//             </View>

//             <View>
//               <Button
//                 style={{
//                   alignItems: "center",
//                   backgroundColor: "#27b6cc",
//                   padding: 10,
//                   margin: 'auto',
//                   borderRadius: 8
//                 }}
//                 onPress={() => { setChatVisible(true), setDataChat(product[0]?.Bidding_Product_Id) }}
//               >
//                 <Text style={{ color: 'white' }} >Add Comments </Text>
//               </Button>
//             </View>
//           </ScrollView>

//           <View style={{ width: dimensions.width <= 700 ? '100%' : '80%' }}>
//           <TouchableOpacity  disabled={(productReviews?.Is_Data_Exist || productReviews?.filter((review) => {
//                   return review.User_Email_Id=== EmailID
//                 }).length) <= 0 ? false : true} style={{
//                   backgroundColor: (productReviews?.filter((review) => {
//                     return review.User_Email_Id === EmailID
//                   }).length) <= 0 ? '#27B6CC' : '#F0F0F0', width: 110, height: 30, borderRadius: 5, justifyContent: 'center', alignItems: 'center'
//                 }} onPress={() =>setReviewModalVisible(true) }>
//                   <Text style={{ color: '#ffffff' }}>ADD REVIEW</Text>
//                 </TouchableOpacity>
//             <View>
//               {!isEmpty(productReviews) && (
//                 productReviews.Is_Data_Exist === "0" || isEmpty(productReviews) ? (
//                   <View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}>
//                     <Text style={{ color: 'black', fontWeight: 'bold' }}>No Product Reviews found!</Text>
//                   </View>
//                 ) : typeof productReviews === "object" && (
//                   <>
//                     {productReviews?.slice(0, visible).map((data, index) => (
//                       <View key={index}>
//                         <View style={{ height: 1, backgroundColor: "#CCCCCC", }} />
//                         <View style={{
//                           paddingLeft: 1,
//                           paddingRight: 16,
//                           paddingVertical: 12,
//                           flexDirection: 'row',
//                           alignItems: 'flex-start'
//                         }}>

//                           <View style={{
//                             marginLeft: 16,
//                             flex: 1,
//                           }}>
//                             <View style={{
//                               flexDirection: 'row',
//                               justifyContent: 'space-between',
//                               marginBottom: 6
//                             }}>
//                               <Text style={{
//                                 fontSize: 16,
//                                 fontWeight: "bold",
//                               }}>{data.Full_Name}
//                               </Text>

//                             </View>
//                             <Text rkType='primary3 mediumLine'>{data.User_Review_For_Partner &&
//                               <RenderHTML
//                                 source={{ html: data.User_Review_For_Partner }}
//                               />}</Text>
//                           </View>
//                         </View>

//                       </View>
//                     ))}
//                     <View style={{ alignSelf: 'center', marginVertical: 15, marginTop: 2 }}>
//                       {productReviews?.length > visible &&
//                         <Text variant="contained" mode="outlined" style={{ fontWeight: 'bold', color: '#27b6cc' }} onPress={() => setVisible(visible + 3)}>Show More ▼</Text>
//                       }
//                     </View>
//                   </>
//                 ))}
//             </View>
//           </View>
//           <Modal animationIn={"slideInDown"}
//         deviceWidth={dimensions.width}
//         deviceHeight={dimensions.height}
//         style={{ alignItems: 'center' }} isVisible={isReviewModalVisible}>

//         <View style={{ flex: 1, maxWidth: 500, minWidth: 300, maxHeight: 325, borderRadius: 10, backgroundColor: Colors.white }}>
//           <View style={{
//             alignItems: 'flex-end', marginTop: '-6%'
//           }}>
//             <TouchableRipple style={{ width: 36 }} onPress={() => { setReviewModalVisible(false), setComment(''), setRating(0) }}>
//               <Avatar.Icon color={'black'} style={{ backgroundColor: Colors.white, marginTop: 30 }} size={36} icon="close" />
//             </TouchableRipple>
//           </View>
//           <View style={{ margin: '4%' }}>

//             <TextInput
//               label='Add Review'
//               mode='outlined'
//               onChangeText={(Text) => { setComment(Text); handleOnChange(Text); setCommentError("") }}
//               multiline={true}
//               numberOfLines={4}
//               value={comment}
//             />
//             <Text style={{ color: 'red' }}>{commenterror}</Text>
//             <Text style={{ color: 'red' }}>{error}</Text>

//             <View style={{
//               alignItems: 'center',
//               justifyContent: 'center',
//               alignContent: 'center'
//             }}>


//               <View style={{ width: 100 }}>
//                 <Button style={{ alignItems: 'center', marginTop: 10 }} mode="contained" onPress={() => addReviewModal()}>
//                   Submit
//                 </Button>
//               </View>
//             </View>

//           </View>

//         </View>
//       </Modal>
//         </ScrollView> :

//         <ActivityIndicator color='#27b6cc' />

//       }
//       <Modal
//         visible={chatvisible} onDismiss={hideModal} contentContainerStyle={containerStyle}>
//         <ESIbiddingCommentModel navigation={navigation} openModal={chatvisible} data={partnerproduct} closeModal={hideModal} />
//       </Modal>

//     </Surface>
//   )
// }