"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _reactNativeWeb = require("react-native-web");

var _propTypes = require("prop-types");

var _styles = require("@vincent_za/styles");

var _utils = require("@vincent_za/utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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 _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 _templateObject() {
  var data = _taggedTemplateLiteral(["\n  position: relative;\n  white-space: nowrap;\n\n  ", ";\n\n  ", ";\n\n  ", ";\n"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

// import { SpinnerLoader } from '../Loader';
// import { ErrorFloat, CN_ERROR_ICON } from '../Error';
var Wrap = (0, _styledComponents.default)(_reactNativeWeb.Text)(_templateObject(), function (props) {
  return props.isFormButton && "\n    display: inline-flex;\n    padding: 0 ".concat(_styles.PX_UNIT_XLG, ";\n    align-items: center;\n    height: 3.6rem;\n    background: ").concat(props.isError ? _styles.SUNSET_ORANGE : '#9BC1BC', ";\n    text-transform: uppercase;\n    border-radius: 1.8rem;\n    color: ").concat(_styles.WHITE, ";\n    font-family: ").concat(_styles.FONT_BOLD, ";\n\n    &:hover {\n      ").concat(!props.isError && "background: ".concat(_styles.STYLE_P_BUTTON_BG_HOVER), ";\n    };\n  ");
}, function (props) {
  return props.isLinkButton && "\n    color: ".concat(_styles.GRAY_X11, ";\n    font-size: ").concat(_styles.PX_UNIT_MD, ";\n    margin-left: ").concat(_styles.PX_UNIT_LG, ";\n    \n    &:hover {\n      color: ").concat(_styles.GAINSBORO, ";\n    };\n  ");
}, function (props) {
  return props.isDisabled && "\n    background: #636363;\n    opacity: 0.5;\n    cursor: not-allowed;\n    pointer-events: none;\n  ";
}); // const ErrorFloatStyled = styled(ErrorFloat)`
//   /* BUG: .${CN_ERROR_ICON} does not work for some reason */
//   .error-icon {
//     margin-left: ${PX_UNIT_SM};
//     fill: ${ISABELLINE};
//   };
// `;
// const SpinnerLoaderStyled = styled(SpinnerLoader)`
//   margin-left: ${PX_UNIT_SM};
//   path {
//     &:nth-child(1) {
//       opacity: 1;
//       fill: rgba(0, 0, 0, 0.2);
//     };
//     &:nth-child(2) {
//       fill: rgba(0, 0, 0, 0.3);
//     };
//   };
// `;

var Button =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(Button, _React$PureComponent);

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

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

  _createClass(Button, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          isDisabled = _this$props.isDisabled,
          isFormButton = _this$props.isFormButton,
          isLinkButton = _this$props.isLinkButton,
          type = _this$props.type,
          tooltipPosition = _this$props.tooltipPosition,
          hasAsyncStatus = _this$props.hasAsyncStatus,
          asyncStatus = _this$props.asyncStatus,
          asyncStatusList = _this$props.asyncStatusList,
          onClick = _this$props.onClick,
          children = _this$props.children,
          className = _this$props.className;

      var _determineAsyncStatus = (0, _utils.determineAsyncStatus)({
        asyncStatus: asyncStatus,
        asyncStatusList: asyncStatusList
      }),
          isError = _determineAsyncStatus.isError;

      return _react.default.createElement(Wrap, {
        isError: isError,
        isFormButton: isFormButton,
        isLinkButton: isLinkButton,
        isDisabled: isDisabled,
        type: type,
        onPress: onClick,
        className: className
      }, children);
    }
  }]);

  return Button;
}(_react.default.PureComponent);

Button.propTypes = {
  className: _propTypes.string,
  children: _propTypes.node.isRequired,
  isFormButton: _propTypes.bool,
  isLinkButton: _propTypes.bool,
  isDisabled: _propTypes.bool,
  tooltipPosition: _propTypes.string,
  hasAsyncStatus: _propTypes.bool,
  asyncStatus: (0, _propTypes.shape)(_utils.PROP_ASYNC_STATUS),
  asyncStatusList: (0, _propTypes.arrayOf)((0, _propTypes.shape)(_utils.PROP_ASYNC_STATUS)),
  type: _propTypes.string,
  onClick: _propTypes.func
};
Button.defaultProps = {
  onClick: function onClick() {},
  className: '',
  isFormButton: false,
  isLinkButton: false,
  isDisabled: false,
  tooltipPosition: 'right',
  hasAsyncStatus: false,
  asyncStatus: _utils.SHAPE_ASYNC_STATUS_INITIAL,
  asyncStatusList: [],
  type: 'submit'
};
var _default = Button;
exports.default = _default;