'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = undefined;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Alert = require('@instructure/ui-alerts/lib/components/Alert');

var _Alert2 = _interopRequireDefault(_Alert);

var _Button = require('@instructure/ui-buttons/lib/components/Button');

var _Button2 = _interopRequireDefault(_Button);

var _Text = require('@instructure/ui-elements/lib/components/Text');

var _Text2 = _interopRequireDefault(_Text);

var _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

var _formatMessage = require('../../../format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.WarningWrapper__styles__alert {\n  padding-bottom: ' + theme.alertPadding + ';\n  z-index: ' + theme.alertZIndex + ';\n  position: inherit;\n}\n\n.WarningWrapper__styles__alertContent {\n  display: block;\n}\n\n.WarningWrapper__styles__container {\n  position: relative;\n  padding: ' + theme.containerPadding + ';\n}\n\n.WarningWrapper__styles__disabledChildren {\n  background-color: ' + theme.disabledChildrenBackgroundColor + ';\n  opacity: ' + theme.disabledChildrenOpacity + ';\n  position: absolute;\n  z-index: ' + theme.disabledChildrenZIndex + ';\n  top: 0;\n  bottom: 0;\n  left: 0;\n  right: 0;\n}\n';
  },
  'alert': 'WarningWrapper__styles__alert',
  'alertContent': 'WarningWrapper__styles__alertContent',
  'container': 'WarningWrapper__styles__container',
  'disabledChildren': 'WarningWrapper__styles__disabledChildren'
};
var WarningWrapper = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(WarningWrapper, _Component);

  function WarningWrapper() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, WarningWrapper);

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

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = WarningWrapper.__proto__ || Object.getPrototypeOf(WarningWrapper)).call.apply(_ref, [this].concat(args))), _this), _this.focusRef = null, _this.setFocusRef = function (element) {
      _this.focusRef = element;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(WarningWrapper, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      if (this.focusRef) this.focusRef.focus();
    }
  }, {
    key: 'renderMessage',
    value: function renderMessage() {
      if (!this.props.showAlert) return;
      return this.renderAlert();
    }
  }, {
    key: 'renderActionButtons',
    value: function renderActionButtons() {
      if (this.props.hideActions) return;
      return _react2.default.createElement(
        'div',
        { className: styles.alertContentRow },
        _react2.default.createElement(
          _Button2.default,
          { size: 'small', onClick: this.props.cancelActionCallback, ref: this.setFocusRef },
          this.props.cancelActionText
        ),
        _react2.default.createElement(
          _Button2.default,
          { size: 'small', margin: 'x-small', variant: 'primary', onClick: this.props.defaultActionCallback },
          this.props.defaultActionText
        )
      );
    }
  }, {
    key: 'renderDescription',
    value: function renderDescription() {
      return _react2.default.createElement(
        'div',
        { className: styles.alertContentRow },
        _react2.default.createElement(
          _Text2.default,
          null,
          this.props.description
        )
      );
    }
  }, {
    key: 'renderAlertContent',
    value: function renderAlertContent() {
      return _react2.default.createElement(
        'div',
        { className: styles.alertContent },
        this.renderDescription(),
        this.renderActionButtons()
      );
    }
  }, {
    key: 'renderAlert',
    value: function renderAlert() {
      return _react2.default.createElement(
        'div',
        { className: styles.alert },
        _react2.default.createElement(
          _Alert2.default,
          { variant: this.props.alertType },
          this.renderAlertContent()
        )
      );
    }
  }, {
    key: 'renderDisableOverlay',
    value: function renderDisableOverlay() {
      if (!this.props.disableChildren) return;
      return _react2.default.createElement('div', { className: styles.disabledChildren });
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: styles.container },
        this.renderMessage(),
        this.renderDisableOverlay(),
        this.props.children
      );
    }
  }]);
  WarningWrapper.displayName = 'WarningWrapper'
  ;
  return WarningWrapper;
}(_react.Component), _class2.propTypes = {
  alertType: _propTypes2.default.oneOf(['info', 'success', 'warning', 'error']),
  cancelActionCallback: _propTypes2.default.func,
  cancelActionText: _propTypes2.default.string,
  children: _propTypes2.default.node.isRequired,
  defaultActionCallback: _propTypes2.default.func,
  defaultActionText: _propTypes2.default.string,
  description: _propTypes2.default.node,
  disableChildren: _propTypes2.default.bool,
  hideActions: _propTypes2.default.bool,
  showAlert: _propTypes2.default.bool
}, _class2.defaultProps = {
  alertType: 'info',
  cancelActionText: 'Cancelar',
  defaultActionText: 'Presentar',
  disableChildren: false,
  showAlert: true
}, _temp2)) || _class);
exports.default = WarningWrapper;