'use strict';

import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import { Popup } from './Popup';
import { Button } from '../Button';
import { DangerousHTML } from '../DangerousHTML';
export var Confirm =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(Confirm, _React$Component);

  function Confirm(props, context) {
    var _this;

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

  var _proto = Confirm.prototype;

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

    this.props.submitAction();
  };

  _proto.cancelAction = function cancelAction() {
    if (!this.props.noAutoClose) {
      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 = _objectWithoutPropertiesLoose(_this$props, ["buttonYesStyle", "submitText", "cancelText", "noAutoClose", "submitAction"]);

    var buttons = [React.createElement(Button, {
      key: "buttonNo",
      testAutomationId: "buttonNo",
      onClick: this.cancelAction
    }, React.createElement(DangerousHTML, null, cancelText)), React.createElement(Button, {
      key: "buttonYes",
      bsStyle: buttonYesStyle,
      testAutomationId: "buttonYes",
      onClick: this.submitAction
    }, React.createElement(DangerousHTML, null, submitText))];
    return React.createElement(Popup, _extends({}, props, {
      onClose: this.cancelAction,
      bsSize: "sm",
      footer: buttons
    }));
  };

  return Confirm;
}(React.Component);

_defineProperty(Confirm, "propTypes", {
  buttonYesStyle: PropTypes.string,
  submitText: PropTypes.string,
  cancelText: PropTypes.string,
  submitAction: PropTypes.func.isRequired,
  cancelAction: PropTypes.func.isRequired,
  noAutoClose: PropTypes.bool,
  shouldDeriveDescFromBody: PropTypes.bool
});

_defineProperty(Confirm, "defaultProps", {
  buttonYesStyle: 'primary',
  title: 'TRANSLATE:CONFIRMATION',
  submitText: 'TRANSLATE:YES',
  cancelText: 'TRANSLATE:NO',
  testAutomationId: 'confirm',
  noAutoClose: false,
  shouldDeriveDescFromBody: true
});