'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 _class, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

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

var _Button2 = _interopRequireDefault(_Button);

var _CloseButton = require('@instructure/ui-buttons/lib/components/CloseButton');

var _CloseButton2 = _interopRequireDefault(_CloseButton);

var _Heading = require('@instructure/ui-elements/lib/components/Heading');

var _Heading2 = _interopRequireDefault(_Heading);

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

var _Text2 = _interopRequireDefault(_Text);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _constants = require('../../../constants');

var _Modal = require('../Modal');

var _Modal2 = _interopRequireDefault(_Modal);

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

var ConfirmationModal = (_temp2 = _class = function (_Component) {
  (0, _inherits3.default)(ConfirmationModal, _Component);

  function ConfirmationModal() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = ConfirmationModal.__proto__ || Object.getPrototypeOf(ConfirmationModal)).call.apply(_ref, [this].concat(args))), _this), _this.continueAction = function () {
      var continueCb = _this.props.modalOptions.get('onContinue');
      continueCb && continueCb();
      _this.props.closeModal();
    }, _this.cancelAction = function () {
      var cancelCb = _this.props.modalOptions.get('onCancel');
      cancelCb && cancelCb();
      _this.props.closeModal();
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(ConfirmationModal, [{
    key: 'render',
    value: function render() {
      var modalOptions = this.props.modalOptions;

      var title = modalOptions.get('title') || 'Confirmar';
      var body = modalOptions.get('text') || 'Voc\xEA tem certeza?';
      var cancelText = modalOptions.get('cancelText') || 'Cancelar';
      var continueText = modalOptions.get('continueText') || 'Confirmar';

      return _react2.default.createElement(
        _Modal2.default,
        {
          open: this.props.modalOpen,
          size: modalOptions.get('size') || 'small',
          label: title,
          onDismiss: this.props.closeModal,
          'data-automation': 'sdk-confirmation-modal',
          shouldReturnFocus: modalOptions.shouldReturnFocus
        },
        _react2.default.createElement(
          _Modal.ModalHeader,
          null,
          _react2.default.createElement(
            _Heading2.default,
            { level: 'reset', as: 'h2' },
            title
          ),
          _react2.default.createElement(
            _CloseButton2.default,
            {
              onClick: this.props.closeModal,
              placement: 'end',
              offset: 'medium',
              variant: 'icon'
            },
            'Perto'
          )
        ),
        _react2.default.createElement(
          _Modal.ModalBody,
          null,
          _react2.default.createElement(
            _Text2.default,
            null,
            body
          )
        ),
        _react2.default.createElement(
          _Modal.ModalFooter,
          null,
          _react2.default.createElement(
            _Button2.default,
            {
              onClick: this.cancelAction,
              margin: _constants.XSMALL_SIDE_MARGIN
            },
            cancelText
          ),
          _react2.default.createElement(
            _Button2.default,
            {
              variant: modalOptions.get('continueVariant') || 'primary',
              onClick: this.continueAction,
              margin: _constants.XSMALL_SIDE_MARGIN
            },
            continueText
          )
        )
      );
    }
  }]);
  ConfirmationModal.displayName = 'ConfirmationModal'
  ;
  return ConfirmationModal;
}(_react.Component), _class.propTypes = {
  closeModal: _propTypes2.default.func.isRequired,
  modalOpen: _propTypes2.default.bool.isRequired,
  modalOptions: _reactImmutableProptypes2.default.map.isRequired
}, _temp2);
exports.default = ConfirmationModal;