import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import { Image, SafeAreaView, TouchableNativeFeedback, TouchableOpacity, View, Linking, Platform } from "react-native";
import { BottomSheetFlatList, BottomSheetModal, BottomSheetModalProvider } from '../bottomSheet/bottom-sheet';
import chatStore from '../../screens/chat/ChatStore';
import { MText as Text } from '../index';
import quickMessageStore from '../../screens/chat/QuickMessageStore';
import colors from '../../Styles';
import listChatStore from '../../screens/listchat/ListChatStore';
import appStore from '../../screens/AppStore';
import { formatTimeLastMessage } from '../../utils';
import { chatVT } from '../../index';
import { Navigation } from 'react-native-navigation';
import services from '../../services';
const BottomSheetChatOptionsVTM = /*#__PURE__*/React.forwardRef((props, ref) => {
  const snapPoints = useMemo(() => ['30%'], []);
  const bottomSheetRef = useRef();
  const [data, setData] = useState([]);
  const [order, setOrder] = useState({});
  const [typeUser, setTypeUser] = useState('');
  const [isSender, setIsSender] = useState(true);
  useImperativeHandle(ref,
  // forwarded ref
  () => {
    return {
      updateData(data, order, orderType, typeUser) {
        console.log('udpate', typeUser);
        setData(data);
        setOrder(order);
        setTypeUser(typeUser);
        setIsSender(orderType !== 4);
      },
      present() {
        var _bottomSheetRef$curre;
        (_bottomSheetRef$curre = bottomSheetRef.current) === null || _bottomSheetRef$curre === void 0 ? void 0 : _bottomSheetRef$curre.present();
      },
      dismiss() {
        var _bottomSheetRef$curre2;
        (_bottomSheetRef$curre2 = bottomSheetRef.current) === null || _bottomSheetRef$curre2 === void 0 ? void 0 : _bottomSheetRef$curre2.dismiss();
      }
    }; // the forwarded ref value
  }, []);
  const toChatWithCustomer = async (order_code, type) => {
    console.log('type', type);
    try {
      var _bottomSheetRef$curre3;
      (_bottomSheetRef$curre3 = bottomSheetRef.current) === null || _bottomSheetRef$curre3 === void 0 ? void 0 : _bottomSheetRef$curre3.dismiss();
    } catch (e) {}
    appStore.createConversation({
      order_number: order_code,
      chat_type: type,
      is_postman_receiver: props === null || props === void 0 ? void 0 : props.postman_receiver
    }, conversation => {
      Navigation.push(props.componentId, {
        component: {
          name: 'ChatScreen',
          options: {
            popGesture: false,
            bottomTabs: {
              visible: false
            },
            topBar: {
              visible: false,
              height: 0
            }
          },
          passProps: {
            data: conversation,
            order: order
          }
        }
      });
    }, error => alert(error));
  };
  return /*#__PURE__*/React.createElement(BottomSheetModalProvider, null, /*#__PURE__*/React.createElement(BottomSheetModal, {
    ref: bottomSheetRef,
    backdropComponent: () => {
      return /*#__PURE__*/React.createElement(TouchableOpacity, {
        activeOpacity: 1,
        onPress: () => {
          var _bottomSheetRef$curre4;
          return (_bottomSheetRef$curre4 = bottomSheetRef.current) === null || _bottomSheetRef$curre4 === void 0 ? void 0 : _bottomSheetRef$curre4.dismiss();
        },
        style: {
          position: 'absolute',
          width: '100%',
          height: '100%',
          backgroundColor: '#00000059'
        }
      });
    },
    index: 0,
    snapPoints: snapPoints,
    onDismiss: () => {}
  }, /*#__PURE__*/React.createElement(SafeAreaView, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => {
      var _bottomSheetRef$curre5;
      (_bottomSheetRef$curre5 = bottomSheetRef.current) === null || _bottomSheetRef$curre5 === void 0 ? void 0 : _bottomSheetRef$curre5.dismiss();
      if (isSender) {
        Linking.openURL(`sms:${order.dienthoai_nguoigui}${Platform.OS === 'ios' ? '&' : '?'}body=${''}`);
        return;
      }
      Linking.openURL(`sms:${typeUser === 'SENDER' ? order.tel_khgui : order.tel_khnhan}${Platform.OS === 'ios' ? '&' : '?'}body=${''}`);
    },
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16,
      alignItems: 'center'
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center',
      marginRight: 12
    }
  }, /*#__PURE__*/React.createElement(Image, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center'
    },
    source: require('../../assets/ic_sms.png')
  })), /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: colors.primaryText
    }
  }, `Tin nhắn văn bản (SMS)`)), /*#__PURE__*/React.createElement(View, {
    style: {
      backgroundColor: 'white',
      height: 1
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      backgroundColor: '#E5E5E5',
      height: 1,
      marginLeft: 76,
      marginRight: 16
    }
  })), /*#__PURE__*/React.createElement(TouchableOpacity, {
    onPress: () => toChatWithCustomer(isSender ? order.ma_vandon : order.ma_phieugui, typeUser),
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16
    }
  }, /*#__PURE__*/React.createElement(View, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center',
      marginRight: 12
    }
  }, /*#__PURE__*/React.createElement(Image, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center'
    },
    source: typeUser === 'SENDER' ? require('../../assets/avatar_postman.png') : require('../../assets/avatar_customer.png')
  })), /*#__PURE__*/React.createElement(View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: colors.primaryText
    }
  }, 'Chat với người - ' + (typeUser === 'SENDER' ? 'Gửi hàng' : 'Nhận hàng')), /*#__PURE__*/React.createElement(Text, {
    style: {
      fontSize: 15,
      fontWeight: '500',
      color: colors.neutralText,
      paddingTop: 4
    }
  }, isSender ? order.order_sendname : typeUser === 'SENDER' ? order.ten_khgui : order.ten_khnhan))))));
});
export default BottomSheetChatOptionsVTM;
//# sourceMappingURL=VTM.js.map