'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var memoize = require('../../node_modules/lodash-es/memoize.js');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/es.regexp.exec.js');
require('core-js/modules/es.string.search.js');
require('core-js/modules/web.dom-collections.for-each.js');
var React = require('react');
var PropTypes = require('prop-types');
var classnames = require('classnames');
var Settings = require('../../constants/Settings.js');
var SimplePagination = require('../SimplePagination/SimplePagination.js');
var DragAndDropUtils = require('../../utils/DragAndDropUtils.js');
var SharedPropTypes = require('../../constants/SharedPropTypes.js');
var ListHeader = require('./ListHeader/ListHeader.js');
var ListContent = require('./ListContent/ListContent.js');
var VirtualListContent = require('./VirtualListContent/VirtualListContent.js');
var ListPropTypes = require('./ListPropTypes.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

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__default.default(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.settings.iotPrefix;
var propTypes = {
  /** Specify an optional className to be applied to the container */
  className: PropTypes__default.default.string,
  /** list title */
  title: PropTypes__default.default.string,
  /** search bar call back function and search value */
  search: PropTypes__default.default.shape({
    onChange: PropTypes__default.default.func,
    value: PropTypes__default.default.string,
    id: PropTypes__default.default.string,
    /** should search be trigger onChange (true) or only on Enter/Blur (false) */
    hasFastSearch: PropTypes__default.default.bool
  }),
  /** action buttons on right side of list title */
  buttons: PropTypes__default.default.arrayOf(PropTypes__default.default.node),
  /** Node to override the default header or content */
  overrides: PropTypes__default.default.shape({
    header: SharedPropTypes.OverridePropTypes,
    content: SharedPropTypes.OverridePropTypes
  }),
  /** ids of selectable rows with indeterminate selection state */
  indeterminateIds: PropTypes__default.default.arrayOf(PropTypes__default.default.string),
  /** data source of list items */
  items: PropTypes__default.default.arrayOf(PropTypes__default.default.shape(ListPropTypes.ListItemPropTypes)),
  /** list editing style for Drag and Drop */
  editingStyle: PropTypes__default.default.oneOf([DragAndDropUtils.EditingStyle.Single, DragAndDropUtils.EditingStyle.Multiple, DragAndDropUtils.EditingStyle.SingleNesting, DragAndDropUtils.EditingStyle.MultipleNesting]),
  /** if true shows empty search state, instead of empty state, when there are no search results */
  isFiltering: PropTypes__default.default.bool,
  /** use full height in list */
  isFullHeight: PropTypes__default.default.bool,
  /** use large/fat row in list */
  isLargeRow: PropTypes__default.default.bool,
  /** optional skeleton to be rendered while loading data */
  isLoading: PropTypes__default.default.bool,
  /** true if the list should have multiple selectable rows using checkboxes */
  isCheckboxMultiSelect: PropTypes__default.default.bool,
  /** optional prop to use a virtualized version of the list instead of rendering all items */
  isVirtualList: PropTypes__default.default.bool,
  /** icon can be left or right side of list row primary value */
  iconPosition: PropTypes__default.default.oneOf(['left', 'right']),
  /** i18n strings */
  i18n: PropTypes__default.default.shape({
    searchPlaceHolderText: PropTypes__default.default.string,
    clearSearchIconDescription: PropTypes__default.default.string,
    expand: PropTypes__default.default.string,
    close: PropTypes__default.default.string,
    loadMore: PropTypes__default.default.string
  }),
  /** the ids of locked items that cannot be reordered */
  lockedIds: PropTypes__default.default.arrayOf(PropTypes__default.default.string),
  /** Multiple currently selected items */
  selectedIds: PropTypes__default.default.arrayOf(PropTypes__default.default.string),
  /** pagination at the bottom of list */
  pagination: PropTypes__default.default.shape(SimplePagination.SimplePaginationPropTypes),
  /** ids of row expanded */
  expandedIds: PropTypes__default.default.arrayOf(PropTypes__default.default.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__default.default.func,
  /** call back function of select */
  handleSelect: PropTypes__default.default.func,
  /** call back function of expansion */
  toggleExpansion: PropTypes__default.default.func,
  /** callback function for reorder */
  onItemMoved: PropTypes__default.default.func,
  /** callback function when reorder will occur - can cancel the move by returning false */
  itemWillMove: PropTypes__default.default.func,
  /** content shown if list is empty */
  emptyState: PropTypes__default.default.oneOfType([PropTypes__default.default.node, PropTypes__default.default.string]),
  /** content shown if list is empty on search */
  emptySearchState: PropTypes__default.default.oneOfType([PropTypes__default.default.node, PropTypes__default.default.string]),
  testId: PropTypes__default.default.string,
  /** call back function for when load more row is clicked  (rowId) => {} */
  handleLoadMore: PropTypes__default.default.func,
  /** RowIds for rows currently loading more child rows */
  loadingMoreIds: PropTypes__default.default.arrayOf(PropTypes__default.default.string),
  /** called after the row has expanded or collapsed and is passed the array of expanded ids */
  onExpandedChange: PropTypes__default.default.func,
  /** enables horizontal scrollbar to appear if content is wider then container */
  enableHorizontalScrollbar: PropTypes__default.default.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__*/React.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 = React.useMemo(function () {
    return _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  }, [i18n]);
  var ListHeader$1 = (overrides === null || overrides === void 0 || (_overrides$header = overrides.header) === null || _overrides$header === void 0 ? void 0 : _overrides$header.component) || ListHeader;
  var ListContent$1 = overrides !== null && overrides !== void 0 && (_overrides$content = overrides.content) !== null && _overrides$content !== void 0 && _overrides$content.component || isVirtualList ? VirtualListContent : ListContent;
  // 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.default.createElement(DragAndDropUtils.DragAndDrop, null, /*#__PURE__*/React__default.default.createElement("div", {
    "data-testid": testId,
    className: classnames__default.default("".concat(iotPrefix, "--list"), className, _defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--list__full-height"), isFullHeight), "".concat(iotPrefix, "--list--virtual"), isVirtualList))
  }, /*#__PURE__*/React__default.default.createElement(ListHeader$1, _extends__default.default({
    className: classnames__default.default("".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.default.createElement(ListContent$1, _extends__default.default({
    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.default.createElement("div", {
    className: "".concat(iotPrefix, "--list--page")
  }, /*#__PURE__*/React__default.default.createElement(SimplePagination.default, _extends__default.default({}, 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;

exports.UnconnectedList = List;
exports.default = List$1;
