'use strict';

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

exports.__esModule = true;
exports.Confirm = void 0;

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

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

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

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

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

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

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

var _Popup = require("./Popup");

var _Button = require("../Button");

var _DangerousHTML = require("../DangerousHTML");

var Confirm =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(Confirm, _React$Component);

  function Confirm(props, context) {
    var _this;

    _this = _React$Component.call(this, props, context) || this;
    _this.submitAction = _this.submitAction.bind((0, _assertThisInitialized2.default)(_this));
    _this.cancelAction = _this.cancelAction.bind((0, _assertThisInitialized2.default)(_this));
    return _this;
  }

  var _proto = Confirm.prototype;

  _proto.submitAction = function submitAction() {
    if (!this.props.noAutoClose) {
      _Popup.Popup.close();
    }

    this.props.submitAction();
  };

  _proto.cancelAction = function cancelAction() {
    if (!this.props.noAutoClose) {
      _Popup.Popup.close();
    }

    if (typeof this.props.cancelAction === 'function') {
      this.props.cancelAction();
    }
  };

  _proto.render = function render() {
    var _this$props = this.props,
        buttonYesStyle = _this$props.buttonYesStyle,
        submitText = _this$props.submitText,
        cancelText = _this$props.cancelText,
        noAutoClose = _this$props.noAutoClose,
        submitAction = _this$props.submitAction,
        props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["buttonYesStyle", "submitText", "cancelText", "noAutoClose", "submitAction"]);
    var buttons = [_react.default.createElement(_Button.Button, {
      key: "buttonNo",
      testAutomationId: "buttonNo",
      onClick: this.cancelAction
    }, _react.default.createElement(_DangerousHTML.DangerousHTML, null, cancelText)), _react.default.createElement(_Button.Button, {
      key: "buttonYes",
      bsStyle: buttonYesStyle,
      testAutomationId: "buttonYes",
      onClick: this.submitAction
    }, _react.default.createElement(_DangerousHTML.DangerousHTML, null, submitText))];
    return _react.default.createElement(_Popup.Popup, (0, _extends2.default)({}, props, {
      onClose: this.cancelAction,
      bsSize: "sm",
      footer: buttons
    }));
  };

  return Confirm;
}(_react.default.Component);

exports.Confirm = Confirm;
(0, _defineProperty2.default)(Confirm, "propTypes", {
  buttonYesStyle: _propTypes.default.string,
  submitText: _propTypes.default.string,
  cancelText: _propTypes.default.string,
  submitAction: _propTypes.default.func.isRequired,
  cancelAction: _propTypes.default.func.isRequired,
  noAutoClose: _propTypes.default.bool,
  shouldDeriveDescFromBody: _propTypes.default.bool
});
(0, _defineProperty2.default)(Confirm, "defaultProps", {
  buttonYesStyle: 'primary',
  title: 'TRANSLATE:CONFIRMATION',
  submitText: 'TRANSLATE:YES',
  cancelText: 'TRANSLATE:NO',
  testAutomationId: 'confirm',
  noAutoClose: false,
  shouldDeriveDescFromBody: true
});