function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React from 'react';
import PropTypes from 'prop-types';
import isNil from 'lodash/fp/isNil';
import map from 'lodash/fp/map';
import isEmpty from 'lodash/fp/isEmpty';
import ListItem from '../list-item';
import DraggableList from '../../molecule/draggable-list';
import Title from '../../atom/title';
import ButtonLink from '../../atom/button-link';
import SelectMultiple from '../../molecule/select-multiple';
import ExpandibleActionableTable from '../../molecule/expandible-actionable-table';
import Loader from '../../atom/loader';
import Search from '../../atom/input-search';
import CheckboxWithTitle from '../../atom/checkbox-with-title';
import ButtonMenuAction from '../../molecule/button-menu-action';
import style from './style.css';
const buildTitleView = title => {
  if (typeof title === 'string') {
    return /*#__PURE__*/React.createElement(Title, {
      title: title,
      type: "form-group",
      titleSize: "standard-light-weight",
      "data-name": "list-title"
    });
  }
  return /*#__PURE__*/React.createElement(Title, title);
};
const buildListItemsView = (content, ariaLabel, selectMultiple) => {
  const {
    items,
    itemType,
    onDrop,
    isDraggable = false,
    tableHeader
  } = content;
  const itemsView = isDraggable && items.length > 1 ? /*#__PURE__*/React.createElement(DraggableList, {
    items: items.map(item => ({
      ...item,
      contentType: itemType
    })),
    itemType: "list-item",
    onDrop: onDrop
  }) : items.map((item, index) => /*#__PURE__*/React.createElement("li", {
    key: item.id,
    className: style.item,
    "data-name": `content-${index}`
  }, /*#__PURE__*/React.createElement(ListItem, _extends({}, item, {
    order: null,
    contentType: itemType,
    "data-name": `list-item-${index}`
  }))));
  const tableHeaderView = !isNil(tableHeader) && !isEmpty(tableHeader) ? /*#__PURE__*/React.createElement("div", {
    className: style.tableHeaderWrapper
  }, /*#__PURE__*/React.createElement("div", {
    className: style.dataColumnsWrapper
  }, tableHeader.map((tableHeaderItem, index) => /*#__PURE__*/React.createElement("div", {
    key: `tableHeadeColumn-key-${index}`,
    className: style.tableHeaderItem,
    "data-name": `tableHeader-${index}`,
    style: index === 0 ? {
      flexGrow: 2,
      flexShrink: 0,
      flexBasis: 0
    } : {
      flexGrow: 1,
      flexShrink: 0,
      flexBasis: 0
    }
  }, tableHeaderItem))), /*#__PURE__*/React.createElement("div", {
    className: style.settings
  }, '')) : null;
  return /*#__PURE__*/React.createElement("div", null, tableHeaderView, /*#__PURE__*/React.createElement("ul", {
    className: !selectMultiple ? style.list : style.listWithSelectMultiple,
    "aria-label": ariaLabel,
    "data-name": 'content-list'
  }, itemsView));
};
const buildEmptyResultView = emptyResult => {
  const {
    title,
    description,
    button
  } = emptyResult;
  return /*#__PURE__*/React.createElement("div", {
    className: style.emptySearchResultContainer
  }, /*#__PURE__*/React.createElement("div", {
    className: style.emptySearchResultTitle
  }, title), /*#__PURE__*/React.createElement("div", {
    className: style.emptySearchResultDescription
  }, description), /*#__PURE__*/React.createElement("div", {
    className: style.emptySearchResultButton
  }, button?.menu ? /*#__PURE__*/React.createElement(ButtonMenuAction, button) : /*#__PURE__*/React.createElement(ButtonLink, button)));
};
const buildContentView = (content, ariaLabel, selectMultiple) => {
  const {
    type
  } = content;
  if (type === 'list' && isEmpty(content.items) && content.emptyResult) {
    return buildEmptyResultView(content.emptyResult);
  }
  switch (type) {
    case 'list':
      return buildListItemsView(content, ariaLabel, selectMultiple);
    case 'expandible-actionable-table':
      return /*#__PURE__*/React.createElement(ExpandibleActionableTable, content);
  }
};
const ListItems = ({
  title,
  buttonLink,
  selectMultiple,
  content,
  'aria-label': ariaLabel,
  isFetching,
  search,
  checkboxWithTitle,
  actionButtons,
  buttonMenuAction
}) => {
  const contentView = buildContentView(content, ariaLabel, selectMultiple);
  const titleView = buildTitleView(title);
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: style.header
  }, checkboxWithTitle ? /*#__PURE__*/React.createElement("div", {
    className: style.checkboxAndActionsWrapper
  }, /*#__PURE__*/React.createElement(CheckboxWithTitle, _extends({}, checkboxWithTitle, {
    title: checkboxWithTitle.title
  })), actionButtons ? map.convert({
    cap: false
  })((action, index) => /*#__PURE__*/React.createElement(ButtonLink, _extends({}, action, {
    key: `action-button-key-${index}`
  })), actionButtons) : null) : /*#__PURE__*/React.createElement("div", {
    className: style.title
  }, titleView), /*#__PURE__*/React.createElement("div", {
    className: style.inputWrapper
  }, !isEmpty(search) ? /*#__PURE__*/React.createElement(Search, search) : null, /*#__PURE__*/React.createElement("div", {
    className: style.actionsWrapper
  }, !isEmpty(selectMultiple) ? /*#__PURE__*/React.createElement("div", {
    className: style.selectMultiple
  }, /*#__PURE__*/React.createElement(SelectMultiple, selectMultiple)) : null, !isEmpty(buttonLink) ? /*#__PURE__*/React.createElement(ButtonLink, buttonLink) : null), buttonMenuAction ? /*#__PURE__*/React.createElement(ButtonMenuAction, buttonMenuAction) : null)), isFetching ? /*#__PURE__*/React.createElement("div", {
    className: style.loaderContainer
  }, /*#__PURE__*/React.createElement(Loader, {
    className: style.loader,
    theme: "coorpmanager"
  })) : contentView);
};
ListItems.propTypes = process.env.NODE_ENV !== "production" ? {
  'aria-label': PropTypes.string,
  buttonLink: PropTypes.shape(ButtonLink.propTypes),
  selectMultiple: PropTypes.shape(SelectMultiple.propTypes),
  content: PropTypes.oneOfType([PropTypes.shape({
    items: PropTypes.arrayOf(PropTypes.shape(ListItem.propTypes)),
    type: PropTypes.oneOf(['list']),
    itemType: PropTypes.string,
    onDrop: PropTypes.func,
    isDraggable: PropTypes.bool,
    tableHeader: PropTypes.arrayOf(PropTypes.string),
    emptyResult: PropTypes.shape({
      title: PropTypes.string,
      description: PropTypes.string,
      button: PropTypes.oneOfType([PropTypes.shape(ButtonLink.propTypes), PropTypes.shape(ButtonMenuAction.propTypes)])
    })
  }), PropTypes.shape({
    ...ExpandibleActionableTable.propTypes,
    type: PropTypes.oneOf(['expandible-actionable-table'])
  })]),
  title: PropTypes.oneOfType([PropTypes.string, PropTypes.shape(Title.propTypes)]),
  isFetching: PropTypes.bool,
  search: PropTypes.shape(Search.propTypes),
  checkboxWithTitle: PropTypes.shape(CheckboxWithTitle.propTypes),
  actionButtons: PropTypes.arrayOf(PropTypes.shape(ButtonLink.propTypes)),
  buttonMenuAction: PropTypes.shape(ButtonMenuAction.propTypes)
} : {};
export default ListItems;
//# sourceMappingURL=index.js.map