"use strict";

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

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

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

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

var _Heading = _interopRequireDefault(require("../Heading"));

var _Translate = _interopRequireDefault(require("../Translate"));

var _default2 = _interopRequireDefault(require("./images/default.svg"));

var _filtered = _interopRequireDefault(require("./images/filtered.svg"));

var _constants = require("../../constants");

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
const createImage = (baseClassName, image, reason) => {
  if (image === undefined) {
    image = reason === 'filtered' ? _filtered.default : _default2.default;
  }

  let node = image;

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

  return node ? /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__image`
  }, node) : null;
};

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

  return /*#__PURE__*/_react.default.createElement(_Heading.default, {
    level: 3,
    className: `${baseClassName}__title`
  }, title);
};

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

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

  return /*#__PURE__*/_react.default.createElement("div", {
    className: `${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 = `${_constants.CLS_PREFIX}list-empty-view`,
  className,
  title,
  image,
  description,
  actions,
  reason,
  ...props
}) => /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
  className: (0, _classnames.default)(baseClassName, className)
}, props), createImage(baseClassName, image, reason), /*#__PURE__*/_react.default.createElement("div", {
  className: `${baseClassName}__body`
}, createTitle(baseClassName, title, reason), createDescription(baseClassName, description, reason), actions && /*#__PURE__*/_react.default.createElement("div", {
  className: `${baseClassName}__actions`
}, actions)));

var _default = ListEmptyView;
exports.default = _default;