function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import TouchFeedback from 'rmc-feedback';
import LottieAnimation from '../lottie-animation';
import Loading from './assets/animation-json/cycle_small_white.json'; // const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
// const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar);
// function isString(str) {
//   return typeof str === 'string';
// }

function insertSpace(child) {
  // if (isString(child.type) && isTwoCNChar(child.props.children)) {
  //   return React.cloneElement(
  //     child,
  //     {},
  //     child.props.children.split('').join(' '),
  //   );
  // }
  // if (isString(child)) {
  //   if (isTwoCNChar(child)) {
  //     child = child.split('').join(' ');
  //   }
  //   return <span>{child}</span>;
  // }
  return child;
} // eslint-disable-next-line react/prefer-stateless-function


var Button =
/*#__PURE__*/
function (_Component) {
  _inherits(Button, _Component);

  function Button() {
    _classCallCheck(this, Button);

    return _possibleConstructorReturn(this, _getPrototypeOf(Button).apply(this, arguments));
  }

  _createClass(Button, [{
    key: "render",
    value: function render() {
      var _classnames;

      var _this$props = this.props,
          children = _this$props.children,
          className = _this$props.className,
          prefixCls = _this$props.prefixCls,
          type = _this$props.type,
          textType = _this$props.textType,
          warningType = _this$props.warningType,
          size = _this$props.size,
          inline = _this$props.inline,
          theme = _this$props.theme,
          disabled = _this$props.disabled,
          icon = _this$props.icon,
          loading = _this$props.loading,
          activeStyle = _this$props.activeStyle,
          activeClassName = _this$props.activeClassName,
          onClick = _this$props.onClick,
          restProps = _objectWithoutProperties(_this$props, ["children", "className", "prefixCls", "type", "textType", "warningType", "size", "inline", "theme", "disabled", "icon", "loading", "activeStyle", "activeClassName", "onClick"]);

      var wrapCls = classnames(prefixCls, className, (_classnames = {}, _defineProperty(_classnames, "".concat(prefixCls, "-default"), type === 'default'), _defineProperty(_classnames, "".concat(prefixCls, "-primary"), type === 'primary'), _defineProperty(_classnames, "".concat(prefixCls, "-candy"), type === 'candy'), _defineProperty(_classnames, "".concat(prefixCls, "-text"), type === 'text'), _defineProperty(_classnames, "".concat(prefixCls, "-warning"), type === 'warning'), _defineProperty(_classnames, "".concat(prefixCls, "-text-vertical"), type === 'text' && textType === 'vertical'), _defineProperty(_classnames, "".concat(prefixCls, "-warning-default"), type === 'warning' && warningType === 'default'), _defineProperty(_classnames, "".concat(prefixCls, "-warning-banner"), type === 'warning' && warningType === 'banner'), _defineProperty(_classnames, "".concat(prefixCls, "-warning-footer"), type === 'warning' && warningType === 'footer'), _defineProperty(_classnames, "".concat(prefixCls, "-small"), size === 'small'), _defineProperty(_classnames, "".concat(prefixCls, "-inline"), inline), _defineProperty(_classnames, "".concat(prefixCls, "-theme"), theme), _defineProperty(_classnames, "".concat(prefixCls, "-disabled"), disabled), _defineProperty(_classnames, "".concat(prefixCls, "-loading"), loading), _classnames));
      var kids = React.Children.map(children, insertSpace);
      var iconEl;

      if (icon) {
        var rawCls = icon.props && icon.props.className;
        var cls = classnames("".concat(prefixCls, "-icon"));
        iconEl = React.cloneElement(icon, {
          className: rawCls ? "".concat(rawCls, " ").concat(cls) : cls
        });
      }

      return React.createElement(TouchFeedback, {
        activeClassName: activeClassName || (activeStyle ? "".concat(prefixCls, "-active") : undefined),
        disabled: disabled,
        activeStyle: activeStyle
      }, React.createElement("a", _extends({
        role: "button",
        tabIndex: 0,
        className: wrapCls
      }, restProps, {
        onClick: disabled || loading ? undefined : onClick,
        "aria-disabled": disabled
      }), loading ? React.createElement(LottieAnimation, {
        animationData: Loading
      }) : React.createElement(React.Fragment, null, iconEl, kids)));
    }
  }]);

  return Button;
}(Component);

_defineProperty(Button, "propTypes", {
  children: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
  prefixCls: PropTypes.string,
  size: PropTypes.string,
  inline: PropTypes.bool,
  theme: PropTypes.bool,
  disabled: PropTypes.bool,
  icon: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
  loading: PropTypes.bool,
  className: PropTypes.string,
  type: PropTypes.string,
  textType: PropTypes.string,
  warningType: PropTypes.string,
  activeStyle: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
  activeClassName: PropTypes.string,
  onClick: PropTypes.func
});

_defineProperty(Button, "defaultProps", {
  prefixCls: 'eh-button',
  size: 'default',
  type: 'default',
  textType: 'default',
  warningType: 'default',
  inline: false,
  theme: true,
  disabled: false,
  loading: false,
  activeStyle: {}
});

export default Button;