import React, { isValidElement, useContext } from 'react';
import clsx from 'clsx';
import { getSizeStyle } from '../utils';
import { Network } from './Network';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
var PRESET_IMAGES = ['error', 'search', 'default'];

var Empty = function Empty(props) {
  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('empty', prefixCls),
      bem = _createNamespace[0];

  var renderImage = function renderImage() {
    var image = props.image;

    if ( /*#__PURE__*/isValidElement(image)) {
      return image;
    }

    if (image === 'network') {
      return Network;
    }

    if (PRESET_IMAGES.includes(image)) {
      image = "https://img.yzcdn.cn/vant/empty-image-" + image + ".png";
    }

    return /*#__PURE__*/React.createElement("img", {
      src: image,
      alt: ""
    });
  };

  var renderDescription = function renderDescription() {
    if (props.description) {
      return /*#__PURE__*/React.createElement("div", {
        className: clsx(bem('description'))
      }, props.description);
    }

    return null;
  };

  var renderBottom = function renderBottom() {
    if (props.children) {
      return /*#__PURE__*/React.createElement("div", {
        className: clsx(bem('bottom'))
      }, props.children);
    }

    return null;
  };

  return /*#__PURE__*/React.createElement("div", {
    className: clsx(props.className, bem()),
    style: props.style
  }, /*#__PURE__*/React.createElement("div", {
    className: clsx(bem('image')),
    style: getSizeStyle(props.imageSize)
  }, renderImage()), renderDescription(), renderBottom());
};

Empty.defaultProps = {
  image: 'default'
};
export default Empty;