text: 'use strict';
  
  exports.__esModule = true;
  exports.Chats = undefined;
  
  var _Activity = require('../../containers/Activity');
  
  var _Activity2 = _interopRequireDefault(_Activity);
  
  var _Avatar = require('@material-ui/core/Avatar');
  
  var _Avatar2 = _interopRequireDefault(_Avatar);
  
  var _Button = require('@material-ui/core/Button');
  
  var _Button2 = _interopRequireDefault(_Button);
  
  var _Divider = require('@material-ui/core/Divider');
  
  var _Divider2 = _interopRequireDefault(_Divider);
  
  var _Icon = require('@material-ui/core/Icon');
  
  var _Icon2 = _interopRequireDefault(_Icon);
  
  var _IconButton = require('@material-ui/core/IconButton');
  
  var _IconButton2 = _interopRequireDefault(_IconButton);
  
  var _IconMenu = require('../../containers/IconMenu');
  
  var _IconMenu2 = _interopRequireDefault(_IconMenu);
  
  var _List = require('@material-ui/core/List');
  
  var _List2 = _interopRequireDefault(_List);
  
  var _ListItem = require('@material-ui/core/ListItem');
  
  var _ListItem2 = _interopRequireDefault(_ListItem);
  
  var _ListItemAvatar = require('@material-ui/core/ListItemAvatar');
  
  var _ListItemAvatar2 = _interopRequireDefault(_ListItemAvatar);
  
  var _ListItemSecondaryAction = require('@material-ui/core/ListItemSecondaryAction');
  
  var _ListItemSecondaryAction2 = _interopRequireDefault(_ListItemSecondaryAction);
  
  var _ListItemText = require('@material-ui/core/ListItemText');
  
  var _ListItemText2 = _interopRequireDefault(_ListItemText);
  
  var _Menu = require('@material-ui/core/Menu');
  
  var _Menu2 = _interopRequireDefault(_Menu);
  
  var _MenuItem = require('@material-ui/core/MenuItem');
  
  var _MenuItem2 = _interopRequireDefault(_MenuItem);
  
  var _MoreHoriz = require('@material-ui/icons/MoreHoriz');
  
  var _MoreHoriz2 = _interopRequireDefault(_MoreHoriz);
  
  var _propTypes = require('prop-types');
  
  var _propTypes2 = _interopRequireDefault(_propTypes);
  
  var _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _reactList = require('react-list');
  
  var _reactList2 = _interopRequireDefault(_reactList);
  
  var _Scrollbar = require('../../components/Scrollbar');
  
  var _Scrollbar2 = _interopRequireDefault(_Scrollbar);
  
  var _Typography = require('@material-ui/core/Typography');
  
  var _Typography2 = _interopRequireDefault(_Typography);
  
  var _messaging = require('../../utils/messaging');
  
  var _messaging2 = _interopRequireDefault(_messaging);
  
  var _withAppConfigs = require('../../utils/withAppConfigs');
  
  var _withAppConfigs2 = _interopRequireDefault(_withAppConfigs);
  
  var _withWidth = require('@material-ui/core/withWidth');
  
  var _withWidth2 = _interopRequireDefault(_withWidth);
  
  var _reactRedux = require('react-redux');
  
  var _materialUiFilter = require('material-ui-filter');
  
  var _firekit = require('firekit');
  
  var _reactIntl = require('react-intl');
  
  var _actions = require('../../store/persistentValues/actions');
  
  var _firekitProvider = require('firekit-provider');
  
  var _reactRouterDom = require('react-router-dom');
  
  var _styles = require('@material-ui/core/styles');
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  var Chats = exports.Chats = function (_Component) {
    _inherits(Chats, _Component);
  
    function Chats() {
      var _temp, _this, _ret;
  
      _classCallCheck(this, Chats);
  
      for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
  
      return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = {
        anchorEl: null,
        hasError: false
      }, _this.handleClick = function (event) {
        _this.setState({ anchorEl: event.currentTarget });
      }, _this.handleClose = function () {
        _this.setState({ anchorEl: null });
      }, _this.handleDeleteChat = function (key, val) {
        var _this$props = _this.props,
            firebaseApp = _this$props.firebaseApp,
            auth = _this$props.auth;
  
  
        firebaseApp.database().ref('user_chats/' + auth.uid + '/' + key).remove();
      }, _this.handleMarkAsUnread = function (key, val) {
        var _this$props2 = _this.props,
            firebaseApp = _this$props2.firebaseApp,
            auth = _this$props2.auth;
  
  
        firebaseApp.database().ref('user_chats/' + auth.uid + '/' + key + '/unread').set(1);
      }, _this.handleItemClick = function (val, key) {
        var _this$props3 = _this.props,
            width = _this$props3.width,
            history = _this$props3.history,
            setPersistentValue = _this$props3.setPersistentValue,
            firebaseApp = _this$props3.firebaseApp,
            auth = _this$props3.auth;
  
  
        var usePreview = (0, _withWidth.isWidthUp)('sm', width);
        setPersistentValue('current_chat_name', val.displayName);
  
        history.push('/chats/edit/' + key);
      }, _this.renderIcons = function (val) {
        var _this$props4 = _this.props,
            theme = _this$props4.theme,
            auth = _this$props4.auth;
  
  
        return _react2.default.createElement(
          'div',
          null,
          val.isSend && auth.uid === val.authorUid && _react2.default.createElement(
            _Icon2.default,
            { className: 'material-icons', style: {
                fontSize: 14,
                padding: 0,
                paddingRight: 2,
                bottom: -1,
                color: val.isRead ? theme.palette.accent1Color : theme.palette.secondary1Color
              } },
            val.isReceived ? 'done_all' : 'done'
          ),
          val.unread > 0 && _react2.default.createElement(
            'b',
            null,
            val.lastMessage
          ),
          !val.unread && val.lastMessage
        );
      }, _this.renderItem = function (i, k) {
        var _this$props5 = _this.props,
            list = _this$props5.list,
            intl = _this$props5.intl,
            persistentValues = _this$props5.persistentValues,
            width = _this$props5.width,
            theme = _this$props5.theme;
  
  
        var usePreview = (0, _withWidth.isWidthUp)('sm', width);
        var currentChatUid = persistentValues['current_chat_uid'] ? persistentValues['current_chat_uid'] : '';
        var key = list[i].key;
        var val = list[i].val;
        var isPreviewed = usePreview && currentChatUid === key;
  
        var options = [{
          text: intl.formatMessage({ id: 'delete_chat' }),
          onClick: function onClick() {
            _this.handleDeleteChat(key, val);
          },
          icon: _react2.default.createElement(
            _Icon2.default,
            null,
            'delete'
          )
        }, {
          text: intl.formatMessage({ id: 'mark_chat_as_unread' }),
          onClick: function onClick() {
            _this.handleMarkAsUnread(key, val);
          },
          icon: _react2.default.createElement(
            _Icon2.default,
            null,
            'history'
          )
        }];
  
        return _react2.default.createElement(
          'div',
          { key: i },
          _react2.default.createElement(
            _ListItem2.default,
            {
              selected: currentChatUid === key,
              key: i,
              onClick: function onClick() {
                _this.handleItemClick(val, key);
              },
              id: i },
            val.photoURL && _react2.default.createElement(_Avatar2.default, { src: val.photoURL, alt: 'person' }),
            !val.photoURL && _react2.default.createElement(
              _Avatar2.default,
              null,
              ' ',
              _react2.default.createElement(
                _Icon2.default,
                null,
                ' person '
              ),
              '  '
            ),
            _react2.default.createElement(_ListItemText2.default, {
              primaryTypographyProps: {
                color: val.unread ? 'secondary' : undefined
              },
              primary: val.unread > 0 ? _react2.default.createElement(
                'div',
                null,
                _react2.default.createElement(
                  'b',
                  null,
                  val.displayName
                )
              ) : val.displayName,
              secondary: _this.renderIcons(val)
            }),
            _react2.default.createElement(
              _ListItemSecondaryAction2.default,
              { style: { paddingTop: 24 } },
              _react2.default.createElement(
                _Typography2.default,
                { variant: 'caption', style: { paddingRight: 12 } },
                val.lastCreated ? intl.formatTime(new Date(val.lastCreated), 'hh:mm') : undefined
              )
            ),
            _react2.default.createElement(
              _ListItemSecondaryAction2.default,
              { style: { paddingBottom: 24 } },
              _react2.default.createElement(
                _Typography2.default,
                { component: 'div' },
                _react2.default.createElement(_IconMenu2.default, {
                  options: options,
                  iconName: 'more_horiz'
                })
              )
            )
          ),
          _react2.default.createElement(_Divider2.default, { inset: true })
        );
      }, _temp), _possibleConstructorReturn(_this, _ret);
    }
  
    Chats.prototype.componentDidMount = function componentDidMount() {
      var _props = this.props,
          watchList = _props.watchList,
          path = _props.path;
  
      watchList(path);
  
      //requestNotificationPermission(this.props)
    };
  
    Chats.prototype.componentDidCatch = function componentDidCatch(error, info) {
      // Display fallback UI
      this.setState({ hasError: true });
      // You can also log the error to an error reporting service
      //logErrorToMyService(error, info);
    };
  
    Chats.prototype.render = function render() {
      var _props2 = this.props,
          intl = _props2.intl,
          list = _props2.list,
          history = _props2.history,
          persistentValues = _props2.persistentValues,
          auth = _props2.auth,
          width = _props2.width,
          uid = _props2.uid;
  
  
      if (this.state.hasError) {
        // You can render any custom fallback UI
        return _react2.default.createElement(
          'h1',
          null,
          'Something went wrong.'
        );
      }
      var path = 'user_chats/' + auth.uid;
      var currentChatUid = uid; //persistentValues['current_chat_uid'] ? persistentValues['current_chat_uid'] : ''
      var usePreview = (0, _withWidth.isWidthUp)('sm', width);
      var isDisplayingMessages = usePreview && currentChatUid;
  
      return _react2.default.createElement(
        'div',
        { style: { width: '100%', maxWidth: usePreview ? 300 : undefined, height: '100%' } },
        _react2.default.createElement(
          _Scrollbar2.default,
          null,
          _react2.default.createElement(
            _List2.default,
            { style: { padding: 0, height: '100%', width: '100%', maxWidth: usePreview ? 300 : undefined } },
            _react2.default.createElement(_reactList2.default, {
              style: { maxWidth: 300 },
              itemRenderer: this.renderItem,
              length: list ? list.length : 0,
              type: 'simple'
            })
          )
        ),
        _react2.default.createElement(
          'div',
          { style: { position: 'absolute', width: usePreview ? 300 : '100%', bottom: 5 } },
          _react2.default.createElement(
            _Button2.default,
            {
              variant: 'fab',
              color: 'secondary',
              onClick: function onClick() {
                history.push('/chats/create');
              },
              style: { position: 'absolute', right: 20, bottom: 10, zIndex: 99 }
            },
            _react2.default.createElement(
              _Icon2.default,
              { className: 'material-icons' },
              'chat'
            )
          )
        )
      );
    };
  
    return Chats;
  }(_react.Component);
  
  Chats.propTypes = process.env.NODE_ENV !== "production" ? {
    list: _propTypes2.default.array.isRequired,
    history: _propTypes2.default.object,
    intl: _reactIntl.intlShape
  } : {};
  
  var mapStateToProps = function mapStateToProps(state, ownPops) {
    var lists = state.lists,
        auth = state.auth,
        persistentValues = state.persistentValues;
    var match = ownPops.match;
  
    var uid = match.params.uid;
  
    var path = 'user_chats/' + auth.uid;
    var list = (0, _firekit.getList)(state, path).sort(_materialUiFilter.filterSelectors.dynamicSort('lastCreated', false, function (fieldValue) {
      return fieldValue.val;
    }));
  
    return {
      uid: uid,
      auth: auth,
      path: path,
      persistentValues: persistentValues,
      list: list
    };
  };
  
  exports.default = (0, _reactRedux.connect)(mapStateToProps, { setPersistentValue: _actions.setPersistentValue })((0, _reactIntl.injectIntl)((0, _firekitProvider.withFirebase)((0, _withAppConfigs2.default)((0, _reactRouterDom.withRouter)((0, _withWidth2.default)()((0, _styles.withTheme)()((0, _styles.withStyles)(function (theme) {}, { withTheme: true })(Chats))))))));