import * as _vue from "vue";
import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import { getComponent } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
import WarningFilled from '@ant-design/icons-vue/WarningFilled';
import noFound from './noFound';
import serverError from './serverError';
import unauthorized from './unauthorized';
export var IconMap = {
  success: CheckCircleFilled,
  error: CloseCircleFilled,
  info: ExclamationCircleFilled,
  warning: WarningFilled
};
export var ExceptionMap = {
  '404': noFound,
  '500': serverError,
  '403': unauthorized
}; // ExceptionImageMap keys

var ExceptionStatus = Object.keys(ExceptionMap);
export var ResultProps = {
  prefixCls: PropTypes.string,
  icon: PropTypes.any,
  status: PropTypes.oneOf(['success', 'error', 'info', 'warning', '404', '403', '500']).def('info'),
  title: PropTypes.any,
  subTitle: PropTypes.any,
  extra: PropTypes.any
};

var renderIcon = function renderIcon(prefixCls, _ref) {
  var status = _ref.status,
      icon = _ref.icon;

  if (ExceptionStatus.includes("".concat(status))) {
    var SVGComponent = ExceptionMap[status];
    return _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-icon ").concat(prefixCls, "-image")
    }, [_vue.createVNode(SVGComponent, null, null)]);
  }

  var IconComponent = IconMap[status];

  var iconNode = icon || _vue.createVNode(IconComponent, null, null);

  return _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-icon")
  }, [iconNode]);
};

var renderExtra = function renderExtra(prefixCls, extra) {
  return extra && _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-extra")
  }, [extra]);
};

var Result = {
  name: 'AResult',
  props: ResultProps,
  setup: function setup() {
    return {
      configProvider: inject('configProvider', ConfigConsumerProps)
    };
  },
  render: function render(h) {
    var customizePrefixCls = this.prefixCls,
        status = this.status;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('result', customizePrefixCls);
    var title = getComponent(this, 'title');
    var subTitle = getComponent(this, 'subTitle');
    var icon = getComponent(this, 'icon');
    var extra = getComponent(this, 'extra');
    return _vue.createVNode("div", {
      "class": "".concat(prefixCls, " ").concat(prefixCls, "-").concat(status)
    }, [renderIcon(prefixCls, {
      status: status,
      icon: icon
    }), _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-title")
    }, [title]), subTitle && _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-subtitle")
    }, [subTitle]), this.$slots.default && _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-content")
    }, [this.$slots.default()]), renderExtra(prefixCls, extra)]);
  }
};
/* add resource */

Result.PRESENTED_IMAGE_403 = ExceptionMap[403];
Result.PRESENTED_IMAGE_404 = ExceptionMap[404];
Result.PRESENTED_IMAGE_500 = ExceptionMap[500];
/* istanbul ignore next */

Result.install = function (app) {
  app.component(Result.name, Result);
};

export default Result;