"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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 _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

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

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

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

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

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

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

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

var _constants = require("@instructure/quiz-common/lib/constants");

var _theme = _interopRequireDefault(require("./theme"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

var _dec,
    _class,
    _class2,
    _temp,
    _default_cy_number = Intl.NumberFormat("cy", { style: "decimal" }).format;

var styles = {
  componentId: 'dYFmJ',
  template: function template(theme) {
    return "\n\n.dYFmJ_dNGs{background-color:".concat(theme.addToBankBackgroundColor || 'inherit', ";border:1px dashed ").concat(theme.addToBankBorderColor || 'inherit', "}");
  },
  'addToBank': 'dYFmJ_dNGs'
};
var AddToBankOptions = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(AddToBankOptions, _Component);

  function AddToBankOptions() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(AddToBankOptions)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _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 = "Methu cadw " + _this.props.entryType + " " + _default_cy_number(displayPosition) + " oherwydd data mewnbwn annilys.";

        _this.props.screenreaderNotification(msg);

        _this.props.showError(_this.props.guid);
      }
    };

    _this.storeAddToBankLinkRef = function (c) {
      _this.addToBankLink = c;
    };

    return _this;
  }

  (0, _createClass2.default)(AddToBankOptions, [{
    key: "render",
    value: function render() {
      return _react.default.createElement("div", null, _react.default.createElement(_View.default, {
        as: "div",
        className: styles.addToBank
      }, _react.default.createElement(_Button.default, {
        variant: "link",
        ref: this.storeAddToBankLinkRef,
        onClick: this.openAddToBankModal,
        "data-automation": "sdk-add-to-bank-link",
        fluidWidth: true
      }, _react.default.createElement(_View.default, {
        as: "div",
        textAlign: "center",
        padding: "xx-small"
      }, "Ychwanegu at y Banc"))));
    }
  }]);
  AddToBankOptions.displayName = "AddToBankOptions";
  return AddToBankOptions;
}(_react.Component), _class2.propTypes = {
  displayPosition: _propTypes.default.number.isRequired,
  entryType: _propTypes.default.string.isRequired,
  guid: _propTypes.default.string.isRequired,
  isValid: _propTypes.default.bool.isRequired,
  openModal: _propTypes.default.func.isRequired,
  screenreaderNotification: _propTypes.default.func.isRequired,
  showError: _propTypes.default.func.isRequired
}, _temp)) || _class);
exports.default = AddToBankOptions;