"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

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

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

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

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

var _isObject = _interopRequireDefault(require("lodash/isObject"));

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

var _noFound = _interopRequireDefault(require("./noFound"));

var _serverError = _interopRequireDefault(require("./serverError"));

var _unauthorized = _interopRequireDefault(require("./unauthorized"));

var _warning = _interopRequireDefault(require("../_util/warning"));

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var renderStatus = function renderStatus(prefixCls, _ref, resultStatusRenderer) {
  var status = _ref.status,
      icon = _ref.icon,
      statusRenderer = _ref.statusRenderer;
  var className = (0, _classnames["default"])("".concat(prefixCls, "-icon"));
  (0, _warning["default"])(!(typeof icon === 'string' && icon.length > 2), "`icon` is using ReactNode instead of string naming . Please check `".concat(icon, "` at https://choerodon.github.io/choerodon-ui/zh/cmp/general/icon")); // 初始化map

  var iconMap = new Map([['403', /*#__PURE__*/_react["default"].createElement(_unauthorized["default"], {
    key: "403"
  })], ['404', /*#__PURE__*/_react["default"].createElement(_noFound["default"], {
    key: "404"
  })], ['500', /*#__PURE__*/_react["default"].createElement(_serverError["default"], {
    key: "500"
  })], ['success', /*#__PURE__*/_react["default"].createElement(_icon["default"], {
    key: "success",
    type: "check_circle"
  })], ['error', /*#__PURE__*/_react["default"].createElement(_icon["default"], {
    key: "error",
    type: "error"
  })], ['info', /*#__PURE__*/_react["default"].createElement(_icon["default"], {
    key: "info",
    type: "info"
  })], ['warning', /*#__PURE__*/_react["default"].createElement(_icon["default"], {
    key: "warning",
    type: "warning"
  })]]); // 注入全局的config

  var statusRendererAll = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, resultStatusRenderer), statusRenderer);

  if ((0, _isObject["default"])(statusRendererAll)) {
    if (Object.keys(statusRendererAll).length > 0) {
      Object.keys(statusRendererAll).forEach(function (item) {
        iconMap.set(item, statusRendererAll[item]);
      });
    }
  }

  var statusIcon = iconMap.get(String(status));

  if (statusIcon && statusIcon.type !== _icon["default"]) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(className, " ").concat(prefixCls, "-image"),
      style: icon || statusRenderer ? {} : "".concat(status) === '500' ? {
        width: 400
      } : {
        width: 800
      }
    }, icon || statusIcon);
  }

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(className)
  }, icon || statusIcon);
};

var renderExtra = function renderExtra(prefixCls, _ref2) {
  var extra = _ref2.extra;
  return extra && /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-extra")
  }, extra);
};

var Result = function Result(props) {
  var customizePrefixCls = props.prefixCls,
      customizeClassName = props.className,
      subTitle = props.subTitle,
      title = props.title,
      style = props.style,
      children = props.children,
      status = props.status;

  var _useContext = (0, _react.useContext)(_ConfigContext["default"]),
      getPrefixCls = _useContext.getPrefixCls,
      getConfig = _useContext.getConfig;

  var prefixCls = getPrefixCls('result', customizePrefixCls);
  var className = (0, _classnames["default"])(prefixCls, "".concat(prefixCls, "-").concat(status), customizeClassName);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: className,
    style: style
  }, renderStatus(prefixCls, props, getConfig('resultStatusRenderer')), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-title")
  }, title), subTitle && /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, subTitle), children && /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-content")
  }, children), renderExtra(prefixCls, props));
};

Result.defaultProps = {
  status: 'info'
};
var _default = Result;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
