import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { useRef } from 'react';
import classNames from 'classnames';
import Icon from '../icon';
import { ConfigContext } from '../config-provider/context';
var SuccessFill = Icon.SuccessFill,
    InfoFill = Icon.InfoFill,
    ErrorFill = Icon.ErrorFill,
    WarningFill = Icon.WarningFill; // eslint-disable-next-line @typescript-eslint/no-redeclare

var IconMap = {
  success: /*#__PURE__*/React.createElement(SuccessFill, null),
  error: /*#__PURE__*/React.createElement(ErrorFill, null),
  info: /*#__PURE__*/React.createElement(InfoFill, null),
  warning: /*#__PURE__*/React.createElement(WarningFill, null)
};
var ExceptionMap = {
  404: /*#__PURE__*/React.createElement(ErrorFill, null),
  500: /*#__PURE__*/React.createElement(ErrorFill, null),
  403: /*#__PURE__*/React.createElement(ErrorFill, null)
};
var Result = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _React$useContext = React.useContext(ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var resultRef = ref || useRef(null);

  var className = props.className,
      icon = props.icon,
      extra = props.extra,
      status = props.status,
      subTitle = props.subTitle,
      title = props.title,
      otherProps = _objectWithoutProperties(props, ["className", "icon", "extra", "status", "subTitle", "title"]);

  var resultCls = getPrefixClassName('result');
  var endCls = classNames(resultCls, _defineProperty({}, "".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.createElement("div", {
        className: "".concat(resultCls, "-icon")
      }, ExceptionMap[currentStatus]);
    }

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


  var tempNode = function tempNode(name, content) {
    var typeNode = name ? /*#__PURE__*/React.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 = _objectSpread({
    ref: resultRef,
    className: endCls
  }, otherProps);

  return /*#__PURE__*/React.createElement("div", Object.assign({}, comProps), iconNode(), titleNode, subTitleNode, extraNode);
});
Result.displayName = 'Result';
Result.defaultProps = {
  status: 'info'
};
export default Result;