import "core-js/modules/es6.string.iterator";
import "core-js/modules/es6.array.from";
import "core-js/modules/es6.regexp.to-string";
import "core-js/modules/es7.symbol.async-iterator";
import "core-js/modules/es6.symbol";
import "core-js/modules/es6.object.assign";
import "core-js/modules/es6.object.set-prototype-of";
import "core-js/modules/es6.array.find";
import "core-js/modules/es6.function.name";
import "core-js/modules/es6.array.sort";
import "core-js/modules/es6.array.find-index";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/es6.array.iterator";
import "core-js/modules/es6.object.keys";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { dropWhile, slice } from 'lodash';
import { formatAuto, formatBoolean, formatDate, formatNumber, formatText, LEFT_ALIGNMENT, PropertySortType, RIGHT_ALIGNMENT, SortDirection } from '../../services';
import { isFunction } from '../../services/predicate';
import { get } from '../../services/objects';
import { EuiTable } from '../table/table';
import { EuiTableHeaderCellCheckbox } from '../table/table_header_cell_checkbox';
import { EuiCheckbox } from '../form/checkbox/checkbox';
import { EuiTableHeaderCell } from '../table/table_header_cell';
import { EuiTableHeader } from '../table/table_header';
import { EuiTableBody } from '../table/table_body';
import { EuiTableFooterCell } from '../table/table_footer_cell';
import { EuiTableFooter } from '../table/table_footer';
import { EuiTableRowCellCheckbox } from '../table/table_row_cell_checkbox';
import { COLORS as BUTTON_ICON_COLORS } from '../button/button_icon/button_icon';
import { ICON_TYPES } from '../icon';
import { CollapsedItemActions } from './collapsed_item_actions';
import { ExpandedItemActions } from './expanded_item_actions';
import { EuiTableRowCell } from '../table/table_row_cell';
import { EuiTableRow } from '../table/table_row';
import { PaginationBar, PaginationType } from './pagination_bar';
import { EuiIcon } from '../icon/icon';
import { LoadingTableBody } from './loading_table_body';
import { EuiTableHeaderMobile } from '../table/mobile/table_header_mobile';
import { EuiTableSortMobile } from '../table/mobile/table_sort_mobile';
import { withRequiredProp } from '../../utils/prop_types/with_required_prop';
import { EuiScreenReaderOnly, EuiKeyboardAccessible } from '../accessibility';
var dataTypesProfiles = {
  auto: {
    align: LEFT_ALIGNMENT,
    render: function render(value) {
      return formatAuto(value);
    }
  },
  string: {
    align: LEFT_ALIGNMENT,
    render: function render(value) {
      return formatText(value);
    }
  },
  number: {
    align: RIGHT_ALIGNMENT,
    render: function render(value) {
      return formatNumber(value);
    }
  },
  boolean: {
    align: LEFT_ALIGNMENT,
    render: function render(value) {
      return formatBoolean(value);
    }
  },
  date: {
    align: LEFT_ALIGNMENT,
    render: function render(value) {
      return formatDate(value);
    }
  }
};
var DATA_TYPES = Object.keys(dataTypesProfiles);
var DefaultItemActionType = PropTypes.shape({
  type: PropTypes.oneOf(['icon', 'button']),
  // default is 'button'
  name: PropTypes.string.isRequired,
  description: PropTypes.string.isRequired,
  onClick: PropTypes.func.isRequired,
  // (item) => void,
  available: PropTypes.func,
  // (item) => boolean;
  enabled: PropTypes.func,
  // (item) => boolean;
  isPrimary: PropTypes.bool,
  icon: PropTypes.oneOfType([// required when type is 'icon'
  PropTypes.oneOf(ICON_TYPES), PropTypes.func // (item) => oneOf(ICON_TYPES)
  ]),
  color: PropTypes.oneOfType([PropTypes.oneOf(BUTTON_ICON_COLORS), PropTypes.func // (item) => oneOf(ICON_BUTTON_COLORS)
  ])
});
var CustomItemActionType = PropTypes.shape({
  render: PropTypes.func.isRequired,
  // (item, enabled) => PropTypes.node;
  available: PropTypes.func,
  // (item) => boolean;
  enabled: PropTypes.func,
  // (item) => boolean;
  isPrimary: PropTypes.bool
});
var SupportedItemActionType = PropTypes.oneOfType([DefaultItemActionType, CustomItemActionType]);
export var ActionsColumnType = PropTypes.shape({
  actions: PropTypes.arrayOf(SupportedItemActionType).isRequired,
  name: PropTypes.string,
  description: PropTypes.string,
  width: PropTypes.string
});
export var FieldDataColumnTypeShape = {
  field: PropTypes.string.isRequired,
  name: PropTypes.node.isRequired,
  description: PropTypes.string,
  dataType: PropTypes.oneOf(DATA_TYPES),
  width: PropTypes.string,
  sortable: PropTypes.bool,
  align: PropTypes.oneOf([LEFT_ALIGNMENT, RIGHT_ALIGNMENT]),
  truncateText: PropTypes.bool,
  render: PropTypes.func,
  // ((value, record) => PropTypes.node (also see [services/value_renderer] for basic implementations)
  footer: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func])
};
export var FieldDataColumnType = PropTypes.shape(FieldDataColumnTypeShape);
export var ComputedColumnType = PropTypes.shape({
  render: PropTypes.func.isRequired,
  // (record) => PropTypes.node
  name: PropTypes.node,
  description: PropTypes.string,
  width: PropTypes.string,
  truncateText: PropTypes.bool
});
export var ColumnType = PropTypes.oneOfType([FieldDataColumnType, ComputedColumnType, ActionsColumnType]);
export var ItemIdType = PropTypes.oneOfType([PropTypes.string, // the name of the item id property
PropTypes.func // (item) => string
]);
export var SelectionType = PropTypes.shape({
  onSelectionChange: PropTypes.func,
  // (selection: item[]) => void;,
  selectable: PropTypes.func,
  // (item) => boolean;
  selectableMessage: PropTypes.func // (selectable, item) => boolean;

});
var SortingType = PropTypes.shape({
  sort: PropertySortType
});
var BasicTablePropTypes = {
  items: PropTypes.array.isRequired,
  itemId: ItemIdType,
  columns: PropTypes.arrayOf(ColumnType).isRequired,
  pagination: PaginationType,
  sorting: SortingType,
  selection: withRequiredProp(SelectionType, 'itemId', 'row selection uses the itemId prop to identify each row'),
  onChange: PropTypes.func,
  error: PropTypes.string,
  loading: PropTypes.bool,
  noItemsMessage: PropTypes.node,
  className: PropTypes.string,
  compressed: PropTypes.bool,
  itemIdToExpandedRowMap: withRequiredProp(PropTypes.object, 'itemId', 'row expansion uses the itemId prop to identify each row'),
  responsive: PropTypes.bool,
  isSelectable: PropTypes.bool,
  isExpandable: PropTypes.bool,
  hasActions: PropTypes.bool,
  rowProps: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
  cellProps: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
};
export function getItemId(item, itemId) {
  if (itemId) {
    if (isFunction(itemId)) {
      return itemId(item);
    }

    return item[itemId];
  }
}

