"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AttachsScreen = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _mobxReactLite = require("mobx-react-lite");
var _Styles = _interopRequireDefault(require("../../Styles"));
var _reactNativeSwipeable = _interopRequireDefault(require("react-native-swipeable"));
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 _AttachsStore = _interopRequireDefault(require("./AttachsStore"));
var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
var _Item = require("../chat/Item");
var _ImageViewing = _interopRequireDefault(require("../../components/imageView/ImageViewing"));
var _components = require("../../components");
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; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
const AttachsScreen = (0, _mobxReactLite.observer)(function AttachsScreen(props) {
  var _receiver$state;
  const conversation = props.data;
  const receiver = props.receiver;
  const insets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
  const [images, setImages] = (0, _react.useState)([]);
  const [imageVisible, setImageVisible] = (0, _react.useState)(false);
  const loadData = () => {
    _AttachsStore.default.getData({
      conversation_id: conversation === null || conversation === void 0 ? void 0 : conversation._id
    });
  };
  (0, _react.useEffect)(() => {
    _AttachsStore.default.data = [];
    _AttachsStore.default.currentTab = 0;
    _AttachsStore.default.page = 0;
    loadData();
  }, []);
  const renderItem = _ref => {
    let {
      item,
      index
    } = _ref;
    const attach = item;
    if (_AttachsStore.default.currentTab === 0) {
      if (attach.url.toLowerCase().includes('jpg') || attach.url.toLowerCase().includes('png') || attach.url.toLowerCase().includes('jpeg') || attach.url.toLowerCase().includes('heic')) {
        return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
          onPress: () => {
            setImages([{
              uri: attach.url
            }]);
            setImageVisible(true);
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
          source: {
            uri: attach.url
          },
          style: {
            borderWidth: 0.5,
            borderColor: '#f2f2f2',
            backgroundColor: "#F2F2F2",
            borderRadius: 5,
            overflow: 'hidden',
            width: _reactNative.Dimensions.get('window').width / 3,
            height: _reactNative.Dimensions.get('window').width / 3
          }
        }));
      }
      if (attach.url.toLowerCase().includes('.mov') || attach.url.toLowerCase().includes('.mp4')) {
        return /*#__PURE__*/_react.default.createElement(_Item.VideoItem, _extends({}, props, {
          url: attach.url,
          style: {
            backgroundColor: "#F2F2F2",
            borderRadius: 5,
            overflow: 'hidden',
            width: _reactNative.Dimensions.get('window').width / 3,
            height: _reactNative.Dimensions.get('window').width / 3
          }
        }));
      }
    } else {
      return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        onPress: () => {
          try {
            _reactNative.Linking.openURL(item.url);
          } catch (e) {
            console.log(e);
          }
        },
        style: {
          // borderRadius: 8,
          // borderWidth: 1,
          // borderColor: "#DCE6F0",
          // backgroundColor: '#F8F8FA',
          paddingHorizontal: 12,
          paddingVertical: 12,
          flexDirection: 'row',
          alignItems: 'center'
        }
      }, attach.type.includes('pdf') && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        source: require('../../assets/file_pdf.png'),
        style: {
          width: 42,
          height: 42,
          resizeMode: 'contain',
          marginRight: 14
        }
      }), (attach.type.includes('.doc') || attach.url.includes('.docx')) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        source: require('../../assets/file_doc.png'),
        style: {
          width: 42,
          height: 42,
          resizeMode: 'contain',
          marginRight: 14
        }
      }), (attach.type.includes('.xls') || attach.url.includes('.xlsx')) && /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        source: require('../../assets/file_xls.png'),
        style: {
          width: 42,
          height: 42,
          resizeMode: 'contain',
          marginRight: 14
        }
      }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flex: 1
        }
      }, /*#__PURE__*/_react.default.createElement(_components.MText, {
        numberOfLines: 1,
        style: {
          fontSize: 15,
          fontWeight: '600',
          color: "#44494D"
        }
      }, attach.key.replace("conversation/", "")), /*#__PURE__*/_react.default.createElement(_components.MText, {
        style: {
          fontSize: 13,
          color: "#828282",
          marginTop: 8
        }
      }, (0, _moment.default)(attach.created_at).format('HH:mm DD/MM/YYYY'))));
    }
  };
  return /*#__PURE__*/_react.default.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: {
      flex: 1,
      backgroundColor: _Styles.default.primary
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: (0, _utils.scale)(64),
      backgroundColor: _Styles.default.primary
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      _reactNativeNavigation.Navigation.pop(props.componentId);
    },
    style: {
      width: 50,
      height: 50,
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 36,
      width: 36,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_close_attach.png')
  }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      alignItems: 'center',
      backgroundColor: 'white'
    }
  }, /*#__PURE__*/_react.default.createElement(_components.MText, {
    style: {
      fontWeight: '600',
      fontSize: 20,
      marginTop: insets.top + 118 - (0, _utils.scale)(64),
      color: _Styles.default.primaryText
    }
  }, (receiver === null || receiver === void 0 ? void 0 : receiver.first_name) + " " + (receiver === null || receiver === void 0 ? void 0 : receiver.last_name)), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row',
      alignItems: 'center',
      marginTop: 4
    }
  }, /*#__PURE__*/_react.default.createElement(_components.MText, {
    style: {
      fontWeight: '500',
      fontSize: 13,
      color: _Styles.default.neutralText,
      textAlign: 'center'
    }
  }, (conversation === null || conversation === void 0 ? void 0 : conversation.type) === 'PAIR' && (receiver === null || receiver === void 0 ? void 0 : receiver.type) === 'VTMAN' && _AppStore.default.lang.common.postman)), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row',
      alignItems: 'center',
      marginTop: 16
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      try {
        _reactNative.Linking.openURL(`tel:${receiver === null || receiver === void 0 ? void 0 : receiver.phone}`);
      } catch (e) {
        console.log(e);
      }
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_call.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    style: {
      marginLeft: 16
    },
    onPress: () => {
      _reactNativeNavigation.Navigation.pop(props.componentId);
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_message.png')
  })), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    style: {
      marginLeft: 16
    },
    onPress: () => {
      alert('Tính năng đang phát triển');
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 48,
      width: 48,
      resizeMode: 'contain'
    },
    source: require('../../assets/ic_star.png')
  })))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row',
      alignItems: 'center',
      height: 74,
      backgroundColor: 'white',
      paddingTop: 24
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      _AttachsStore.default.currentTab = 0;
      _AttachsStore.default.page = 0;
      loadData();
    },
    style: {
      flex: 1,
      height: 50,
      justifyContent: 'center',
      borderBottomWidth: 2,
      borderColor: _AttachsStore.default.currentTab === 0 ? _Styles.default.primary : '#DCE6F0'
    }
  }, /*#__PURE__*/_react.default.createElement(_components.MText, {
    style: {
      fontWeight: '600',
      fontSize: 17,
      color: _AttachsStore.default.currentTab === 0 ? _Styles.default.primary : _Styles.default.primaryText,
      textAlign: 'center'
    }
  }, "\u1EA2nh, video")), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      _AttachsStore.default.currentTab = 1;
      _AttachsStore.default.page = 0;
      loadData();
    },
    style: {
      flex: 1,
      height: 50,
      justifyContent: 'center',
      borderBottomWidth: 2,
      borderColor: _AttachsStore.default.currentTab === 1 ? _Styles.default.primary : '#DCE6F0'
    }
  }, /*#__PURE__*/_react.default.createElement(_components.MText, {
    style: {
      borderLeftWidth: 1,
      borderColor: '#DCE6F0',
      fontWeight: '600',
      fontSize: 17,
      color: _AttachsStore.default.currentTab === 1 ? _Styles.default.primary : _Styles.default.primaryText,
      textAlign: 'center'
    }
  }, "T\xE0i li\u1EC7u"))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      backgroundColor: '#f2f2f2',
      height: 8
    }
  }), /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
    key: _AttachsStore.default.currentTab === 0 ? '0' : '1',
    refreshing: _AttachsStore.default.isLoading,
    onRefresh: () => {
      _AttachsStore.default.page = 0;
      loadData();
    },
    keyExtractor: item => item._id,
    numColumns: _AttachsStore.default.currentTab === 0 ? 3 : 1,
    onEndReached: () => loadData(),
    style: {
      flex: 1,
      backgroundColor: 'white'
    },
    data: _AttachsStore.default.data,
    renderItem: renderItem,
    ItemSeparatorComponent: () => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        backgroundColor: 'white',
        height: 1
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        backgroundColor: '#E5E5E5',
        height: 1,
        marginLeft: 66,
        marginRight: 16
      }
    })),
    ListEmptyComponent: () => {
      return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          alignItems: 'center',
          marginTop: 50
        }
      }, _AttachsStore.default.currentTab === 0 ? /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        style: {
          width: 102,
          height: 102,
          resizeMode: 'contain'
        },
        source: require('../../assets/ic_no_picture.png')
      }) : /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
        style: {
          width: 102,
          height: 102,
          resizeMode: 'contain'
        },
        source: require('../../assets/ic_no_file.png')
      }), /*#__PURE__*/_react.default.createElement(_components.MText, {
        style: {
          fontWeight: '600',
          fontSize: 15,
          color: '#828282'
        }
      }, _AttachsStore.default.currentTab === 0 ? "Chưa có ảnh, video được gửi trong hội thoại " : "Chưa có tài liệu được gửi trong hội thoại "));
    }
  }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      height: 94,
      width: 94,
      top: insets.top + 20,
      resizeMode: 'contain',
      position: 'absolute',
      alignSelf: 'center'
    }
  }, (receiver === null || receiver === void 0 ? void 0 : receiver.type) === 'VTMAN' ? /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 94,
      width: 94,
      resizeMode: 'contain'
    },
    source: require('../../assets/avatar_default.png')
  }) : /*#__PURE__*/_react.default.createElement(_reactNativeFastImage.default, {
    style: {
      height: 94,
      width: 94,
      resizeMode: 'contain'
    },
    source: 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: 70,
      left: 60
    },
    source: require('../../assets/ic_online.png')
  })), /*#__PURE__*/_react.default.createElement(_ImageViewing.default, {
    images: images,
    swipeToCloseEnabled: true,
    doubleTapToZoomEnabled: true,
    imageIndex: 0,
    visible: imageVisible,
    onRequestClose: () => setImageVisible(false)
  }));
});
exports.AttachsScreen = AttachsScreen;
//# sourceMappingURL=index.js.map