// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import classNames from 'classnames';
import Heading from '../Heading';
import Translate from '../Translate';
import empty from './images/default.png';
import filtered from './images/filtered.png';
import { CLS_PREFIX } from '../../constants';
import { ButtonContext, getButtonContextValue } from '../Button/ButtonContext';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const createImage = (baseClassName, image, reason) => {
  if (image === undefined) {
    image = reason === 'filtered' ? filtered : empty;
  }
  let node = image;
  if (typeof image === 'string') {
    node = /*#__PURE__*/_jsx("img", {
      src: image,
      height: "192",
      alt: ""
    });
  }
  return node ? /*#__PURE__*/_jsx("div", {
    className: `${baseClassName}__image`,
    children: node
  }) : null;
};
const createTitle = (baseClassName, title, reason) => {
  if (title === undefined) {
    title = reason === 'filtered' ? /*#__PURE__*/_jsx(Translate, {
      content: "ListEmptyView.filteredTitle",
      fallback: "Could not find any items matching the filter"
    }) : /*#__PURE__*/_jsx(Translate, {
      content: "ListEmptyView.emptyTitle",
      fallback: "Looks like there's nothing here"
    });
  }
  return /*#__PURE__*/_jsx(Heading, {
    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__*/_jsx(Translate, {
      content: "ListEmptyView.filteredDescription",
      fallback: "Refine your query or remove some of the criteria from the filter and try again."
    });
  }
  return /*#__PURE__*/_jsx("div", {
    className: `${baseClassName}__description`,
    children: description
  });
};
const buttonConfig = 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 = `${CLS_PREFIX}list-empty-view`,
    className,
    title,
    image,
    description,
    actions,
    reason,
    ...props
  } = _ref;
  return /*#__PURE__*/_jsxs("div", {
    className: classNames(baseClassName, className),
    ...props,
    children: [createImage(baseClassName, image, reason), /*#__PURE__*/_jsxs("div", {
      className: `${baseClassName}__body`,
      children: [createTitle(baseClassName, title, reason), createDescription(baseClassName, description, reason), actions && /*#__PURE__*/_jsx("div", {
        className: `${baseClassName}__actions`,
        children: /*#__PURE__*/_jsx(ButtonContext.Provider, {
          value: buttonConfig,
          children: actions
        })
      })]
    })]
  });
};
export default ListEmptyView;