"use strict";

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

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

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

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

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

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

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

var _bem = require("@zarm-design/bem");

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

var _configProvider = require("../config-provider");

var _loading = _interopRequireDefault(require("../loading"));

var _hooks = require("../utils/hooks");

var ModalAction = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _ref;

  var className = props.className,
      bold = props.bold,
      theme = props.theme,
      disabled = props.disabled,
      text = props.text,
      onClick = props.onClick,
      rest = (0, _objectWithoutProperties2.default)(props, ["className", "bold", "theme", "disabled", "text", "onClick"]);

  var _useSafeState = (0, _hooks.useSafeState)(false),
      _useSafeState2 = (0, _slicedToArray2.default)(_useSafeState, 2),
      loading = _useSafeState2[0],
      setLoading = _useSafeState2[1];

  var _React$useContext = React.useContext(_configProvider.ConfigContext),
      prefixCls = _React$useContext.prefixCls;

  var bem = (0, _bem.createBEM)('modal', {
    prefixCls: prefixCls
  });
  var cls = bem('button', [(_ref = {}, (0, _defineProperty2.default)(_ref, "".concat(theme), !!theme), (0, _defineProperty2.default)(_ref, "bold", bold), (0, _defineProperty2.default)(_ref, "disabled", disabled || loading), _ref), className]);
  return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({}, rest, {
    ref: ref,
    className: cls,
    onClick: /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
      return _regenerator.default.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              setLoading(true);
              _context.prev = 1;
              _context.next = 4;
              return onClick === null || onClick === void 0 ? void 0 : onClick();

            case 4:
              _context.prev = 4;
              setLoading(false);
              return _context.finish(4);

            case 7:
            case "end":
              return _context.stop();
          }
        }
      }, _callee, null, [[1,, 4, 7]]);
    }))
  }), loading ? /*#__PURE__*/React.createElement(_loading.default, null) : text);
});
var _default = ModalAction;
exports.default = _default;