"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _bottomSheet = require("../bottomSheet/bottom-sheet");
var _ChatStore = _interopRequireDefault(require("../../screens/chat/ChatStore"));
var _index = require("../index");
var _QuickMessageStore = _interopRequireDefault(require("../../screens/chat/QuickMessageStore"));
var _Styles = _interopRequireDefault(require("../../Styles"));
var _ListChatStore = _interopRequireDefault(require("../../screens/listchat/ListChatStore"));
var _AppStore = _interopRequireDefault(require("../../screens/AppStore"));
var _utils = require("../../utils");
var _index2 = require("../../index");
var _reactNativeNavigation = require("react-native-navigation");
var _services = _interopRequireDefault(require("../../services"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const BottomSheetChatOptions = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
  const snapPoints = (0, _react.useMemo)(() => ['40%'], []);
  const bottomSheetRef = (0, _react.useRef)();
  const [data, setData] = (0, _react.useState)([]);
  const [order, setOrder] = (0, _react.useState)({});
  const [isSender, setIsSender] = (0, _react.useState)(true);
  (0, _react.useImperativeHandle)(ref,
  // forwarded ref
  () => {
    return {
      updateData(data, order, orderType) {
        setData(data);
        setOrder(order);
        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 toChat = listUserId => {
    _AppStore.default.createConversation({
      vtm_user_ids: listUserId,
      order_number: order.ORDER_NUMBER,
      is_receiver: !isSender
    }, conversation => {
      _reactNativeNavigation.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));
  };
  const toChatGroup = () => {
    try {
      var _bottomSheetRef$curre3;
      (_bottomSheetRef$curre3 = bottomSheetRef.current) === null || _bottomSheetRef$curre3 === void 0 ? void 0 : _bottomSheetRef$curre3.dismiss();
      _AppStore.default.createConversation({
        order_number: order.ma_phieugui,
        chat_type: 'GROUP'
      }, conversation => {
        _reactNativeNavigation.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));
    } catch (e) {}
  };
  const getUserIdFromOrder = async order_code => {
    try {
      var _response$data;
      const response = await _services.default.create().getVTMCustomerByOrder({
        order_code
      });
      console.log(response);
      if ((_response$data = response.data) !== null && _response$data !== void 0 && _response$data.data) {
        var _response$data2, _response$data2$data;
        return (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : (_response$data2$data = _response$data2.data) === null || _response$data2$data === void 0 ? void 0 : _response$data2$data.cus_id;
      } else {
        return 0;
      }
    } catch (e) {
      console.log(e);
      return -1;
    }
  };
  const toChatWithCustomer = async (order_code, type) => {
    try {
      var _bottomSheetRef$curre4;
      (_bottomSheetRef$curre4 = bottomSheetRef.current) === null || _bottomSheetRef$curre4 === void 0 ? void 0 : _bottomSheetRef$curre4.dismiss();
    } catch (e) {}
    _AppStore.default.createConversation({
      order_number: order_code,
      chat_type: type
    }, conversation => {
      _reactNativeNavigation.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));
  };
  const toChatReceiver = () => {
    try {
      var _bottomSheetRef$curre5;
      (_bottomSheetRef$curre5 = bottomSheetRef.current) === null || _bottomSheetRef$curre5 === void 0 ? void 0 : _bottomSheetRef$curre5.dismiss();
    } catch (e) {}
    _AppStore.default.createConversationWithReceiver({
      order_number: order.ORDER_NUMBER,
      is_receiver: !isSender
    }, conversation => {
      _reactNativeNavigation.Navigation.push(props.componentId, {
        component: {
          name: 'ChatScreen',
          options: {
            popGesture: false,
            bottomTabs: {
              visible: false
            },
            topBar: {
              visible: false,
              height: 0
            }
          },
          passProps: {
            data: conversation,
            order
          }
        }
      });
    }, error => alert(error));
  };
  const renderItem = (item, index) => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => {
        try {
          var _bottomSheetRef$curre6;
          (_bottomSheetRef$curre6 = bottomSheetRef.current) === null || _bottomSheetRef$curre6 === void 0 ? void 0 : _bottomSheetRef$curre6.dismiss();
        } catch (e) {}
        toChat([item.USERID]);
      },
      style: {
        flexDirection: 'row',
        backgroundColor: 'white',
        paddingVertical: 12,
        paddingHorizontal: 16
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        height: 48,
        width: 48,
        resizeMode: 'center',
        marginRight: 12
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      style: {
        height: 48,
        width: 48,
        resizeMode: 'center'
      },
      source: require('../../assets/avatar_default.png')
    })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1
      }
    }, /*#__PURE__*/_react.default.createElement(_index.MText, {
      style: {
        fontSize: 17,
        fontWeight: '600',
        color: _Styles.default.primaryText
      }
    }, `Chat với bưu tá ${item.RECEIVER_POSTMAN === 1 ? 'giao' : 'lấy'}`), /*#__PURE__*/_react.default.createElement(_index.MText, {
      style: {
        fontSize: 15,
        fontWeight: '500',
        color: _Styles.default.neutralText,
        paddingTop: 4
      }
    }, item.FIRSTNAME + ' ' + item.LASTNAME)));
  };
  return /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetModalProvider, null, /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetModal, {
    ref: bottomSheetRef,
    backdropComponent: () => {
      return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        activeOpacity: 1,
        onPress: () => {
          var _bottomSheetRef$curre7;
          return (_bottomSheetRef$curre7 = bottomSheetRef.current) === null || _bottomSheetRef$curre7 === void 0 ? void 0 : _bottomSheetRef$curre7.dismiss();
        },
        style: {
          position: 'absolute',
          width: '100%',
          height: '100%',
          backgroundColor: '#00000059'
        }
      });
    },
    index: 0,
    snapPoints: snapPoints,
    onDismiss: () => {}
  }, _AppStore.default.appId === 'VTPost' && /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: toChatReceiver,
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center',
      marginRight: 12
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center'
    },
    source: require('../../assets/avatar_default_customer.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: _Styles.default.primaryText
    }
  }, `Chat với người nhận`), /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 15,
      fontWeight: '500',
      color: _Styles.default.neutralText,
      paddingTop: 4
    }
  }, order.RECEIVER_FULLNAME))), data.length > 0 && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: 'white',
      height: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: '#E5E5E5',
      height: 1,
      marginLeft: 76,
      marginRight: 16
    }
  })), /*#__PURE__*/_react.default.createElement(_bottomSheet.BottomSheetFlatList, {
    data: data,
    renderItem: _ref => {
      let {
        item,
        index
      } = _ref;
      return renderItem(item, index);
    },
    ItemSeparatorComponent: () => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        backgroundColor: 'white',
        height: 1
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        backgroundColor: '#E5E5E5',
        height: 1,
        marginLeft: 76,
        marginRight: 16
      }
    }))
  })), _AppStore.default.appId === 'VTMan' && /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: toChatGroup,
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center',
      marginRight: 12
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center'
    },
    source: require('../../assets/avatar_create_group.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: _Styles.default.primaryText
    }
  }, `Chat nhóm`), /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 15,
      fontWeight: '500',
      color: _Styles.default.neutralText,
      paddingTop: 4
    }
  }, 'Tham gia của nhiều người'))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: 'white',
      height: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: '#E5E5E5',
      height: 1,
      marginLeft: 76,
      marginRight: 16
    }
  })), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      toChatWithCustomer(order.ma_phieugui, 'SENDER');
    },
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center',
      marginRight: 12
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center'
    },
    source: require('../../assets/avatar_default_customer.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: _Styles.default.primaryText
    }
  }, `Chat với khách hàng gửi`), /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 15,
      fontWeight: '500',
      color: _Styles.default.neutralText,
      paddingTop: 4
    }
  }, order.ten_khgui))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: 'white',
      height: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: '#E5E5E5',
      height: 1,
      marginLeft: 76,
      marginRight: 16
    }
  })), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      try {
        var _bottomSheetRef$curre8;
        (_bottomSheetRef$curre8 = bottomSheetRef.current) === null || _bottomSheetRef$curre8 === void 0 ? void 0 : _bottomSheetRef$curre8.dismiss();
      } catch (e) {}
      toChatWithCustomer(order.ma_phieugui, 'RECEIVER');
    },
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center',
      marginRight: 12
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'center'
    },
    source: require('../../assets/avatar_default_customer.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: _Styles.default.primaryText
    }
  }, `Chat với khách hàng nhận`), /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 15,
      fontWeight: '500',
      color: _Styles.default.neutralText,
      paddingTop: 4
    }
  }, order.ten_khnhan))))));
});
var _default = BottomSheetChatOptions;
exports.default = _default;
//# sourceMappingURL=index.js.map