text: 'use strict';
  
  exports.__esModule = true;
  exports.PredefinedChatMessages = undefined;
  
  var _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _reactRedux = require('react-redux');
  
  var _reactIntl = require('react-intl');
  
  var _Activity = require('../../containers/Activity');
  
  var _Activity2 = _interopRequireDefault(_Activity);
  
  var _List = require('@material-ui/core/List');
  
  var _List2 = _interopRequireDefault(_List);
  
  var _ListItem = require('@material-ui/core/ListItem');
  
  var _ListItem2 = _interopRequireDefault(_ListItem);
  
  var _ListItemText = require('@material-ui/core/ListItemText');
  
  var _ListItemText2 = _interopRequireDefault(_ListItemText);
  
  var _ListItemAvatar = require('@material-ui/core/ListItemAvatar');
  
  var _ListItemAvatar2 = _interopRequireDefault(_ListItemAvatar);
  
  var _ListItemSecondaryAction = require('@material-ui/core/ListItemSecondaryAction');
  
  var _ListItemSecondaryAction2 = _interopRequireDefault(_ListItemSecondaryAction);
  
  var _Divider = require('@material-ui/core/Divider');
  
  var _Divider2 = _interopRequireDefault(_Divider);
  
  var _firekitProvider = require('firekit-provider');
  
  var _reactRouterDom = require('react-router-dom');
  
  var _Icon = require('@material-ui/core/Icon');
  
  var _Icon2 = _interopRequireDefault(_Icon);
  
  var _auth = require('../../utils/auth');
  
  var _auth2 = _interopRequireDefault(_auth);
  
  var _propTypes = require('prop-types');
  
  var _propTypes2 = _interopRequireDefault(_propTypes);
  
  var _actions = require('../../store/simpleValues/actions');
  
  var _reduxFormMaterialUi = require('redux-form-material-ui');
  
  var _Button = require('@material-ui/core/Button');
  
  var _Button2 = _interopRequireDefault(_Button);
  
  var _IconButton = require('@material-ui/core/IconButton');
  
  var _IconButton2 = _interopRequireDefault(_IconButton);
  
  var _BottomNavigation = require('@material-ui/core/BottomNavigation');
  
  var _BottomNavigation2 = _interopRequireDefault(_BottomNavigation);
  
  var _Dialog = require('@material-ui/core/Dialog');
  
  var _Dialog2 = _interopRequireDefault(_Dialog);
  
  var _DialogActions = require('@material-ui/core/DialogActions');
  
  var _DialogActions2 = _interopRequireDefault(_DialogActions);
  
  var _DialogContent = require('@material-ui/core/DialogContent');
  
  var _DialogContent2 = _interopRequireDefault(_DialogContent);
  
  var _DialogContentText = require('@material-ui/core/DialogContentText');
  
  var _DialogContentText2 = _interopRequireDefault(_DialogContentText);
  
  var _DialogTitle = require('@material-ui/core/DialogTitle');
  
  var _DialogTitle2 = _interopRequireDefault(_DialogTitle);
  
  var _styles = require('@material-ui/core/styles');
  
  var _reactList = require('react-list');
  
  var _reactList2 = _interopRequireDefault(_reactList);
  
  var _Scrollbar = require('../../components/Scrollbar');
  
  var _Scrollbar2 = _interopRequireDefault(_Scrollbar);
  
  var _firekit = require('firekit');
  
  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 path = 'predefined_chat_messages';
  
  var PredefinedChatMessages = exports.PredefinedChatMessages = function (_Component) {
    _inherits(PredefinedChatMessages, _Component);
  
    function PredefinedChatMessages() {
      var _temp, _this, _ret;
  
      _classCallCheck(this, PredefinedChatMessages);
  
      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 = {
        value: ''
      }, _this.handleClose = function () {
        var setSimpleValue = _this.props.setSimpleValue;
  
        setSimpleValue('delete_predefined_chat_message', undefined);
      }, _this.handleDelete = function (key) {
        var _this$props = _this.props,
            firebaseApp = _this$props.firebaseApp,
            delete_predefined_chat_message = _this$props.delete_predefined_chat_message;
  
  
        if (key) {
          firebaseApp.database().ref('/' + path + '/' + delete_predefined_chat_message).remove().then(function () {
            _this.handleClose();
          });
        }
      }, _this.handleKeyDown = function (event, onSuccess) {
        if (event.keyCode === 13) {
          onSuccess();
        }
      }, _this.handleAddMessage = function () {
        var firebaseApp = _this.props.firebaseApp;
  
  
        firebaseApp.database().ref('/' + path + '/').push({ message: _this.state.value }).then(function () {
          _this.setState({ value: '' });
        });
      }, _this.renderItem = function (i, k) {
        var _this$props2 = _this.props,
            list = _this$props2.list,
            setSimpleValue = _this$props2.setSimpleValue;
  
  
        var key = list[i].key;
        var message = list[i].val.message;
  
        return _react2.default.createElement(
          'div',
          { key: key },
          _react2.default.createElement(
            _ListItem2.default,
            {
              key: key,
              id: key },
            _react2.default.createElement(_ListItemText2.default, { primary: message }),
            _react2.default.createElement(
              _IconButton2.default,
              {
                onClick: function onClick() {
                  return setSimpleValue('delete_predefined_chat_message', key);
                } },
              _react2.default.createElement(
                _Icon2.default,
                { color: 'secondary' },
                'delete'
              )
            )
          ),
          _react2.default.createElement(_Divider2.default, null)
        );
      }, _temp), _possibleConstructorReturn(_this, _ret);
    }
  
    PredefinedChatMessages.prototype.componentWillMount = function componentWillMount() {
      var watchList = this.props.watchList;
  
      watchList(path);
    };
  
    PredefinedChatMessages.prototype.render = function render() {
      var _this2 = this;
  
      var _props = this.props,
          intl = _props.intl,
          list = _props.list,
          theme = _props.theme,
          delete_predefined_chat_message = _props.delete_predefined_chat_message;
  
  
      return _react2.default.createElement(
        _Activity2.default,
        {
          isLoading: list === undefined,
          containerStyle: { overflow: 'hidden' },
          title: intl.formatMessage({ id: 'predefined_messages' }) },
        _react2.default.createElement(
          'div',
          { style: { overflow: 'auto', height: '100%', width: '100%', backgroundColor: theme.palette.canvasColor, paddingBottom: 56 } },
          _react2.default.createElement(
            _Scrollbar2.default,
            null,
            _react2.default.createElement(
              _List2.default,
              { ref: function ref(field) {
                  _this2.list = field;
                } },
              _react2.default.createElement(_reactList2.default, {
                itemRenderer: this.renderItem,
                length: list.length,
                type: 'simple'
              })
            )
          ),
          _react2.default.createElement('div', { style: { float: "left", clear: "both" },
            ref: function ref(el) {
              _this2.listEnd = el;
            }
          })
        ),
        list && _react2.default.createElement(
          _BottomNavigation2.default,
          { style: { width: '100%', position: 'absolute', bottom: 0, right: 0, left: 0, zIndex: 50, backgroundColor: theme.palette.background.default } },
          _react2.default.createElement(
            'div',
            { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 15 } },
            _react2.default.createElement(_reduxFormMaterialUi.TextField, {
              id: 'predefinedChatMessage',
              fullWidth: true,
              value: this.state.value,
              onChange: function onChange(e) {
                _this2.setState({ value: e.target.value });
              },
              onKeyDown: function onKeyDown(event) {
                _this2.handleKeyDown(event, _this2.handleAddMessage);
              },
              ref: 'predefinedChatMessage',
              type: 'Text'
            }),
            _react2.default.createElement(
              _IconButton2.default,
              {
                disabled: !this.state.value,
                onClick: this.handleAddMessage },
              _react2.default.createElement(
                _Icon2.default,
                { className: 'material-icons', color: theme.palette.primary1Color },
                'send'
              )
            )
          )
        ),
        _react2.default.createElement(
          _Dialog2.default,
          {
            open: delete_predefined_chat_message !== undefined,
            onClose: this.handleClose,
            'aria-labelledby': 'alert-dialog-title',
            'aria-describedby': 'alert-dialog-description'
          },
          _react2.default.createElement(
            _DialogTitle2.default,
            { id: 'alert-dialog-title' },
            intl.formatMessage({ id: 'delete_predefined_chat_message_title' })
          ),
          _react2.default.createElement(
            _DialogContent2.default,
            null,
            _react2.default.createElement(
              _DialogContentText2.default,
              { id: 'alert-dialog-description' },
              intl.formatMessage({ id: 'delete_predefined_chat_message_message' })
            )
          ),
          _react2.default.createElement(
            _DialogActions2.default,
            null,
            _react2.default.createElement(
              _Button2.default,
              { onClick: this.handleClose, color: 'primary' },
              intl.formatMessage({ id: 'cancel' })
            ),
            _react2.default.createElement(
              _Button2.default,
              { onClick: this.handleDelete, color: 'secondary' },
              intl.formatMessage({ id: 'delete' })
            )
          )
        )
      );
    };
  
    return PredefinedChatMessages;
  }(_react.Component);
  
  PredefinedChatMessages.propTypes = process.env.NODE_ENV !== "production" ? {
    list: _propTypes2.default.array.isRequired,
    history: _propTypes2.default.object,
    intl: _reactIntl.intlShape.isRequired,
    isGranted: _propTypes2.default.func.isRequired
  } : {};
  
  var mapStateToProps = function mapStateToProps(state) {
    var lists = state.lists,
        simpleValues = state.simpleValues;
  
  
    var delete_predefined_chat_message = simpleValues.delete_predefined_chat_message;
  
    return {
      delete_predefined_chat_message: delete_predefined_chat_message,
      list: (0, _firekit.getList)(state, path),
      isGranted: function isGranted(grant) {
        return (0, _auth2.default)(state, grant);
      }
    };
  };
  
  exports.default = (0, _reactRedux.connect)(mapStateToProps, { setSimpleValue: _actions.setSimpleValue })((0, _reactIntl.injectIntl)((0, _styles.withTheme)()((0, _reactRouterDom.withRouter)((0, _firekitProvider.withFirebase)(PredefinedChatMessages)))));