import _extends from '@babel/runtime/helpers/extends';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import memoize from '../../node_modules/lodash-es/memoize.js';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/es.regexp.exec.js';
import 'core-js/modules/es.string.search.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import React__default, { forwardRef, useMemo } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { settings } from '../../constants/Settings.js';
import SimplePagination, { SimplePaginationPropTypes } from '../SimplePagination/SimplePagination.js';
import { EditingStyle, DragAndDrop } from '../../utils/DragAndDropUtils.js';
import { OverridePropTypes } from '../../constants/SharedPropTypes.js';
import DefaultListHeader from './ListHeader/ListHeader.js';
import DefaultListContent from './ListContent/ListContent.js';
import VirtualListContent from './VirtualListContent/VirtualListContent.js';
import { ListItemPropTypes } from './ListPropTypes.js';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var iotPrefix = settings.iotPrefix;
var propTypes = {
  /** Specify an optional className to be applied to the container */
  className: PropTypes.string,
  /** list title */
  title: PropTypes.string,
  /** search bar call back function and search value */
  search: PropTypes.shape({
    onChange: PropTypes.func,
    value: PropTypes.string,
    id: PropTypes.string,
    /** should search be trigger onChange (true) or only on Enter/Blur (false) */
    hasFastSearch: PropTypes.bool
  }),
  /** action buttons on right side of list title */
  buttons: PropTypes.arrayOf(PropTypes.node),
  /** Node to override the default header or content */
  overrides: PropTypes.shape({
    header: OverridePropTypes,
    content: OverridePropTypes
  }),
  /** ids of selectable rows with indeterminate selection state */
  indeterminateIds: PropTypes.arrayOf(PropTypes.string),
  /** data source of list items */
  items: PropTypes.arrayOf(PropTypes.shape(ListItemPropTypes)),
  /** list editing style for Drag and Drop */
  editingStyle: PropTypes.oneOf([EditingStyle.Single, EditingStyle.Multiple, EditingStyle.SingleNesting, EditingStyle.MultipleNesting]),
  /** if true shows empty search state, instead of empty state, when there are no search results */
  isFiltering: PropTypes.bool,
  /** use full height in list */
  isFullHeight: PropTypes.bool,
  /** use large/fat row in list */
  isLargeRow: PropTypes.bool,
  /** optional skeleton to be rendered while loading data */
  isLoading: PropTypes.bool,
  /** true if the list should have multiple selectable rows using checkboxes */
  isCheckboxMultiSelect: PropTypes.bool,
  /** optional prop to use a virtualized version of the list instead of rendering all items */
  isVirtualList: PropTypes.bool,
  /** icon can be left or right side of list row primary value */
  iconPosition: PropTypes.oneOf(['left', 'right']),
  /** i18n strings */
  i18n: PropTypes.shape({
    searchPlaceHolderText: PropTypes.string,
    clearSearchIconDescription: PropTypes.string,
    expand: PropTypes.string,
    close: PropTypes.string,
    loadMore: PropTypes.string
  }),
  /** the ids of locked items that cannot be reordered */
  lockedIds: PropTypes.arrayOf(PropTypes.string),
  /** Multiple currently selected items */
  selectedIds: PropTypes.arrayOf(PropTypes.string),
  /** pagination at the bottom of list */
  pagination: PropTypes.shape(SimplePaginationPropTypes),
  /** ids of row expanded */
  expandedIds: PropTypes.arrayOf(PropTypes.string),
  /** callback used to limit which items that should get drop targets rendered.
   * Receives the id of the item that is being dragged and should return a list of allowed ids.
   * Returning an empty list will result in 0 drop targets but returning null will
   * enable all items as drop targets */
  getAllowedDropIds: PropTypes.func,
  /** call back function of select */
  handleSelect: PropTypes.func,
  /** call back function of expansion */
  toggleExpansion: PropTypes.func,
  /** callback function for reorder */
  onItemMoved: PropTypes.func,
  /** callback function when reorder will occur - can cancel the move by returning false */
  itemWillMove: PropTypes.func,
  /** content shown if list is empty */
  emptyState: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
  /** content shown if list is empty on search */
  emptySearchState: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
  testId: PropTypes.string,
  /** call back function for when load more row is clicked  (rowId) => {} */
  handleLoadMore: PropTypes.func,
  /** RowIds for rows currently loading more child rows */
  loadingMoreIds: PropTypes.arrayOf(PropTypes.string),
  /** called after the row has expanded or collapsed and is passed the array of expanded ids */
  onExpandedChange: PropTypes.func,
  /** enables horizontal scrollbar to appear if content is wider then container */
  enableHorizontalScrollbar: PropTypes.bool
};
var defaultProps = {
  className: null,
  title: null,
  search: null,
  buttons: [],
  editingStyle: null,
  getAllowedDropIds: null,
  overrides: null,
  indeterminateIds: [],
  isFiltering: false,
  isFullHeight: false,
  isLargeRow: false,
  isLoading: false,
  isCheckboxMultiSelect: false,
  isVirtualList: false,
  i18n: {
    searchPlaceHolderText: 'Enter a value',
    expand: 'Expand',
    close: 'Close',
    loadMore: 'View more'
  },
  iconPosition: 'left',
  lockedIds: [],
  pagination: null,
  selectedIds: [],
  expandedIds: [],
  loadingMoreIds: [],
  items: [],
  handleSelect: function handleSelect() {},
  toggleExpansion: function toggleExpansion() {},
  onItemMoved: function onItemMoved() {},
  itemWillMove: function itemWillMove() {
    return true;
  },
  emptyState: 'No list items to show',
  emptySearchState: 'No results found',
  testId: 'list',
  handleLoadMore: function handleLoadMore() {},
  onExpandedChange: null,
  enableHorizontalScrollbar: false
};
var List = /*#__PURE__*/forwardRef(function (props, ref) {
  var _overrides$header, _overrides$content, _overrides$header2, _overrides$header3, _overrides$content2;
  // Destructuring this way is needed to retain the propTypes and defaultProps
  var className = props.className,
    title = props.title,
    search = props.search,
    buttons = props.buttons,
    items = props.items,
    isFullHeight = props.isFullHeight,
    i18n = props.i18n,
    lockedIds = props.lockedIds,
    pagination = props.pagination,
    selectedIds = props.selectedIds,
    expandedIds = props.expandedIds,
    getAllowedDropIds = props.getAllowedDropIds,
    handleSelect = props.handleSelect,
    overrides = props.overrides,
    toggleExpansion = props.toggleExpansion,
    iconPosition = props.iconPosition,
    editingStyle = props.editingStyle,
    indeterminateIds = props.indeterminateIds,
    isLargeRow = props.isLargeRow,
    isLoading = props.isLoading,
    isFiltering = props.isFiltering,
    isCheckboxMultiSelect = props.isCheckboxMultiSelect,
    isVirtualList = props.isVirtualList,
    onItemMoved = props.onItemMoved,
    itemWillMove = props.itemWillMove,
    emptyState = props.emptyState,
    emptySearchState = props.emptySearchState,
    testId = props.testId,
    handleLoadMore = props.handleLoadMore,
    loadingMoreIds = props.loadingMoreIds,
    onExpandedChange = props.onExpandedChange,
    enableHorizontalScrollbar = props.enableHorizontalScrollbar;
  var mergedI18n = useMemo(function () {
    return _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  }, [i18n]);
  var ListHeader = (overrides === null || overrides === void 0 || (_overrides$header = overrides.header) === null || _overrides$header === void 0 ? void 0 : _overrides$header.component) || DefaultListHeader;
  var ListContent = overrides !== null && overrides !== void 0 && (_overrides$content = overrides.content) !== null && _overrides$content !== void 0 && _overrides$content.component || isVirtualList ? VirtualListContent : DefaultListContent;
  // getAllowedDropIds will be called by all list items when a drag is initiated and the
  // parameter (id of the dragged item) will be the same until a new drag starts.
  var memoizedGetAllowedDropIds = getAllowedDropIds ? memoize(getAllowedDropIds) : null;
  return /*#__PURE__*/React__default.createElement(DragAndDrop, null, /*#__PURE__*/React__default.createElement("div", {
    "data-testid": testId,
    className: classnames("".concat(iotPrefix, "--list"), className, _defineProperty(_defineProperty({}, "".concat(iotPrefix, "--list__full-height"), isFullHeight), "".concat(iotPrefix, "--list--virtual"), isVirtualList))
  }, /*#__PURE__*/React__default.createElement(ListHeader, _extends({
    className: classnames("".concat(iotPrefix, "--list--header"), overrides === null || overrides === void 0 || (_overrides$header2 = overrides.header) === null || _overrides$header2 === void 0 || (_overrides$header2 = _overrides$header2.props) === null || _overrides$header2 === void 0 ? void 0 : _overrides$header2.className),
    title: title,
    buttons: buttons,
    search: search,
    i18n: mergedI18n,
    testId: "".concat(testId, "-header")
  }, overrides === null || overrides === void 0 || (_overrides$header3 = overrides.header) === null || _overrides$header3 === void 0 ? void 0 : _overrides$header3.props)), /*#__PURE__*/React__default.createElement(ListContent, _extends({
    emptyState: emptyState,
    emptySearchState: emptySearchState,
    items: items,
    isFullHeight: isFullHeight,
    testId: testId,
    indeterminateIds: indeterminateIds,
    isFiltering: isFiltering,
    isLoading: isLoading,
    isCheckboxMultiSelect: isCheckboxMultiSelect,
    selectedIds: selectedIds,
    expandedIds: expandedIds,
    getAllowedDropIds: memoizedGetAllowedDropIds,
    handleSelect: handleSelect,
    toggleExpansion: toggleExpansion,
    iconPosition: iconPosition,
    editingStyle: editingStyle,
    isLargeRow: isLargeRow,
    onItemMoved: onItemMoved,
    itemWillMove: itemWillMove,
    handleLoadMore: handleLoadMore,
    loadingMoreIds: loadingMoreIds,
    selectedItemRef: ref,
    i18n: mergedI18n,
    lockedIds: lockedIds,
    onExpandedChange: onExpandedChange,
    enableHorizontalScrollbar: enableHorizontalScrollbar
  }, overrides === null || overrides === void 0 || (_overrides$content2 = overrides.content) === null || _overrides$content2 === void 0 ? void 0 : _overrides$content2.props)), pagination && !isLoading ? /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "--list--page")
  }, /*#__PURE__*/React__default.createElement(SimplePagination, _extends({}, pagination, {
    size: "md"
  }))) : null));
});
List.displayName = 'List';
List.propTypes = propTypes;
List.defaultProps = defaultProps;
List.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "List",
  "props": {
    "className": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Specify an optional className to be applied to the container",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "title": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "list title",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "search": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "search bar call back function and search value",
      "type": {
        "name": "shape",
        "value": {
          "onChange": {
            "name": "func",
            "required": false
          },
          "value": {
            "name": "string",
            "required": false
          },
          "id": {
            "name": "string",
            "required": false
          },
          "hasFastSearch": {
            "name": "bool",
            "description": "should search be trigger onChange (true) or only on Enter/Blur (false)",
            "required": false
          }
        }
      },
      "required": false
    },
    "buttons": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "action buttons on right side of list title",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "node"
        }
      },
      "required": false
    },
    "editingStyle": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "list editing style for Drag and Drop",
      "type": {
        "name": "enum",
        "value": [{
          "value": "EditingStyle.Single",
          "computed": true
        }, {
          "value": "EditingStyle.Multiple",
          "computed": true
        }, {
          "value": "EditingStyle.SingleNesting",
          "computed": true
        }, {
          "value": "EditingStyle.MultipleNesting",
          "computed": true
        }]
      },
      "required": false
    },
    "getAllowedDropIds": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "callback used to limit which items that should get drop targets rendered.\nReceives the id of the item that is being dragged and should return a list of allowed ids.\nReturning an empty list will result in 0 drop targets but returning null will\nenable all items as drop targets",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "overrides": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Node to override the default header or content",
      "type": {
        "name": "shape",
        "value": {
          "header": {
            "name": "custom",
            "raw": "OverridePropTypes",
            "required": false
          },
          "content": {
            "name": "custom",
            "raw": "OverridePropTypes",
            "required": false
          }
        }
      },
      "required": false
    },
    "indeterminateIds": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "ids of selectable rows with indeterminate selection state",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "isFiltering": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "if true shows empty search state, instead of empty state, when there are no search results",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isFullHeight": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "use full height in list",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isLargeRow": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "use large/fat row in list",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isLoading": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "optional skeleton to be rendered while loading data",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isCheckboxMultiSelect": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "true if the list should have multiple selectable rows using checkboxes",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isVirtualList": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "optional prop to use a virtualized version of the list instead of rendering all items",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  searchPlaceHolderText: 'Enter a value',\n  expand: 'Expand',\n  close: 'Close',\n  loadMore: 'View more',\n}",
        "computed": false
      },
      "description": "i18n strings",
      "type": {
        "name": "shape",
        "value": {
          "searchPlaceHolderText": {
            "name": "string",
            "required": false
          },
          "clearSearchIconDescription": {
            "name": "string",
            "required": false
          },
          "expand": {
            "name": "string",
            "required": false
          },
          "close": {
            "name": "string",
            "required": false
          },
          "loadMore": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "iconPosition": {
      "defaultValue": {
        "value": "'left'",
        "computed": false
      },
      "description": "icon can be left or right side of list row primary value",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'left'",
          "computed": false
        }, {
          "value": "'right'",
          "computed": false
        }]
      },
      "required": false
    },
    "lockedIds": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "the ids of locked items that cannot be reordered",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "pagination": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "pagination at the bottom of list",
      "type": {
        "name": "shape",
        "value": "import SimplePagination, { SimplePaginationPropTypes } from '../SimplePagination/SimplePagination';",
        "computed": true
      },
      "required": false
    },
    "selectedIds": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Multiple currently selected items",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "expandedIds": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "ids of row expanded",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "loadingMoreIds": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "RowIds for rows currently loading more child rows",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "items": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "data source of list items",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": "import { ListItemPropTypes } from './ListPropTypes';",
          "computed": true
        }
      },
      "required": false
    },
    "handleSelect": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "call back function of select",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "toggleExpansion": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "call back function of expansion",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onItemMoved": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "callback function for reorder",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "itemWillMove": {
      "defaultValue": {
        "value": "() => {\n  return true;\n}",
        "computed": false
      },
      "description": "callback function when reorder will occur - can cancel the move by returning false",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "emptyState": {
      "defaultValue": {
        "value": "'No list items to show'",
        "computed": false
      },
      "description": "content shown if list is empty",
      "type": {
        "name": "union",
        "value": [{
          "name": "node"
        }, {
          "name": "string"
        }]
      },
      "required": false
    },
    "emptySearchState": {
      "defaultValue": {
        "value": "'No results found'",
        "computed": false
      },
      "description": "content shown if list is empty on search",
      "type": {
        "name": "union",
        "value": [{
          "name": "node"
        }, {
          "name": "string"
        }]
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'list'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "handleLoadMore": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "call back function for when load more row is clicked  (rowId) => {}",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onExpandedChange": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "called after the row has expanded or collapsed and is passed the array of expanded ids",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "enableHorizontalScrollbar": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "enables horizontal scrollbar to appear if content is wider then container",
      "type": {
        "name": "bool"
      },
      "required": false
    }
  }
};
var List$1 = List;

export { List as UnconnectedList, List$1 as default };
