import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React from 'react';
import classNames from 'classnames';
import Heading from '../Heading';
import Translate from '../Translate';
import empty from './images/default.svg';
import filtered from './images/filtered.svg';
import { CLS_PREFIX } from '../../constants';

const createImage = (baseClassName, image, reason) => {
  if (image === undefined) {
    image = reason === 'filtered' ? filtered : empty;
  }

  let node = image;

  if (typeof image === 'string') {
    node = /*#__PURE__*/React.createElement("img", {
      src: image,
      height: "192",
      alt: ""
    });
  }

  return node ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__image")
  }, node) : null;
};

const createTitle = (baseClassName, title, reason) => {
  if (title === undefined) {
    title = reason === 'filtered' ? /*#__PURE__*/React.createElement(Translate, {
      content: "ListEmptyView.filteredTitle",
      fallback: "Could not find any items matching the filter"
    }) : /*#__PURE__*/React.createElement(Translate, {
      content: "ListEmptyView.emptyTitle",
      fallback: "Looks like there's nothing here"
    });
  }

  return /*#__PURE__*/React.createElement(Heading, {
    level: 3,
    className: "".concat(baseClassName, "__title")
  }, title);
};

const createDescription = (baseClassName, description, reason) => {
  if (description === undefined && !reason) {
    return null;
  }

  if (description === undefined && reason === 'filtered') {
    description = /*#__PURE__*/React.createElement(Translate, {
      content: "ListEmptyView.filteredDescription",
      fallback: "Refine your query or remove some of the criteria from the filter and try again."
    });
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__description")
  }, description);
};
/**
 * `ListEmptyView` component is used for displaying "empty" state of [List](#!/List)
 * when there are no any objects are added to the list.
 * @since 2.5.0
 */


const ListEmptyView = ({
  baseClassName = "".concat(CLS_PREFIX, "list-empty-view"),
  className,
  title,
  image,
  description,
  actions,
  reason,
  ...props
}) => /*#__PURE__*/React.createElement("div", _extends({
  className: classNames(baseClassName, className)
}, props), createImage(baseClassName, image, reason), /*#__PURE__*/React.createElement("div", {
  className: "".concat(baseClassName, "__body")
}, createTitle(baseClassName, title, reason), createDescription(baseClassName, description, reason), actions && /*#__PURE__*/React.createElement("div", {
  className: "".concat(baseClassName, "__actions")
}, actions)));

export default ListEmptyView;