"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _List = _interopRequireDefault(require("react-virtualized/dist/commonjs/List"));

var _AutoSizer = _interopRequireDefault(require("react-virtualized/dist/commonjs/AutoSizer"));

var _CellMeasurer = require("react-virtualized/dist/commonjs/CellMeasurer");

var _index = require("./index.js");

var _examplesList = _interopRequireDefault(require("./examples-list.js"));

var _examples$TABLE$virtu;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

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

var data = [['1', 'Sarah', 'Brown', 31, 'New York No. 1 Anywhere'], ['2', 'Jane', 'Smith', 32, 'San Francisco No. 1 Anywhere'], ['3', 'Joe', 'Black', 33, 'Sydney No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere London No. 1 Anywhere London No. 1 Anywhere London No. 1 Anywhere London No. 1 Anywhere London No. 1 Anywhere London No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere'], ['4', 'Jane', 'Red', 34, 'London No. 1 Anywhere']].map(function (row) {
  return ["".concat(row[1], " ").concat(row[2]), row[3], row[4]];
}); // selects data to display

var DATA = data.concat(data).concat(data).concat(data);
var cache = new _CellMeasurer.CellMeasurerCache({
  defaultHeight: 36
}); // eslint-disable-next-line flowtype/no-weak-types

function Virtual(props) {
  return _react.default.createElement(_index.StyledTable, null, _react.default.createElement(_index.StyledContent, {
    $width: props.width + 'px'
  }, _react.default.createElement(_index.StyledHead, {
    $width: props.width + 'px'
  }, props.columns.map(function (column, index) {
    return _react.default.createElement(_index.StyledHeadCell, {
      key: index
    }, column);
  })), _react.default.createElement(_AutoSizer.default, null, function (_ref) {
    var width = _ref.width,
        height = _ref.height;
    return _react.default.createElement(_List.default, {
      height: height - 60,
      width: props.width || width,
      rowCount: props.data.length,
      rowHeight: cache.rowHeight,
      deferredMeasurementCache: cache,
      rowRenderer: function rowRenderer(_ref2) {
        var index = _ref2.index,
            key = _ref2.key,
            parent = _ref2.parent,
            style = _ref2.style;
        return _react.default.createElement(_CellMeasurer.CellMeasurer, {
          cache: cache,
          columnIndex: 0,
          key: key,
          parent: parent,
          rowIndex: index
        }, _react.default.createElement(_index.StyledRow, {
          key: key,
          style: style
        }, props.data[index].map(function (cell, index) {
          return _react.default.createElement(_index.StyledCell, {
            key: index
          }, cell);
        })));
      }
    });
  })));
}

var _default = (_examples$TABLE$virtu = {}, _defineProperty(_examples$TABLE$virtu, _examplesList.default.TABLE, function TableStory() {
  return _react.default.createElement("div", {
    style: {
      height: '400px',
      width: '800px',
      marginTop: '48px'
    }
  }, _react.default.createElement(_index.Table, {
    columns: ['Name', 'Age', 'Address'],
    data: DATA
  }));
}), _defineProperty(_examples$TABLE$virtu, "virtual", function VirtualStory() {
  return _react.default.createElement("div", {
    style: {
      height: '500px',
      width: '800px',
      marginTop: '48px'
    }
  }, _react.default.createElement(Virtual, {
    columns: ['Name', 'Age', 'Address'],
    data: DATA
  }));
}), _defineProperty(_examples$TABLE$virtu, "virtualHorizontalScroll", function VirtualHorizontalStory() {
  return _react.default.createElement("div", {
    style: {
      height: '500px',
      width: '800px',
      marginTop: '48px'
    }
  }, _react.default.createElement(Virtual, {
    columns: ['Name', 'Age', 'Address'],
    data: DATA,
    width: 2200
  }));
}), _defineProperty(_examples$TABLE$virtu, "horizontalScroll", function Horizontal() {
  return _react.default.createElement("div", {
    style: {
      height: '500px',
      maxWidth: '1200px',
      marginTop: '48px'
    }
  }, _react.default.createElement(_index.Table, {
    columns: _toConsumableArray(new Array(10)).map(function () {
      return 'Column Name';
    }),
    data: _toConsumableArray(new Array(40)).map(function () {
      return _toConsumableArray(new Array(10)).map(function () {
        return 'Cell Data';
      });
    }),
    horizontalScrollWidth: "2200px"
  }));
}), _examples$TABLE$virtu);

exports.default = _default;