function getRowProps(item, rowProps) {
  if (rowProps) {
    if (isFunction(rowProps)) {
      return rowProps(item);
    }

    return rowProps;
  }

  return {};
}

function getCellProps(item, column, cellProps) {
  if (cellProps) {
    if (isFunction(cellProps)) {
      return cellProps(item, column);
    }

    return cellProps;
  }

  return {};
}

function getColumnFooter(column, _ref) {
  var items = _ref.items,
      pagination = _ref.pagination;

  if (column.footer) {
    if (isFunction(column.footer)) {
      return column.footer({
        items: items,
        pagination: pagination
      });
    }

    return column.footer;
  }

  return undefined;
}

export var EuiBasicTable =
/*#__PURE__*/
function (_Component) {
  _inherits(EuiBasicTable, _Component);

  _createClass(EuiBasicTable, null, [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps, prevState) {
      if (!nextProps.selection) {
        // next props doesn't have a selection, reset our state
        return {
          selection: []
        };
      }

      var itemId = nextProps.itemId;
      var selection = prevState.selection.filter(function (selectedItem) {
        return nextProps.items.findIndex(function (item) {
          return getItemId(item, itemId) === getItemId(selectedItem, itemId);
        }) !== -1;
      });

      if (selection.length !== prevState.selection.length) {
        if (nextProps.selection.onSelectionChange) {
          nextProps.selection.onSelectionChange(selection);
        }

        return {
          selection: selection
        };
      }

      return null;
    }
  }]);

  function EuiBasicTable(props) {
    var _this;

    _classCallCheck(this, EuiBasicTable);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(EuiBasicTable).call(this, props));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveColumnSortDirection", function (column) {
      var sorting = _this.props.sorting;

      if (!sorting || !sorting.sort || !column.sortable) {
        return;
      }

      if (sorting.sort.field === column.field) {
        return sorting.sort.direction;
      }
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "resolveColumnOnSort", function (column) {
      var sorting = _this.props.sorting;

      if (!sorting || !column.sortable) {
        return;
      }

      if (!_this.props.onChange) {
        throw new Error("BasicTable is configured to be sortable on column [".concat(column.field, "] but\n          [onChange] is not configured. This callback must be implemented to handle the sort requests"));
      }

      return function () {
        return _this.onColumnSortChange(column);
      };
    });

    _this.state = {
      selection: []
    };
    return _this;
  }

  _createClass(EuiBasicTable, [{
    key: "changeSelection",
    value: function changeSelection(selection) {
      if (!this.props.selection) {
        return;
      }

      this.setState({
        selection: selection
      });

      if (this.props.selection.onSelectionChange) {
        this.props.selection.onSelectionChange(selection);
      }
    }
  }, {
    key: "clearSelection",
    value: function clearSelection() {
      this.changeSelection([]);
    }
  }, {
    key: "onPageSizeChange",
    value: function onPageSizeChange(size) {
      this.clearSelection();
      var currentCriteria = EuiBasicTable.buildCriteria(this.props);

      var criteria = _objectSpread({}, currentCriteria, {
        page: {
          index: 0,
          // when page size changes, we take the user back to the first page
          size: size
        }
      });

      this.props.onChange(criteria);
    }
  }, {
    key: "onPageChange",
    value: function onPageChange(index) {
      this.clearSelection();
      var currentCriteria = EuiBasicTable.buildCriteria(this.props);

      var criteria = _objectSpread({}, currentCriteria, {
        page: _objectSpread({}, currentCriteria.page, {
          index: index
        })
      });

      this.props.onChange(criteria);
    }
  }, {
    key: "onColumnSortChange",
    value: function onColumnSortChange(column) {
      this.clearSelection();
      var currentCriteria = EuiBasicTable.buildCriteria(this.props);
      var direction = SortDirection.ASC;

      if (currentCriteria && currentCriteria.sort && currentCriteria.sort.field === column.field) {
        direction = SortDirection.reverse(currentCriteria.sort.direction);
      }

      var criteria = _objectSpread({}, currentCriteria, {
        // resetting the page if the criteria has one
        page: !currentCriteria.page ? undefined : {
          index: 0,
          size: currentCriteria.page.size
        },
        sort: {
          field: column.field,
          direction: direction
        }
      });

      this.props.onChange(criteria);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          className = _this$props.className,
          loading = _this$props.loading,
          items = _this$props.items,
          itemId = _this$props.itemId,
          columns = _this$props.columns,
          pagination = _this$props.pagination,
          sorting = _this$props.sorting,
          selection = _this$props.selection,
          onChange = _this$props.onChange,
          error = _this$props.error,
          noItemsMessage = _this$props.noItemsMessage,
          compressed = _this$props.compressed,
          itemIdToExpandedRowMap = _this$props.itemIdToExpandedRowMap,
          responsive = _this$props.responsive,
          isSelectable = _this$props.isSelectable,
          isExpandable = _this$props.isExpandable,
          hasActions = _this$props.hasActions,
          rowProps = _this$props.rowProps,
          cellProps = _this$props.cellProps,
          rest = _objectWithoutProperties(_this$props, ["className", "loading", "items", "itemId", "columns", "pagination", "sorting", "selection", "onChange", "error", "noItemsMessage", "compressed", "itemIdToExpandedRowMap", "responsive", "isSelectable", "isExpandable", "hasActions", "rowProps", "cellProps"]);

      var classes = classNames('euiBasicTable', {
        'euiBasicTable-loading': loading
      }, className);
      var table = this.renderTable();
      var paginationBar = this.renderPaginationBar();
      return React.createElement("div", _extends({
        className: classes
      }, rest), table, paginationBar);
    }
  }, {
    key: "renderTable",
    value: function renderTable() {
      var _this2 = this;

      var _this$props2 = this.props,
          compressed = _this$props2.compressed,
          responsive = _this$props2.responsive;
      var mobileHeader = responsive ? React.createElement(EuiTableHeaderMobile, null, this.renderTableMobileSort()) : undefined;
      var caption = this.renderTableCaption();
      var head = this.renderTableHead();
      var body = this.renderTableBody();
      var footer = this.renderTableFooter();
      return React.createElement("div", {
        ref: function ref(element) {
          _this2.tableElement = element;
        }
      }, mobileHeader, React.createElement(EuiTable, {
        responsive: responsive,
        compressed: compressed
      }, caption, head, body, footer));
    }
  }, {
    key: "renderTableMobileSort",
    value: function renderTableMobileSort() {
      var _this3 = this;

      var _this$props3 = this.props,
          columns = _this$props3.columns,
          sorting = _this$props3.sorting;
      var items = [];

      if (!sorting) {
        return null;
      }

      columns.forEach(function (column, index) {
        if (!column.sortable || column.hideForMobile) {
          return;
        }

        var sortDirection = _this3.resolveColumnSortDirection(column);

        items.push({
          name: column.name,
          key: "_data_s_".concat(column.field, "_").concat(index),
          onSort: _this3.resolveColumnOnSort(column),
          isSorted: !!sortDirection,
          isSortAscending: sortDirection ? SortDirection.isAsc(sortDirection) : undefined
        });
      });
      return items.length ? React.createElement(EuiTableSortMobile, {
        items: items
      }) : null;
    }
  }, {
    key: "renderTableCaption",
    value: function renderTableCaption() {
      var items = this.props.items;
      return React.createElement(EuiScreenReaderOnly, null, React.createElement("caption", {
        role: "status",
        "aria-relevant": "text",
        "aria-live": "polite"
      }, "Below is a table of ", items.length, " items."));
    }
  }, {
    key: "renderTableHead",
    value: function renderTableHead() {
      var _this4 = this;

      var _this$props4 = this.props,
          items = _this$props4.items,
          columns = _this$props4.columns,
          selection = _this$props4.selection;
      var headers = [];

      if (selection) {
        var selectableItems = items.filter(function (item) {
          return !selection.selectable || selection.selectable(item);
        });
        var checked = this.state.selection && selectableItems.length > 0 && this.state.selection.length === selectableItems.length;
        var disabled = selectableItems.length === 0;

        var onChange = function onChange(event) {
          if (event.target.checked) {
            _this4.changeSelection(selectableItems);
          } else {
            _this4.changeSelection([]);
          }
        };

        headers.push(React.createElement(EuiTableHeaderCellCheckbox, {
          key: "_selection_column_h",
          width: "24px"
        }, React.createElement(EuiCheckbox, {
          id: "_selection_column-checkbox",
          type: "inList",
          checked: checked,
          disabled: disabled,
          onChange: onChange,
          "data-test-subj": "checkboxSelectAll",
          "aria-label": "Select all rows"
        })));
      }

      columns.forEach(function (column, index) {
        var actions = column.actions,
            width = column.width,
            name = column.name,
            field = column.field,
            align = column.align,
            dataType = column.dataType,
            sortable = column.sortable,
            isMobileHeader = column.isMobileHeader,
            hideForMobile = column.hideForMobile;

        var columnAlign = align || _this4.getAlignForDataType(dataType); // actions column


        if (actions) {
          headers.push(React.createElement(EuiTableHeaderCell, {
            key: "_actions_h_".concat(index),
            align: "right",
            width: width
          }, name));
          return;
        } // computed column


        if (!field) {
          headers.push(React.createElement(EuiTableHeaderCell, {
            key: "_computed_column_h_".concat(index),
            align: columnAlign,
            width: width
          }, name));
          return;
        } // field data column


        var sorting = {};

        if (_this4.props.sorting && sortable) {
          var sortDirection = _this4.resolveColumnSortDirection(column);

          sorting.isSorted = !!sortDirection;
          sorting.isSortAscending = sortDirection ? SortDirection.isAsc(sortDirection) : undefined;
          sorting.onSort = _this4.resolveColumnOnSort(column);
        }

        headers.push(React.createElement(EuiTableHeaderCell, _extends({
          key: "_data_h_".concat(field, "_").concat(index),
          align: columnAlign,
          width: width,
          isMobileHeader: isMobileHeader,
          hideForMobile: hideForMobile,
          "data-test-subj": "tableHeaderCell_".concat(field, "_").concat(index)
        }, sorting), name));
      });
      return React.createElement(EuiTableHeader, null, headers);
    }
  }, {
    key: "renderTableFooter",
    value: function renderTableFooter() {
      var _this$props5 = this.props,
          items = _this$props5.items,
          columns = _this$props5.columns,
          pagination = _this$props5.pagination,
          selection = _this$props5.selection;
      var footers = [];
      var hasDefinedFooter = false;

      if (selection) {
        // Create an empty cell to compensate for additional selection column
        footers.push(React.createElement(EuiTableFooterCell, {
          key: "_selection_column_f"
        }, undefined));
      }

      columns.forEach(function (column) {
        var footer = getColumnFooter(column, {
          items: items,
          pagination: pagination
        });

        if (column.isMobileHeader) {
          return; // exclude columns that only exist for mobile headers
        }

        if (footer) {
          footers.push(React.createElement(EuiTableFooterCell, {
            key: "footer_".concat(column.field),
            align: column.align
          }, footer));
          hasDefinedFooter = true;
        } else {
          // Footer is undefined, so create an empty cell to preserve layout
          footers.push(React.createElement(EuiTableFooterCell, {
            key: "footer_empty_".concat(footers.length - 1),
            align: column.align
          }, undefined));
        }
      });
      return footers.length && hasDefinedFooter ? React.createElement(EuiTableFooter, null, footers) : null;
    }
  }, {
    key: "renderTableBody",
    value: function renderTableBody() {
      var _this5 = this;

      if (this.props.error) {
        return this.renderErrorBody(this.props.error);
      }

      var items = this.props.items;

      if (items.length === 0) {
        return this.renderEmptyBody();
      }

      var rows = items.map(function (item, index) {
        // if there's pagination the item's index must be adjusted to the where it is in the whole dataset
        var tableItemIndex = _this5.props.pagination ? _this5.props.pagination.pageIndex * _this5.props.pagination.pageSize + index : index;
        return _this5.renderItemRow(item, tableItemIndex);
      });

      if (this.props.loading) {
        return React.createElement(LoadingTableBody, null, rows);
      }

      return React.createElement(EuiTableBody, null, rows);
    }
  }, {
    key: "renderErrorBody",
    value: function renderErrorBody(error) {
      var colSpan = this.props.columns.length + (this.props.selection ? 1 : 0);
      return React.createElement(EuiTableBody, null, React.createElement(EuiTableRow, null, React.createElement(EuiTableRowCell, {
        align: "center",
        colSpan: colSpan,
        isMobileFullWidth: true
      }, React.createElement(EuiIcon, {
        type: "minusInCircle",
        color: "danger"
      }), " ", error)));
    }
  }, {
    key: "renderEmptyBody",
    value: function renderEmptyBody() {
      var _this$props6 = this.props,
          columns = _this$props6.columns,
          selection = _this$props6.selection,
          noItemsMessage = _this$props6.noItemsMessage;
      var colSpan = columns.length + (selection ? 1 : 0);
      return React.createElement(EuiTableBody, null, React.createElement(EuiTableRow, null, React.createElement(EuiTableRowCell, {
        align: "center",
        colSpan: colSpan,
        isMobileFullWidth: true
      }, noItemsMessage)));
    }
  }, {
    key: "renderItemRow",
    value: function renderItemRow(item, rowIndex) {
      var _this6 = this;

      var _this$props7 = this.props,
          columns = _this$props7.columns,
          selection = _this$props7.selection,
          isSelectable = _this$props7.isSelectable,
          hasActions = _this$props7.hasActions,
          _this$props7$itemIdTo = _this$props7.itemIdToExpandedRowMap,
          itemIdToExpandedRowMap = _this$props7$itemIdTo === void 0 ? {} : _this$props7$itemIdTo,
          isExpandable = _this$props7.isExpandable;
      var cells = [];
      var itemIdCallback = this.props.itemId;
      var itemId = getItemId(item, itemIdCallback) || rowIndex;
      var selected = !selection ? false : this.state.selection && !!this.state.selection.find(function (selectedItem) {
        return getItemId(selectedItem, itemIdCallback) === itemId;
      });
      var calculatedHasSelection;

      if (selection) {
        cells.push(this.renderItemSelectionCell(itemId, item, selected));
        calculatedHasSelection = true;
      }

      var calculatedHasActions;
      columns.forEach(function (column, columnIndex) {
        if (column.actions) {
          cells.push(_this6.renderItemActionsCell(itemId, item, column, columnIndex, rowIndex));
          calculatedHasActions = true;
        } else if (column.field) {
          cells.push(_this6.renderItemFieldDataCell(itemId, item, column, columnIndex));
        } else {
          cells.push(_this6.renderItemComputedCell(itemId, item, column, columnIndex));
        }
      }); // Occupy full width of table, taking checkbox & mobile only columns into account.

      var expandedRowColSpan = selection ? columns.length + 1 : columns.length;
      var mobileOnlyCols = columns.reduce(function (num, column) {
        return column.isMobileHeader ? num + 1 : num + 0;
      }, 0);
      expandedRowColSpan = expandedRowColSpan - mobileOnlyCols; // We'll use the ID to associate the expanded row with the original.

      var hasExpandedRow = itemIdToExpandedRowMap.hasOwnProperty(itemId);
      var expandedRowId = hasExpandedRow ? "row_".concat(itemId, "_expansion") : undefined;
      var expandedRow = hasExpandedRow ? React.createElement(EuiTableRow, {
        id: expandedRowId,
        isExpandedRow: true,
        isSelectable: isSelectable
      }, React.createElement(EuiTableRowCell, {
        colSpan: expandedRowColSpan
      }, itemIdToExpandedRowMap[itemId])) : undefined;
      var rowPropsCallback = this.props.rowProps;
      var rowProps = getRowProps(item, rowPropsCallback);
      var row = React.createElement(EuiTableRow, _extends({
        "aria-owns": expandedRowId,
        isSelectable: isSelectable == null ? calculatedHasSelection : isSelectable,
        isSelected: selected,
        hasActions: hasActions == null ? calculatedHasActions : hasActions,
        isExpandable: isExpandable
      }, rowProps), cells);
      return React.createElement(Fragment, {
        key: "row_".concat(itemId)
      }, rowProps.onClick ? React.createElement(EuiKeyboardAccessible, null, row) : row, expandedRow);
    }
  }, {
    key: "renderItemSelectionCell",
    value: function renderItemSelectionCell(itemId, item, selected) {
      var _this7 = this;

      var selection = this.props.selection;
      var key = "_selection_column_".concat(itemId);
      var checked = selected;
      var disabled = selection.selectable && !selection.selectable(item);
      var title = selection.selectableMessage && selection.selectableMessage(!disabled, item);

      var onChange = function onChange(event) {
        if (event.target.checked) {
          _this7.changeSelection(_toConsumableArray(_this7.state.selection).concat([item]));
        } else {
          var itemIdCallback = _this7.props.itemId;

          _this7.changeSelection(_this7.state.selection.reduce(function (selection, selectedItem) {
            if (getItemId(selectedItem, itemIdCallback) !== itemId) {
              selection.push(selectedItem);
            }

            return selection;
          }, []));
        }
      };

      return React.createElement(EuiTableRowCellCheckbox, {
        key: key
      }, React.createElement(EuiCheckbox, {
        id: "".concat(key, "-checkbox"),
        type: "inList",
        disabled: disabled,
        checked: checked,
        onChange: onChange,
        title: title,
        "aria-label": "Select this row",
        "data-test-subj": "checkboxSelectRow-".concat(itemId)
      }));
    }
  }, {
    key: "renderItemActionsCell",
    value: function renderItemActionsCell(itemId, item, column, columnIndex) {
      var _this8 = this;

      var actionEnabled = function actionEnabled(action) {
        return _this8.state.selection.length === 0 && (!action.enabled || action.enabled(item));
      };

      var actualActions = column.actions;

      if (column.actions.length > 2) {
        // if any of the actions `isPrimary`, add them inline as well, but only the first 2
        actualActions = slice(dropWhile(column.actions, function (o) {
          return !o.isPrimary;
        }), 0, 2); // if we have more than 1 action, we don't show them all in the cell, instead we
        // put them all in a popover tool. This effectively means we can only have a maximum
        // of one tool per row (it's either and normal action, or it's a popover that shows multiple actions)
        //
        // here we create a single custom action that triggers the popover with all the configured actions

        actualActions.push({
          name: 'All actions',
          render: function render(item) {
            return React.createElement(CollapsedItemActions, {
              actions: column.actions,
              itemId: itemId,
              item: item,
              actionEnabled: actionEnabled
            });
          }
        });
      }

      var tools = React.createElement(ExpandedItemActions, {
        actions: actualActions,
        itemId: itemId,
        item: item,
        actionEnabled: actionEnabled
      });
      var key = "record_actions_".concat(itemId, "_").concat(columnIndex);
      return React.createElement(EuiTableRowCell, {
        showOnHover: true,
        key: key,
        align: "right",
        textOnly: false,
        hasActions: true
      }, tools);
    }
  }, {
    key: "renderItemFieldDataCell",
    value: function renderItemFieldDataCell(itemId, item, column, columnIndex) {
      var field = column.field,
          render = column.render,
          dataType = column.dataType;
      var key = "_data_column_".concat(field, "_").concat(itemId, "_").concat(columnIndex);
      var contentRenderer = render || this.getRendererForDataType(dataType);
      var value = get(item, field);
      var content = contentRenderer(value, item);
      return this.renderItemCell(item, column, key, content);
    }
  }, {
    key: "renderItemComputedCell",
    value: function renderItemComputedCell(itemId, item, column, columnIndex) {
      var render = column.render,
          dataType = column.dataType;
      var key = "_computed_column_".concat(itemId, "_").concat(columnIndex);
      var contentRenderer = render || this.getRendererForDataType(dataType);
      var content = contentRenderer(item);
      return this.renderItemCell(item, column, key, content);
    }
  }, {
    key: "renderItemCell",
    value: function renderItemCell(item, column, key, content) {
      var align = column.align,
          render = column.render,
          dataType = column.dataType,
          isExpander = column.isExpander,
          textOnly = column.textOnly,
          name = column.name,
          field = column.field,
          description = column.description,
          sortable = column.sortable,
          footer = column.footer,
          rest = _objectWithoutProperties(column, ["align", "render", "dataType", "isExpander", "textOnly", "name", "field", "description", "sortable", "footer"]);

      var columnAlign = align || this.getAlignForDataType(dataType);
      var cellPropsCallback = this.props.cellProps;
      var cellProps = getCellProps(item, column, cellPropsCallback);
      return React.createElement(EuiTableRowCell, _extends({
        key: key,
        align: columnAlign,
        header: name,
        isExpander: isExpander,
        textOnly: textOnly || !render
      }, cellProps, rest), content);
    }
  }, {
    key: "getRendererForDataType",
    value: function getRendererForDataType() {
      var dataType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'auto';
      var profile = dataTypesProfiles[dataType];

      if (!profile) {
        throw new Error("Unknown dataType [".concat(dataType, "]. The supported data types are [").concat(DATA_TYPES.join(', '), "]"));
      }

      return profile.render;
    }
  }, {
    key: "getAlignForDataType",
    value: function getAlignForDataType() {
      var dataType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'auto';
      var profile = dataTypesProfiles[dataType];

      if (!profile) {
        throw new Error("Unknown dataType [".concat(dataType, "]. The supported data types are [").concat(DATA_TYPES.join(', '), "]"));
      }

      return profile.align;
    }
  }, {
    key: "renderPaginationBar",
    value: function renderPaginationBar() {
      var _this$props8 = this.props,
          error = _this$props8.error,
          pagination = _this$props8.pagination,
          onChange = _this$props8.onChange;

      if (!error && pagination) {
        if (!onChange) {
          throw new Error("The Basic Table is configured with pagination but [onChange] is\n        not configured. This callback must be implemented to handle pagination changes");
        }

        return React.createElement(PaginationBar, {
          pagination: pagination,
          onPageSizeChange: this.onPageSizeChange.bind(this),
          onPageChange: this.onPageChange.bind(this)
        });
      }
    }
  }], [{
    key: "buildCriteria",
    value: function buildCriteria(props) {
      var criteria = {};

      if (props.pagination) {
        criteria.page = {
          index: props.pagination.pageIndex,
          size: props.pagination.pageSize
        };
      }

      if (props.sorting) {
        criteria.sort = props.sorting.sort;
      }

      return criteria;
    }
  }]);

  return EuiBasicTable;
}(Component);

