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

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

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _icon = _interopRequireDefault(require("../icon"));

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

var SuccessFill = _icon.default.SuccessFill,
    InfoFill = _icon.default.InfoFill,
    ErrorFill = _icon.default.ErrorFill,
    WarningFill = _icon.default.WarningFill; // eslint-disable-next-line @typescript-eslint/no-redeclare

var IconMap = {
  success: /*#__PURE__*/_react.default.createElement(SuccessFill, null),
  error: /*#__PURE__*/_react.default.createElement(ErrorFill, null),
  info: /*#__PURE__*/_react.default.createElement(InfoFill, null),
  warning: /*#__PURE__*/_react.default.createElement(WarningFill, null)
};
var ExceptionMap = {
  404: /*#__PURE__*/_react.default.createElement(ErrorFill, null),
  500: /*#__PURE__*/_react.default.createElement(ErrorFill, null),
  403: /*#__PURE__*/_react.default.createElement(ErrorFill, null)
};

var Result = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var resultRef = ref || (0, _react.useRef)(null);
  var className = props.className,
      icon = props.icon,
      extra = props.extra,
      status = props.status,
      subTitle = props.subTitle,
      title = props.title,
      otherProps = (0, _objectWithoutProperties2.default)(props, ["className", "icon", "extra", "status", "subTitle", "title"]);
  var resultCls = getPrefixClassName('result');
  var endCls = (0, _classnames.default)(resultCls, (0, _defineProperty2.default)({}, "".concat(resultCls, "-").concat(status), status), className);
  var ExceptionStatus = Object.keys(ExceptionMap); // icon node

  var iconNode = function iconNode() {
    var currentStatus = !status ? 'info' : status;

    if (ExceptionStatus.includes(''.concat(currentStatus.toString()))) {
      return /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(resultCls, "-icon")
      }, ExceptionMap[currentStatus]);
    }

    return /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(resultCls, "-icon")
    }, icon || IconMap[currentStatus]);
  }; // normal node


  var tempNode = function tempNode(name, content) {
    var typeNode = name ? /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(resultCls, "-").concat(name)
    }, content) : null;
    return typeNode;
  };

  var titleNode = tempNode('title', title);
  var subTitleNode = tempNode('subTitle', subTitle);
  var extraNode = tempNode('extra', extra);
  var comProps = (0, _objectSpread2.default)({
    ref: resultRef,
    className: endCls
  }, otherProps);
  return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, comProps), iconNode(), titleNode, subTitleNode, extraNode);
});

Result.displayName = 'Result';
Result.defaultProps = {
  status: 'info'
};
var _default = Result;
exports.default = _default;