import _extends from "@babel/runtime/helpers/extends";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import { createBEM } from '@zarm-design/bem';
import Button from '../button';
import { useSafeState } from '../utils/hooks';
import { ConfigContext } from '../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 = _objectWithoutProperties(props, ["className", "text", "onClick", "theme"]);

  var _useSafeState = useSafeState(false),
      _useSafeState2 = _slicedToArray(_useSafeState, 2),
      loading = _useSafeState2[0],
      setLoading = _useSafeState2[1];

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

  var bem = createBEM('swipe-action-item', {
    prefixCls: prefixCls
  });
  var cls = bem('item', [className]);
  return /*#__PURE__*/React.createElement(Button, _extends({}, rest, {
    className: cls,
    ref: ref,
    shape: "rect",
    size: "md",
    theme: theme,
    loading: loading,
    onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      return _regeneratorRuntime.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);
});
export default SwipeActionItem;