"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _Translate = _interopRequireDefault(require("../Translate"));
var _default2 = _interopRequireDefault(require("./images/default.png"));
var _filtered = _interopRequireDefault(require("./images/filtered.png"));
var _constants = require("../../constants");
var _ButtonContext = require("../Button/ButtonContext");
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. 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__*/(0, _jsxRuntime.jsx)("img", {
      src: image,
      height: "192",
      alt: ""
    });
  }
  return node ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: `${baseClassName}__image`,
    children: node
  }) : null;
};
const createTitle = (baseClassName, title, reason) => {
  if (title === undefined) {
    title = reason === 'filtered' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Translate.default, {
      content: "ListEmptyView.filteredTitle",
      fallback: "Could not find any items matching the filter"
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Translate.default, {
      content: "ListEmptyView.emptyTitle",
      fallback: "Looks like there's nothing here"
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Heading.default, {
    level: 3,
    className: `${baseClassName}__title`,
    children: title
  });
};
const createDescription = (baseClassName, description, reason) => {
  if (description === undefined && !reason) {
    return null;
  }
  if (description === undefined && reason === 'filtered') {
    description = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Translate.default, {
      content: "ListEmptyView.filteredDescription",
      fallback: "Refine your query or remove some of the criteria from the filter and try again."
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: `${baseClassName}__description`,
    children: description
  });
};
const buttonConfig = (0, _ButtonContext.getButtonContextValue)({
  defaultProps: {
    size: 'lg'
  }
});

/**
 * `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 = _ref => {
  let {
    baseClassName = `${_constants.CLS_PREFIX}list-empty-view`,
    className,
    title,
    image,
    description,
    actions,
    reason,
    ...props
  } = _ref;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)(baseClassName, className),
    ...props,
    children: [createImage(baseClassName, image, reason), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: `${baseClassName}__body`,
      children: [createTitle(baseClassName, title, reason), createDescription(baseClassName, description, reason), actions && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${baseClassName}__actions`,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonContext.ButtonContext.Provider, {
          value: buttonConfig,
          children: actions
        })
      })]
    })]
  });
};
var _default = exports.default = ListEmptyView;