import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { style } from 'typestyle';
import red from '@material-ui/core/colors/red';
var cn = {
  root: style({
    position: 'absolute',
    width: '100%',
    top: 0,
    display: 'flex',
    flexDirection: 'column',
    backgroundColor: red['500'],
    zIndex: 3000
  }),
  pre: style({
    width: '100%',
    maxHeight: '8rem',
    color: 'white',
    overflow: 'scroll',
    fontFamily: 'Consolas, "Liberation Mono", Menlo, Courier, monospace'
  })
};

var ErrorMessage =
/*#__PURE__*/
function (_PureComponent) {
  _inherits(ErrorMessage, _PureComponent);

  function ErrorMessage() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, ErrorMessage);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(ErrorMessage)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
      open: false
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleClose", function () {
      _this.setState({
        open: false
      });
    });

    return _this;
  }

  _createClass(ErrorMessage, [{
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps) {
      if (prevProps.error !== this.props.error) {
        this.setState({
          open: this.props.error !== null
        });
      }
    }
  }, {
    key: "render",
    value: function render() {
      return this.state.open ? React.createElement("div", {
        className: cn.root
      }, React.createElement("div", {
        style: {
          cursor: 'pointer',
          alignSelf: 'flex-end'
        },
        onClick: this.handleClose
      }, React.createElement("svg", {
        fill: "white",
        style: {
          height: 24
        },
        viewBox: "0 0 24 24"
      }, React.createElement("path", {
        d: 'M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'
      }))), React.createElement("pre", {
        className: cn.pre
      }, this.message)) : null;
    }
  }, {
    key: "message",
    get: function get() {
      return this.props.error ? this.props.error.message : '';
    }
  }]);

  return ErrorMessage;
}(PureComponent);

_defineProperty(ErrorMessage, "propTypes", {
  error: PropTypes.object
});

_defineProperty(ErrorMessage, "defaultProps", {
  error: null
});

export { ErrorMessage as default };