"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _BEM = require("../../../core/utils/BEM");

var _propTypes = _interopRequireDefault(require("prop-types"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

// Style

/* istanbul ignore next */
if (typeof window !== 'undefined') require("./style.scss");

var Notification = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Notification, _Component);

  var _super = _createSuper(Notification);

  function Notification(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Notification);
    _this = _super.call(this, props, 'Notifcation');
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function () {
      _this.setState({
        open: !_this.state.open
      });

      if (typeof _this.props.handleClick === 'function') _this.props.handleClick();
    });
    _this.state = {
      open: true
    };
    return _this;
  }

  (0, _createClass2["default"])(Notification, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          children = _this$props.children,
          color = _this$props.color,
          className = _this$props.className,
          dismissible = _this$props.dismissible,
          emoji = _this$props.emoji,
          position = _this$props.position;
      var open = this.state.open;
      var NotificationClasses = ['Notification', "Notification_".concat(color), "Notification_".concat(open ? 'open' : 'close'), position && "Notification_".concat(position), className].filter(function (e) {
        return e;
      }).join(' ');
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: NotificationClasses
      }, emoji && /*#__PURE__*/_react["default"].createElement("span", {
        "aria-label": "",
        className: "Notification-Emoji",
        role: "img"
      }, emoji), children, dismissible && /*#__PURE__*/_react["default"].createElement("button", {
        className: "Notification-Button",
        onClick: this.handleClick,
        type: "button"
      }, /*#__PURE__*/_react["default"].createElement("i", {
        className: "icon icon-cancel"
      })));
    }
  }]);
  return Notification;
}(_BEM.Component);

exports["default"] = Notification;
(0, _defineProperty2["default"])(Notification, "propTypes", {
  color: _propTypes["default"].oneOf(['graphite', 'green', 'red']),
  dismissible: _propTypes["default"].bool,
  emoji: _propTypes["default"].string,
  handleClick: _propTypes["default"].func,
  position: _propTypes["default"].oneOf(['bottom', 'top'])
});
(0, _defineProperty2["default"])(Notification, "defaultProps", {
  color: 'graphite',
  dismissible: false
});