'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,
    _default_enIE_number = Intl.NumberFormat('en-IE', { style: 'decimal' }).format;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _View = require('@instructure/ui-layout/lib/components/View');

var _View2 = _interopRequireDefault(_View);

var _Link = require('@instructure/ui-elements/lib/components/Link');

var _Link2 = _interopRequireDefault(_Link);

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

var _lib2 = _interopRequireDefault(_lib);

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

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

var _theme2 = _interopRequireDefault(_theme);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.AddToBankOptions__styles__addToBank {\n  background-color: ' + theme.addToBankBackgroundColor + ';\n  border: 1px dashed ' + theme.addToBankBorderColor + ';\n  cursor: pointer;\n  padding: ' + theme.addToBankPadding + ';\n}\n';
  },
  'addToBank': 'AddToBankOptions__styles__addToBank'
};
var AddToBankOptions = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(AddToBankOptions, _Component);

  function AddToBankOptions() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = AddToBankOptions.__proto__ || Object.getPrototypeOf(AddToBankOptions)).call.apply(_ref, [this].concat(args))), _this), _this.openAddToBankModal = function () {
      var displayPosition = _this.props.displayPosition;

      if (_this.props.isValid) {
        _this.props.openModal([_constants.ADD_TO_BANK_MODAL, _this.props.entryType, _this.props.guid].join(':'), { modalTrigger: _this.addToBankLink });
      } else {
        var msg = _this.props.entryType + ' ' + _default_enIE_number(displayPosition) + ' cannot be saved due to invalid input data.';
        _this.props.screenreaderNotification(msg);
        _this.props.showError(_this.props.guid);
      }
    }, _this.storeAddToBankLinkRef = function (c) {
      _this.addToBankLink = c;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(AddToBankOptions, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          _View2.default,
          {
            as: 'div',
            className: styles.addToBank,
            textAlign: 'center',
            padding: 'small'
          },
          _react2.default.createElement(
            _Link2.default,
            {
              ref: this.storeAddToBankLinkRef,
              onClick: this.openAddToBankModal,
              'data-automation': 'sdk-add-to-bank-link'
            },
            'Add to Bank'
          )
        )
      );
    }
  }]);
  AddToBankOptions.displayName = 'AddToBankOptions'
  ;
  return AddToBankOptions;
}(_react.Component), _class2.propTypes = {
  displayPosition: _propTypes2.default.number.isRequired,
  entryType: _propTypes2.default.string.isRequired,
  guid: _propTypes2.default.string.isRequired,
  isValid: _propTypes2.default.bool.isRequired,
  openModal: _propTypes2.default.func.isRequired,
  screenreaderNotification: _propTypes2.default.func.isRequired,
  showError: _propTypes2.default.func.isRequired
}, _temp2)) || _class);
exports.default = AddToBankOptions;