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

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

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

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

var _button = _interopRequireDefault(require("../button"));

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

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

var SwipeActionItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var className = props.className,
      text = props.text,
      onClick = props.onClick,
      _props$theme = props.theme,
      theme = _props$theme === void 0 ? 'primary' : _props$theme,
      rest = (0, _objectWithoutProperties2.default)(props, ["className", "text", "onClick", "theme"]);

  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)('swipe-action-item', {
    prefixCls: prefixCls
  });
  var cls = bem('item', [className]);
  return /*#__PURE__*/React.createElement(_button.default, (0, _extends2.default)({}, rest, {
    className: cls,
    ref: ref,
    shape: "rect",
    size: "md",
    theme: theme,
    loading: loading,
    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 ? null : text);
});
var _default = SwipeActionItem;
exports.default = _default;