_defineProperty(EuiBasicTable, "propTypes", BasicTablePropTypes);

_defineProperty(EuiBasicTable, "defaultProps", {
  responsive: true,
  noItemsMessage: 'No items found'
});

EuiBasicTable.__docgenInfo = {
  "description": "",
  "methods": [{
    "name": "getDerivedStateFromProps",
    "docblock": null,
    "modifiers": ["static"],
    "params": [{
      "name": "nextProps",
      "type": null
    }, {
      "name": "prevState",
      "type": null
    }],
    "returns": null
  }, {
    "name": "buildCriteria",
    "docblock": null,
    "modifiers": ["static"],
    "params": [{
      "name": "props",
      "type": null
    }],
    "returns": null
  }, {
    "name": "changeSelection",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "selection",
      "type": null
    }],
    "returns": null
  }, {
    "name": "clearSelection",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "onPageSizeChange",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "size",
      "type": null
    }],
    "returns": null
  }, {
    "name": "onPageChange",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "index",
      "type": null
    }],
    "returns": null
  }, {
    "name": "onColumnSortChange",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "column",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderTable",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderTableMobileSort",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderTableCaption",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderTableHead",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderTableFooter",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderTableBody",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderErrorBody",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "error",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderEmptyBody",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "renderItemRow",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "item",
      "type": null
    }, {
      "name": "rowIndex",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderItemSelectionCell",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "itemId",
      "type": null
    }, {
      "name": "item",
      "type": null
    }, {
      "name": "selected",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderItemActionsCell",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "itemId",
      "type": null
    }, {
      "name": "item",
      "type": null
    }, {
      "name": "column",
      "type": null
    }, {
      "name": "columnIndex",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderItemFieldDataCell",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "itemId",
      "type": null
    }, {
      "name": "item",
      "type": null
    }, {
      "name": "column",
      "type": null
    }, {
      "name": "columnIndex",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderItemComputedCell",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "itemId",
      "type": null
    }, {
      "name": "item",
      "type": null
    }, {
      "name": "column",
      "type": null
    }, {
      "name": "columnIndex",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderItemCell",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "item",
      "type": null
    }, {
      "name": "column",
      "type": null
    }, {
      "name": "key",
      "type": null
    }, {
      "name": "content",
      "type": null
    }],
    "returns": null
  }, {
    "name": "resolveColumnSortDirection",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "column",
      "type": null
    }],
    "returns": null
  }, {
    "name": "resolveColumnOnSort",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "column",
      "type": null
    }],
    "returns": null
  }, {
    "name": "getRendererForDataType",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "dataType",
      "type": null
    }],
    "returns": null
  }, {
    "name": "getAlignForDataType",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "dataType",
      "type": null
    }],
    "returns": null
  }, {
    "name": "renderPaginationBar",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }],
  "displayName": "EuiBasicTable",
  "props": {
    "responsive": {
      "defaultValue": {
        "value": "true",
        "computed": false
      },
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "noItemsMessage": {
      "defaultValue": {
        "value": "'No items found'",
        "computed": false
      },
      "type": {
        "name": "node"
      },
      "required": false,
      "description": ""
    },
    "items": {
      "type": {
        "name": "array"
      },
      "required": true,
      "description": ""
    },
    "itemId": {
      "type": {
        "name": "custom",
        "raw": "ItemIdType"
      },
      "required": false,
      "description": ""
    },
    "columns": {
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "custom",
          "raw": "ColumnType"
        }
      },
      "required": true,
      "description": ""
    },
    "pagination": {
      "type": {
        "name": "custom",
        "raw": "PaginationType"
      },
      "required": false,
      "description": ""
    },
    "sorting": {
      "type": {
        "name": "custom",
        "raw": "SortingType"
      },
      "required": false,
      "description": ""
    },
    "selection": {
      "type": {
        "name": "custom",
        "raw": "withRequiredProp(SelectionType, 'itemId', 'row selection uses the itemId prop to identify each row')"
      },
      "required": false,
      "description": ""
    },
    "onChange": {
      "type": {
        "name": "func"
      },
      "required": false,
      "description": ""
    },
    "error": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "loading": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "className": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "compressed": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "itemIdToExpandedRowMap": {
      "type": {
        "name": "custom",
        "raw": "withRequiredProp(PropTypes.object, 'itemId', 'row expansion uses the itemId prop to identify each row')"
      },
      "required": false,
      "description": ""
    },
    "isSelectable": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "isExpandable": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "hasActions": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": ""
    },
    "rowProps": {
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "object"
        }]
      },
      "required": false,
      "description": ""
    },
    "cellProps": {
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "object"
        }]
      },
      "required": false,
      "description": ""
    }
  }
};