import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { isValidElement, useContext } from 'react';
import clsx from 'clsx';
import { getSizeStyle } from '../utils';
import { Network } from './Network';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
const PRESET_IMAGES = ['error', 'search', 'default'];

const Empty = props => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace('empty', prefixCls);

  const renderImage = () => {
    let {
      image
    } = props;

    if (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 _jsx("img", {
      src: image,
      alt: ""
    });
  };

  const renderDescription = () => {
    if (props.description) {
      return _jsx("div", Object.assign({
        className: clsx(bem('description'))
      }, {
        children: props.description
      }));
    }

    return null;
  };

  const renderBottom = () => {
    if (props.children) {
      return _jsx("div", Object.assign({
        className: clsx(bem('bottom'))
      }, {
        children: props.children
      }));
    }

    return null;
  };

  return _jsxs("div", Object.assign({
    className: clsx(props.className, bem()),
    style: props.style
  }, {
    children: [_jsx("div", Object.assign({
      className: clsx(bem('image')),
      style: getSizeStyle(props.imageSize)
    }, {
      children: renderImage()
    })), renderDescription(), renderBottom()]
  }));
};

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