"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ListChatScreen = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _components = require("../../components");
var _mobxReactLite = require("mobx-react-lite");
var _Styles = _interopRequireDefault(require("../../Styles"));
var _swipeable = _interopRequireDefault(require("../../components/swipeable"));
var _ListChatStore = _interopRequireDefault(require("./ListChatStore"));
var _AppStore = _interopRequireDefault(require("../AppStore"));
var _moment = _interopRequireDefault(require("moment"));
var _reactNativeNavigation = require("react-native-navigation");
var _reactNativeFastImage = _interopRequireDefault(require("react-native-fast-image"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _utils = require("../../utils");
var _bottomSheetChatOptions = _interopRequireDefault(require("../../components/bottomSheetChatOptions"));
var _bottomSheet = require("../../components/bottomSheet/bottom-sheet");
var _mobx = require("mobx");
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 ListChatScreen = (0, _mobxReactLite.observer)(function ListChatScreen(props) {
  const [showSearch, setShowSearch] = (0, _react.useState)(false);
  const bottomSheetModalRef = (0, _react.useRef)();
  const [query, setQuery] = (0, _react.useState)("");
  (0, _react.useEffect)(() => {
    _ListChatStore.default.search = '';
    // intLoad();
    // bottomSheetModalRef.current?.present();
    return () => {
      var _bottomSheetModalRef$;
      (_bottomSheetModalRef$ = bottomSheetModalRef.current) === null || _bottomSheetModalRef$ === void 0 ? void 0 : _bottomSheetModalRef$.dismiss();
    };
  }, []);
  const intLoad = () => {
    _ListChatStore.default.page = 0;
    _ListChatStore.default.getData({});
  };
  const navigationChat = data => {
    _reactNativeNavigation.Navigation.push(props.componentId, {
      component: {
        name: 'ChatScreen',
        passProps: {
          data: data
        },
        options: {
          popGesture: false,
          bottomTabs: {
            visible: false
          },
          topBar: {
            visible: false,
            height: 0
          }
        }
      }
    });
  };
  const getLastMessage = (item, setting, isMe) => {
    const prefix = isMe ? _AppStore.default.lang.list_chat.you + ': ' : '';
    try {
      if (item.message.type === 'CREATED_QUOTE_ORDER') {
        return /*#__PURE__*/_react.default.createElement(_components.MText, {
          numberOfLines: 1,
          style: {
            flex: 1,
            fontSize: 15,
            fontWeight: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? '600' : '500',
            color: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? _Styles.default.primaryText : _Styles.default.neutralText
          }
        }, _AppStore.default.lang.list_chat.message_system);
      }
      if (item.message.type === 'VOICE') {
        return /*#__PURE__*/_react.default.createElement(_components.MText, {
          numberOfLines: 1,
          style: {
            flex: 1,
            fontSize: 15,
            fontWeight: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? '600' : '500',
            color: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? _Styles.default.primaryText : _Styles.default.neutralText
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          source: require('../../assets/ic_attach_message.png'),
          style: {
            width: 16,
            height: 16,
            resizeMode: 'contain'
          }
        }), /*#__PURE__*/_react.default.createElement(_components.MText, null, prefix + _AppStore.default.lang.list_chat.message_voice));
      }
      if (item.message.type === 'LOCATION') {
        return /*#__PURE__*/_react.default.createElement(_components.MText, {
          numberOfLines: 1,
          style: {
            flex: 1,
            fontSize: 15,
            fontWeight: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? '600' : '500',
            color: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? _Styles.default.primaryText : _Styles.default.neutralText
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          source: require('../../assets/ic_attach_message.png'),
          style: {
            width: 16,
            height: 16,
            resizeMode: 'contain'
          }
        }), /*#__PURE__*/_react.default.createElement(_components.MText, null, prefix + _AppStore.default.lang.list_chat.message_location));
      }
      if (item.message.type === 'FILE') {
        return /*#__PURE__*/_react.default.createElement(_components.MText, {
          numberOfLines: 1,
          style: {
            flex: 1,
            fontSize: 15,
            fontWeight: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? '600' : '500',
            color: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? _Styles.default.primaryText : _Styles.default.neutralText
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          source: require('../../assets/ic_attach_message.png'),
          style: {
            width: 16,
            height: 16,
            resizeMode: 'contain'
          }
        }), /*#__PURE__*/_react.default.createElement(_components.MText, null, prefix + _AppStore.default.lang.list_chat.message_doc));
      }
      if (item.message.has_attachment) {
        return /*#__PURE__*/_react.default.createElement(_components.MText, {
          numberOfLines: 1,
          style: {
            flex: 1,
            fontSize: 15,
            lineHeight: 21,
            fontWeight: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? '600' : '500',
            color: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? _Styles.default.primaryText : _Styles.default.neutralText
          }
        }, prefix + (isMe ? `Bạn đã gửi ${item.message.attachment_ids.length} ảnh/video` : `Bạn đã nhận ${item.message.attachment_ids.length} ảnh/video`));
      }
    } catch (e) {}
    return /*#__PURE__*/_react.default.createElement(_components.MText, {
      numberOfLines: 1,
      style: {
        flex: 1,
        fontSize: 15,
        fontWeight: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? '600' : '500',
        color: (setting === null || setting === void 0 ? void 0 : setting.unread_count) > 0 ? _Styles.default.primaryText : _Styles.default.neutralText
      }
    }, prefix + item.message.text);
  };
  const renderItem = _ref => {
    let {
      item,
      index
    } = _ref;
    let setting = {};
    try {
      var _item$settings;
      let mySetting = (_item$settings = item.settings) === null || _item$settings === void 0 ? void 0 : _item$settings.find(i => i.user_id === _AppStore.default.user.type + '_' + _AppStore.default.user.user_id);
      setting = mySetting ? mySetting : {};
    } catch (e) {}
    let receiver = {};
    let isMe = false;
    try {
      isMe = _AppStore.default.user.type + '_' + _AppStore.default.user.user_id === item.message.sender;
      receiver = item.detail_participants.find(i => i.user_id !== _AppStore.default.user.user_id);
    } catch (e) {}
    const rightButtons = [/*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => {
        if (setting.is_pin) {
          _ListChatStore.default.unPin({
            conversation_id: item._id
          }, () => {
            try {
              item.settings = item.settings.map(i => {
                i.is_pin = false;
                return i;
              });
            } catch (e) {}
            _ListChatStore.default.data.unshift(item);
            _ListChatStore.default.dataPin = [..._ListChatStore.default.dataPin.filter(i => i._id !== item._id)];
            _ListChatStore.default.data = [..._ListChatStore.default.data];
          });
        } else {
          _ListChatStore.default.pin({
            conversation_id: item._id
          }, () => {
            try {
              item.settings = item.settings.map(i => {
                i.is_pin = true;
                return i;
              });
            } catch (e) {}
            _ListChatStore.default.dataPin.unshift(item);
            _ListChatStore.default.data = [..._ListChatStore.default.data.filter(i => i._id !== item._id)];
            _ListChatStore.default.dataPin = [..._ListChatStore.default.dataPin];
          });
        }
      },
      style: {
        width: 66,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#3B7CEC',
        flex: 1
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
      resizeMode: 'contain',
      source: setting.is_pin ? require('../../assets/ic_unpin.png') : require('../../assets/ic_pin_white.png'),
      style: {
        width: 20,
        height: 20,
        resizeMode: 'contain'
      }
    }), /*#__PURE__*/_react.default.createElement(_components.MText, {
      style: {
        color: 'white',
        fontSize: 13,
        fontWeight: '500',
        backgroundColor: 'transparent',
        textAlign: 'center',
        paddingTop: 4
      }
    }, setting.is_pin ? _AppStore.default.lang.list_chat.unpin : _AppStore.default.lang.list_chat.pin)), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => {
        try {
          _ListChatStore.default.mute({
            conversation_id: item._id,
            is_show: !setting.is_hide_notification
          }, () => {
            var _item$settings2;
            item.settings = (_item$settings2 = item.settings) === null || _item$settings2 === void 0 ? void 0 : _item$settings2.map(i => {
              i.is_hide_notification = !i.is_hide_notification;
              return i;
            });
            _ListChatStore.default.data = [..._ListChatStore.default.data];
            //   item.settings = item.settings.map(i=>{
            //     i.is_pin = true;
            //     return i
            //   })
            // listChatStore.data = [...listChatStore.data]
          });
        } catch (e) {}
      },
      style: {
        width: 66,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#EB960A',
        flex: 1
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
      resizeMode: 'contain',
      source: !setting.is_hide_notification ? require('../../assets/ic_notify_off.png') : require('../../assets/ic_notify.png'),
      style: {
        width: 24,
        height: 24,
        resizeMode: 'contain'
      }
    }), /*#__PURE__*/_react.default.createElement(_components.MText, {
      style: {
        color: 'white',
        fontSize: 13,
        backgroundColor: 'transparent',
        textAlign: 'center',
        fontWeight: '500',
        paddingTop: 4
      }
    }, setting.is_hide_notification ? _AppStore.default.lang.list_chat.unmute : _AppStore.default.lang.list_chat.mute)), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => {
        _ListChatStore.default.hide({
          conversation_id: item._id
        }, () => intLoad());
      },
      style: {
        width: 66,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#EE0033',
        flex: 1
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
      resizeMode: 'contain',
      source: require('../../assets/ic_delete.png'),
      style: {
        width: 24,
        height: 24,
        resizeMode: 'contain'
      }
    }), /*#__PURE__*/_react.default.createElement(_components.MText, {
      style: {
        color: 'white',
        fontSize: 13,
        backgroundColor: 'transparent',
        fontWeight: '500',
        textAlign: 'center',
        paddingTop: 4
      }
    }, _AppStore.default.lang.list_chat.delete))];
    if (item.type === 'GROUP') {
      var _setting, _item$orders$, _setting2, _setting3, _item$message, _item$message$read_by, _setting4, _setting5;
      //Group Chat
      return /*#__PURE__*/_react.default.createElement(_swipeable.default, {
        rightButtonWidth: 66,
        rightButtons: rightButtons
      }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        onPress: () => {
          try {
            navigationChat({
              ...item,
              ...{
                receiver: receiver
              }
            });
            item.settings = item.settings.map(i => {
              if (i.user_id === _AppStore.default.user.type + '_' + _AppStore.default.user.user_id) {
                i.unread_count = 0;
              }
              return i;
            });
            _ListChatStore.default.data = [..._ListChatStore.default.data];
            _ListChatStore.default.dataPin = [..._ListChatStore.default.dataPin];
          } catch (e) {}
        },
        style: {
          flexDirection: 'row',
          backgroundColor: (_setting = setting) !== null && _setting !== void 0 && _setting.is_pin ? '#F8F8FA' : 'white',
          paddingVertical: 12,
          paddingHorizontal: 16
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          height: 48,
          width: 48,
          resizeMode: 'center',
          marginRight: 12
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        style: {
          height: 48,
          width: 48,
          resizeMode: 'center'
        },
        source: require('../../assets/avatar_group.png')
      })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flex: 1
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flexDirection: 'row'
        }
      }, /*#__PURE__*/_react.default.createElement(_components.MText, {
        numberOfLines: 1,
        style: {
          flex: 1,
          fontSize: 17,
          fontWeight: '600',
          color: _Styles.default.primaryText
        }
      }, "\u0110\u01A1n ", item.order_numbers[0], ' ', /*#__PURE__*/_react.default.createElement(_components.MText, {
        style: {
          fontSize: 13,
          fontWeight: '400',
          color: _Styles.default.neutralText
        }
      }, "- ", (0, _utils.orderStatus)((_item$orders$ = item.orders[0]) === null || _item$orders$ === void 0 ? void 0 : _item$orders$.order_status), ' ')), /*#__PURE__*/_react.default.createElement(_components.MText, {
        style: {
          textAlign: 'right',
          color: _Styles.default.neutralText
        }
      }, (0, _utils.formatTimeLastMessage)(item.message.created_at))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flexDirection: 'row',
          paddingTop: 6,
          alignItems: 'center'
        }
      }, getLastMessage(item, setting, isMe), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flexDirection: 'row'
        }
      }, ((_setting2 = setting) === null || _setting2 === void 0 ? void 0 : _setting2.is_pin) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        style: {
          height: 16,
          width: 16,
          resizeMode: 'center',
          marginLeft: 10
        },
        source: require('../../assets/ic_pin.png')
      }), ((_setting3 = setting) === null || _setting3 === void 0 ? void 0 : _setting3.is_hide_notification) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        style: {
          height: 16,
          width: 16,
          resizeMode: 'center',
          marginLeft: 10
        },
        source: require('../../assets/ic_mute.png')
      }), (_item$message = item.message) === null || _item$message === void 0 ? void 0 : (_item$message$read_by = _item$message.read_by) === null || _item$message$read_by === void 0 ? void 0 : _item$message$read_by.map((item, index) => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        key: index + ''
      }, item !== _AppStore.default.user.type + '_' + _AppStore.default.user.user_id && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        style: {
          height: 16,
          width: 16,
          resizeMode: 'center',
          marginLeft: 10
        },
        source: item.includes('VTM') ? require('../../assets/avatar_default.png') : require('../../assets/avatar_default_customer.png')
      }))), ((_setting4 = setting) === null || _setting4 === void 0 ? void 0 : _setting4.unread_count) > 0 && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          height: 16,
          width: 16,
          backgroundColor: _Styles.default.primary,
          borderRadius: 8,
          marginLeft: 10,
          alignItems: 'center',
          justifyContent: 'center'
        }
      }, /*#__PURE__*/_react.default.createElement(_components.MText, {
        style: {
          color: 'white',
          fontSize: 10,
          textAlign: 'center'
        }
      }, (_setting5 = setting) === null || _setting5 === void 0 ? void 0 : _setting5.unread_count)))))));
    } else if (item.type === 'PAIR') {
      var _setting6, _receiver, _receiver$state, _receiver2, _receiver3, _receiver4, _receiver5, _receiver6, _item$message2, _item$message2$read_b, _setting7, _setting8, _setting9, _setting10;
      //Private Chat

      return (
        /*#__PURE__*/
        // <ChatSwipeableRow
        //   isPin={setting?.is_pin}
        //   onPress1={(isPin)=>{
        //     listChatStore.pin({
        //       conversation_id: item._id
        //     })
        //   }}
        //   onPress3={()=>{
        //     listChatStore.hide({
        //       conversation_id: item._id
        //     })
        //   }}
        // >
        _react.default.createElement(_swipeable.default, {
          rightButtonWidth: 66,
          rightButtons: rightButtons
        }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
          onPress: () => {
            try {
              navigationChat({
                ...item,
                ...{
                  receiver: receiver
                }
              });
              _ListChatStore.default.data[index].settings = _ListChatStore.default.data[index].settings.map(i => {
                if (i.user_id === _AppStore.default.user.type + '_' + _AppStore.default.user.user_id) {
                  i.unread_count = 0;
                }
                return i;
              });
              _ListChatStore.default.data = [..._ListChatStore.default.data];
              _ListChatStore.default.dataPin = [..._ListChatStore.default.dataPin];
            } catch (e) {}
          },
          style: {
            flexDirection: 'row',
            backgroundColor: (_setting6 = setting) !== null && _setting6 !== void 0 && _setting6.is_pin ? '#F8F8FA' : 'white',
            paddingVertical: 12,
            paddingHorizontal: 16
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            height: 48,
            width: 48,
            resizeMode: 'center',
            marginRight: 12
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          style: {
            height: 48,
            width: 48,
            resizeMode: 'center'
          },
          source: ((_receiver = receiver) === null || _receiver === void 0 ? void 0 : _receiver.type) === 'VTMAN' ? require('../../assets/avatar_default.png') : require('../../assets/avatar_default_customer.png')
        }), ((_receiver$state = receiver.state) === null || _receiver$state === void 0 ? void 0 : _receiver$state.includes('ONLINE')) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          style: {
            height: 12,
            width: 12,
            resizeMode: 'center',
            position: 'absolute',
            top: 36,
            left: 36
          },
          source: require('../../assets/ic_online.png')
        })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            flex: 1
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            flexDirection: 'row'
          }
        }, /*#__PURE__*/_react.default.createElement(_components.MText, {
          style: {
            flex: 1,
            fontSize: 17,
            fontWeight: '600',
            color: _Styles.default.primaryText
          }
        }, ((_receiver2 = receiver) !== null && _receiver2 !== void 0 && _receiver2.first_name ? (_receiver3 = receiver) === null || _receiver3 === void 0 ? void 0 : _receiver3.first_name : '') + ' ' + ((_receiver4 = receiver) !== null && _receiver4 !== void 0 && _receiver4.last_name ? (_receiver5 = receiver) === null || _receiver5 === void 0 ? void 0 : _receiver5.last_name : ''), ' ', ((_receiver6 = receiver) === null || _receiver6 === void 0 ? void 0 : _receiver6.type) === 'VTMAN' && /*#__PURE__*/_react.default.createElement(_components.MText, {
          style: {
            fontSize: 13,
            fontWeight: '400',
            color: _Styles.default.neutralText
          }
        }, "- ", _AppStore.default.lang.common.postman, ' '), ' '), /*#__PURE__*/_react.default.createElement(_components.MText, {
          style: {
            textAlign: 'right',
            color: _Styles.default.neutralText
          }
        }, (0, _utils.formatTimeLastMessage)(item.message.created_at))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            flexDirection: 'row',
            paddingTop: 6,
            alignItems: 'center'
          }
        }, getLastMessage(item, setting, isMe), (_item$message2 = item.message) === null || _item$message2 === void 0 ? void 0 : (_item$message2$read_b = _item$message2.read_by) === null || _item$message2$read_b === void 0 ? void 0 : _item$message2$read_b.map((reader, index) => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          key: index + ''
        }, reader !== _AppStore.default.user.type + '_' + _AppStore.default.user.user_id && reader !== (item === null || item === void 0 ? void 0 : item.sender) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          style: {
            height: 16,
            width: 16,
            resizeMode: 'center',
            marginLeft: 10
          },
          source: reader.includes('VTM') ? require('../../assets/avatar_default.png') : require('../../assets/avatar_default_customer.png')
        }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            flexDirection: 'row'
          }
        }, ((_setting7 = setting) === null || _setting7 === void 0 ? void 0 : _setting7.is_pin) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          style: {
            height: 16,
            width: 16,
            resizeMode: 'center',
            marginLeft: 10
          },
          source: require('../../assets/ic_pin.png')
        }), ((_setting8 = setting) === null || _setting8 === void 0 ? void 0 : _setting8.is_hide_notification) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          style: {
            height: 16,
            width: 16,
            resizeMode: 'center',
            marginLeft: 10
          },
          source: require('../../assets/ic_mute.png')
        }), ((_setting9 = setting) === null || _setting9 === void 0 ? void 0 : _setting9.unread_count) > 0 && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            height: 16,
            width: 16,
            backgroundColor: _Styles.default.primary,
            borderRadius: 8,
            marginLeft: 10,
            alignItems: 'center',
            justifyContent: 'center'
          }
        }, /*#__PURE__*/_react.default.createElement(_components.MText, {
          style: {
            color: 'white',
            fontSize: 10,
            textAlign: 'center'
          }
        }, (_setting10 = setting) === null || _setting10 === void 0 ? void 0 : _setting10.unread_count)))))))
      );
    }
  };
  function renderHeader() {
    return /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
      refreshing: _ListChatStore.default.isLoading,
      onRefresh: () => {
        _ListChatStore.default.page = 0;
        _ListChatStore.default.getData({});
      }
      // keyExtractor={(item) => item?.message?._id}
      ,
      style: {
        backgroundColor: 'white'
      },
      data: _ListChatStore.default.dataPin,
      extraData: _ListChatStore.default.data,
      ItemSeparatorComponent: () => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          backgroundColor: '#F8F8FA',
          height: 1
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          backgroundColor: '#E5E5E5',
          height: 1,
          marginLeft: 76,
          marginRight: 16
        }
      })),
      renderItem: renderItem
    });
  }
  (0, _react.useEffect)(() => {
    const delayDebounceFn = setTimeout(() => {
      _ListChatStore.default.search = query;
      _ListChatStore.default.page = 0;
      _ListChatStore.default.getData({});
    }, 1000);
    return () => clearTimeout(delayDebounceFn);
  }, [query]);
  return /*#__PURE__*/_react.default.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: {
      flex: 1,
      backgroundColor: _Styles.default.primary
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.KeyboardAvoidingView, {
    style: {
      flex: 1
    },
    behavior: _reactNative.Platform.OS === 'ios' ? 'padding' : ''
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: (0, _utils.scale)(64),
      backgroundColor: _Styles.default.primary
    }
  }, showSearch === true ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: (0, _utils.scale)(64),
      flexDirection: 'row',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      width: 50,
      height: 50,
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 24,
      width: 24,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_search.png')
  })), /*#__PURE__*/_react.default.createElement(_components.MTextInput, {
    placeholder: _AppStore.default.appId === 'VTPost' ? _AppStore.default.lang.list_chat.placeholder_search : _AppStore.default.lang.list_chat.placeholder_search_VTM,
    placeholderTextColor: 'white',
    value: query,
    autoFocus: true,
    onChangeText: setQuery,
    style: {
      fontWeight: '500',
      fontSize: (0, _utils.scale)(15),
      color: 'white',
      flex: 1
    }
  }), _ListChatStore.default.search !== '' && /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      setQuery('');
      _ListChatStore.default.search = '';
      _ListChatStore.default.page = 0;
      _ListChatStore.default.getData({});
    },
    style: {
      width: 50,
      height: 50,
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 24,
      width: 24,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_clear.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      setShowSearch(false);
      setQuery('');
      _ListChatStore.default.search = '';
      _ListChatStore.default.page = 0;
      _ListChatStore.default.getData({});
    },
    style: {
      width: (0, _utils.scale)(50),
      height: (0, _utils.scale)(50),
      justifyContent: 'center',
      alignItems: 'flex-end'
    }
  }, /*#__PURE__*/_react.default.createElement(_components.MText, {
    style: {
      fontWeight: '600',
      fontSize: (0, _utils.scale)(15),
      color: 'white',
      marginRight: 16
    }
  }, _AppStore.default.lang.common.cancel))) : /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: (0, _utils.scale)(64),
      flexDirection: 'row',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      if (props.buttonBack !== false) {
        _reactNativeNavigation.Navigation.pop(props.componentId);
      }
    },
    style: {
      width: 50,
      height: 50,
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, props.buttonBack !== false && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 36,
      width: 36,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_back.png')
  })), /*#__PURE__*/_react.default.createElement(_components.MText, {
    style: {
      fontWeight: '600',
      fontSize: (0, _utils.scale)(17),
      color: 'white',
      flex: 1,
      textAlign: 'center'
    }
  }, _AppStore.default.appId === 'VTPost' ? _AppStore.default.lang.list_chat.message : 'Trò chuyện'), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => setShowSearch(true),
    style: {
      width: 50,
      height: 50,
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 24,
      width: 24,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_search.png')
  })))), /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
    refreshing: _ListChatStore.default.isLoading,
    onRefresh: () => {
      _ListChatStore.default.page = 0;
      _ListChatStore.default.getData({});
    },
    ListHeaderComponent: renderHeader,
    keyExtractor: item => {
      var _item$message3;
      return (_item$message3 = item.message) === null || _item$message3 === void 0 ? void 0 : _item$message3._id;
    },
    onEndReached: () => () => {
      _ListChatStore.default.getData({});
    },
    style: {
      flex: 1,
      backgroundColor: 'white'
    },
    data: _ListChatStore.default.data,
    extraData: _ListChatStore.default.data,
    ListEmptyComponent: () => {
      if (!_ListChatStore.default.isLoading) {
        return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
          onPress: () => intLoad(),
          style: {
            alignItems: 'center',
            height: _reactNative.Dimensions.get('window').height
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          source: require('../../assets/ic_message_empty.png'),
          style: {
            width: 120,
            height: 120,
            resizeMode: 'contain',
            marginTop: 28
          }
        }), /*#__PURE__*/_react.default.createElement(_components.MText, {
          style: {
            fontWight: '500',
            fontSize: 15,
            color: _Styles.default.neutralText,
            marginTop: 16
          }
        }, "Qu\xFD kh\xE1ch ch\u01B0a c\xF3 tin nh\u1EAFn"));
      } else {
        return null;
      }
    },
    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
      }
    })),
    renderItem: renderItem
  }), props.admin && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      width: 58,
      height: 58,
      alignItems: 'center',
      justifyContent: 'center',
      position: 'absolute',
      right: 27,
      bottom: 27,
      backgroundColor: _Styles.default.primary,
      borderRadius: 58 / 2
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 25,
      width: 25,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_add_chat.png')
  }))), /*#__PURE__*/_react.default.createElement(_bottomSheetChatOptions.default, {
    ref: bottomSheetModalRef
  }));
});
exports.ListChatScreen = ListChatScreen;
//# sourceMappingURL=index.js.map