"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 BottomSheetChatOptionsVTM = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
  const [show, setShow] = (0, _react.useState)(false);
  const [data, setData] = (0, _react.useState)([]);
  const [order, setOrder] = (0, _react.useState)({});
  const [typeUser, setTypeUser] = (0, _react.useState)('');
  const [isSender, setIsSender] = (0, _react.useState)(true);
  (0, _react.useImperativeHandle)(ref,
  // forwarded ref
  () => {
    return {
      updateData(data, order, orderType, typeUser) {
        console.log('order', order);
        setData(data);
        setOrder(order);
        setTypeUser(typeUser);
        setIsSender(typeUser === 'SENDER');
      },
      present() {
        setShow(true);
      },
      dismiss() {
        setShow(false);
      }
    }; // the forwarded ref value
  }, []);
  const toChatWithCustomer = async (order_code, type) => {
    console.log('type', type);
    try {
      setShow(false);
    } catch (e) {}
    _AppStore.default.createConversation({
      order_number: order_code,
      chat_type: type,
      is_postman_receiver: props === null || props === void 0 ? void 0 : props.postman_receiver
    }, 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,
              ...{
                order_number: order_code,
                ma_phieugui: order_code
              }
            }
          }
        }
      });
    }, error => alert(error));
  };
  return /*#__PURE__*/_react.default.createElement(_reactNative.Modal, {
    visible: show,
    transparent: true,
    animationType: "fade"
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    activeOpacity: 1,
    onPress: () => setShow(false),
    style: {
      flex: 1,
      backgroundColor: '#00000059'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
    style: {
      flex: 1,
      justifyContent: 'flex-end'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      borderTopLeftRadius: 16,
      borderTopRightRadius: 16,
      overflow: 'hidden'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      setShow(false);
      if (isSender) {
        _reactNative.Linking.openURL(`sms:${order.tel_khgui ? order.tel_khgui : order.dienthoai_nguoigui}${_reactNative.Platform.OS === 'ios' ? '&' : '?'}body=${''}`);
        return;
      }
      _reactNative.Linking.openURL(`sms:${typeUser === 'SENDER' ? order.tel_khgui : order.tel_khnhan}${_reactNative.Platform.OS === 'ios' ? '&' : '?'}body=${''}`);
    },
    style: {
      flexDirection: 'row',
      backgroundColor: 'white',
      paddingVertical: 12,
      paddingHorizontal: 16,
      alignItems: 'center'
    }
  }, /*#__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/ic_sms.png')
  })), /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 17,
      fontWeight: '600',
      color: _Styles.default.primaryText
    }
  }, `Tin nhắn văn bản (SMS)`)), /*#__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(isSender ? order.ma_vandon ? order.ma_vandon : order.ma_phieugui : order.ma_phieugui, typeUser),
    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: typeUser === 'SENDER' ? require('../../assets/avatar_postman.png') : require('../../assets/avatar_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 - ' + (typeUser === 'SENDER' ? 'Gửi hàng' : 'Nhận hàng')), /*#__PURE__*/_react.default.createElement(_index.MText, {
    style: {
      fontSize: 15,
      fontWeight: '500',
      color: _Styles.default.neutralText,
      paddingTop: 4
    }
  }, isSender ? order.ten_khgui ? order.ten_khgui : order.ten_nguoigui : typeUser === 'SENDER' ? order.ten_khgui : order.ten_khnhan)))))));
});
var _default = BottomSheetChatOptionsVTM;
exports.default = _default;
//# sourceMappingURL=VTM.js.map