text: var _class, _temp, _initialiseProps;
  
  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; }
  
  import AudioPlayer from '../../containers/AudioPlayer';
  import Input from './Input';
  import Message from './Message';
  import Chip from '@material-ui/core/Chip';
  import Divider from '@material-ui/core/Divider';
  import Button from '@material-ui/core/Button';
  import Icon from '@material-ui/core/Icon';
  import IconButton from '@material-ui/core/IconButton';
  import Image from 'material-ui-image';
  import PropTypes from 'prop-types';
  import React, { Component } from 'react';
  import ReactDOM from 'react-dom';
  import Scrollbar from '../../components/Scrollbar';
  import TextField from '@material-ui/core/TextField';
  import firebase from 'firebase';
  import moment from 'moment';
  import { withTheme, withStyles } from '@material-ui/core/styles';
  import ListItem from '@material-ui/core/ListItem';
  import { connect } from 'react-redux';
  import { getGeolocation } from '../../utils/googleMaps';
  import { injectIntl, intlShape } from 'react-intl';
  import { setSimpleValue } from '../../store/simpleValues/actions';
  import { withFirebase } from 'firekit-provider';
  import { withRouter } from 'react-router-dom';
  import { getList } from 'firekit';
  import requestNotificationPermission from '../../utils/messaging';
  import withAppConfigs from '../../utils/withAppConfigs';
  import { setPersistentValue } from '../../store/persistentValues/actions';
  
  var pageStep = 20;
  
  var ChatMessages = (_temp = _class = function (_Component) {
    _inherits(ChatMessages, _Component);
  
    function ChatMessages(props) {
      _classCallCheck(this, ChatMessages);
  
      var _this = _possibleConstructorReturn(this, _Component.call(this, props));
  
      _initialiseProps.call(_this);
  
      _this.name = null;
      _this.listEnd = null;
      return _this;
    }
  
    ChatMessages.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
      var _props = this.props,
          unwatchList = _props.unwatchList,
          path = _props.path;
      var nextPath = nextProps.path;
  
  
      if (path !== nextPath) {
        unwatchList(path);
        this.initMessages(nextProps);
      }
    };
  
    ChatMessages.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
      this.scrollToBottom();
    };
  
    ChatMessages.prototype.componentDidMount = function componentDidMount() {
      var _props2 = this.props,
          uid = _props2.uid,
          userChats = _props2.userChats,
          setPersistentValue = _props2.setPersistentValue;
  
  
      this.initMessages(this.props);
      this.scrollToBottom();
  
      requestNotificationPermission(this.props);
  
      userChats.forEach(function (chat) {
        if (chat.key === uid) {
          setPersistentValue('current_chat_name', chat.val.displayName);
        }
      });
    };
  
    ChatMessages.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);
    };
  
    ChatMessages.prototype.renderList = function renderList(messages) {
      var _props3 = this.props,
          auth = _props3.auth,
          intl = _props3.intl,
          theme = _props3.theme,
          history = _props3.history,
          path = _props3.path;
  
  
      var currentDate = '';
      var currentAuthor = '';
  
      if (messages === undefined) {
        return React.createElement('div', null);
      }
  
      return messages.map(function (row, i) {
        var values = row.val;
        //const key=row.key
  
        if (values.created === null) {
          return undefined;
        }
  
        var myBColor = theme.palette.type === 'light' ? theme.palette.grey[300] : theme.palette.grey[700];
  
        var stringDate = values.created ? new Date(values.created).toISOString().slice(0, 10) : '';
        var dataChanged = false;
        var authorChanged = false;
        var backgroundColor = values.authorUid === auth.uid ? theme.palette.primary.main : myBColor;
        var color = theme.palette.text.primary;
        var type = values.message ? 'text' : values.link ? "link" : values.location ? 'location' : values.image ? 'image' : undefined;
  
        if (values.type) {
          type = values.type;
        }
  
        if (currentDate !== stringDate) {
          currentDate = stringDate;
          dataChanged = true;
        }
  
        if (currentAuthor !== values.authorUid) {
          currentAuthor = values.authorUid;
          authorChanged = true;
        }
  
        return React.createElement(Message, {
          key: i,
          path: path,
          dataChanged: dataChanged,
          authorChanged: authorChanged,
          row: row,
          i: i,
          values: values,
          backgroundColor: backgroundColor,
          color: color,
          type: type
        });
      });
    };
  
    ChatMessages.prototype.render = function render() {
      var _this2 = this;
  
      var _props4 = this.props,
          messages = _props4.messages,
          theme = _props4.theme,
          intl = _props4.intl,
          setSimpleValue = _props4.setSimpleValue,
          chatMessageMenuOpen = _props4.chatMessageMenuOpen,
          predefinedMessages = _props4.predefinedMessages,
          uid = _props4.uid,
          firebaseApp = _props4.firebaseApp,
          auth = _props4.auth,
          path = _props4.path,
          receiverPath = _props4.receiverPath;
  
  
      if (this.state.hasError) {
        // You can render any custom fallback UI
        return React.createElement(
          'h1',
          null,
          'Something went wrong.'
        );
      }
  
      return React.createElement(
        Scrollbar,
        {
          style: {
            backgroundColor: theme.palette.background.default,
            width: '100%'
          } },
        React.createElement(
          'div',
          { style: { display: 'flex', justifyContent: 'center', alignItems: 'center' } },
          React.createElement(
            'div',
            { style: { maxWidth: 600, margin: 8, width: '100%' } },
            React.createElement(
              'div',
              { style: { display: 'flex', justifyContent: 'center' } },
              React.createElement(Chip, {
                label: intl.formatMessage({ id: 'load_more_label' }),
                onClick: this.handleLoadMore,
                backgroundColor: theme.palette.primary.main
              })
            ),
            this.renderList(messages)
          )
        ),
        React.createElement('div', {
          style: { float: "left", clear: "both" },
          ref: function ref(el) {
            _this2.listEnd = el;
          } })
      );
    };
  
    return ChatMessages;
  }(Component), _initialiseProps = function _initialiseProps() {
    var _this3 = this;
  
    this.state = {
      anchorEl: null,
      hasError: false
    };
  
    this.scrollToBottom = function () {
      var node = ReactDOM.findDOMNode(_this3.listEnd);
      if (node) {
        node.scrollIntoView({ behavior: "smooth" });
      }
    };
  
    this.initMessages = function (props) {
      var watchList = props.watchList,
          firebaseApp = props.firebaseApp,
          path = props.path,
          auth = props.auth;
  
  
      try {
        var messagesRef = firebaseApp.database().ref(path).orderByKey().limitToLast(pageStep);
        watchList(messagesRef);
        watchList('user_chats/' + auth.uid);
      } catch (error) {
        console.log(error);
      }
    };
  
    this.handleLoadMore = function () {
      var _props5 = _this3.props,
          watchList = _props5.watchList,
          unwatchList = _props5.unwatchList,
          firebaseApp = _props5.firebaseApp,
          setSimpleValue = _props5.setSimpleValue,
          simpleValues = _props5.simpleValues,
          path = _props5.path;
  
  
      var currentAmount = simpleValues['chat_messages_limit'] ? simpleValues['chat_messages_limit'] : pageStep;
      var nextAmount = currentAmount + pageStep;
  
      unwatchList(path);
      setSimpleValue('chat_messages_limit', nextAmount);
      var messagesRef = firebaseApp.database().ref(path).orderByKey().limitToLast(nextAmount);
      watchList(messagesRef);
    };
  }, _temp);
  
  
  ChatMessages.propTypes = process.env.NODE_ENV !== "production" ? {
    intl: intlShape.isRequired,
    theme: PropTypes.object.isRequired,
    auth: PropTypes.object.isRequired
  } : {};
  
  var mapStateToProps = function mapStateToProps(state, ownPops) {
    var lists = state.lists,
        auth = state.auth,
        simpleValues = state.simpleValues,
        messaging = state.messaging;
    var uid = ownPops.uid,
        path = ownPops.path;
  
  
    var chatMessageMenuOpen = simpleValues['chatMessageMenuOpen'] === true;
    var imageDialogOpen = simpleValues.chatOpenImageDialog;
    var chatsPath = 'user_chats/' + auth.uid;
  
    return {
      imageDialogOpen: imageDialogOpen,
      simpleValues: simpleValues,
      path: path,
      uid: uid,
      chatMessageMenuOpen: chatMessageMenuOpen,
      messaging: messaging,
      messages: getList(state, path),
      userChats: getList(state, chatsPath),
      predefinedMessages: getList(state, 'predefined_chat_messages'),
      auth: auth
    };
  };
  
  export default connect(mapStateToProps, { setSimpleValue: setSimpleValue, setPersistentValue: setPersistentValue })(injectIntl(withTheme()(withRouter(withFirebase(withAppConfigs(ChatMessages))))));