var _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; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React from 'react';
import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext';

import { StyledPagingTable } from './StyledPagingTable';

var responsiveColumns = function responsiveColumns(size, columns) {
  return Array.isArray(columns) ? columns.map(function (column) {
    if (size === undefined) {
      return column;
    }
    var show = column.show;
    if (column.responsiveShow) {
      var sizes = Array.isArray(column.responsiveShow) ? column.responsiveShow : [column.responsiveShow];
      if (sizes.indexOf(size) !== -1) {
        show = true;
      }
    }
    if (column.responsiveHide) {
      var _sizes = Array.isArray(column.responsiveHide) ? column.responsiveHide : [column.responsiveHide];
      if (_sizes.indexOf(size) !== -1) {
        show = false;
      }
    }
    if (show === undefined) {
      return column;
    }
    return _extends({}, column, { show: show });
  }) : columns;
};
var PagingTable = function PagingTable(_ref) {
  var data = _ref.data,
      columns = _ref.columns,
      rest = _objectWithoutProperties(_ref, ['data', 'columns']);

  var defaults = {
    showPagination: rest.onFetchData !== undefined || data && data.length > (rest.defaultPageSize || 20),
    minRows: data && data.length < (rest.defaultPageSize || 20) ? 0 : undefined
  };
  var newProps = _extends({}, defaults, rest);
  return React.createElement(
    ResponsiveContext.Consumer,
    null,
    function (size) {
      return React.createElement(StyledPagingTable, _extends({
        data: data || [],
        columns: responsiveColumns(size, columns)
      }, newProps));
    }
  );
};

var PagingTableDoc = void 0;
if (process.env.NODE_ENV !== 'production') {
  PagingTableDoc = require('./doc').default(PagingTable); // eslint-disable-line global-require
}

var PagingTableWrapper = PagingTableDoc || PagingTable;

export { PagingTableWrapper as PagingTable };