var _examples$TABLE$virtu;

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

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import List from 'react-virtualized/dist/commonjs/List'; // eslint-disable-line import/extensions

import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer'; // eslint-disable-line import/extensions

import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer'; // eslint-disable-line import/extensions

import { Table, StyledTable, StyledContent, StyledHead, StyledHeadCell, StyledRow, StyledCell } from './index.js';
import examples from './examples-list.js';
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 CellMeasurerCache({
  defaultHeight: 36
}); // eslint-disable-next-line flowtype/no-weak-types

function Virtual(props) {
  return React.createElement(StyledTable, null, React.createElement(StyledContent, {
    $width: props.width + 'px'
  }, React.createElement(StyledHead, {
    $width: props.width + 'px'
  }, props.columns.map(function (column, index) {
    return React.createElement(StyledHeadCell, {
      key: index
    }, column);
  })), React.createElement(AutoSizer, null, function (_ref) {
    var width = _ref.width,
        height = _ref.height;
    return React.createElement(List, {
      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.createElement(CellMeasurer, {
          cache: cache,
          columnIndex: 0,
          key: key,
          parent: parent,
          rowIndex: index
        }, React.createElement(StyledRow, {
          key: key,
          style: style
        }, props.data[index].map(function (cell, index) {
          return React.createElement(StyledCell, {
            key: index
          }, cell);
        })));
      }
    });
  })));
}

export default (_examples$TABLE$virtu = {}, _defineProperty(_examples$TABLE$virtu, examples.TABLE, function TableStory() {
  return React.createElement("div", {
    style: {
      height: '400px',
      width: '800px',
      marginTop: '48px'
    }
  }, React.createElement(Table, {
    columns: ['Name', 'Age', 'Address'],
    data: DATA
  }));
}), _defineProperty(_examples$TABLE$virtu, "virtual", function VirtualStory() {
  return React.createElement("div", {
    style: {
      height: '500px',
      width: '800px',
      marginTop: '48px'
    }
  }, React.createElement(Virtual, {
    columns: ['Name', 'Age', 'Address'],
    data: DATA
  }));
}), _defineProperty(_examples$TABLE$virtu, "virtualHorizontalScroll", function VirtualHorizontalStory() {
  return React.createElement("div", {
    style: {
      height: '500px',
      width: '800px',
      marginTop: '48px'
    }
  }, React.createElement(Virtual, {
    columns: ['Name', 'Age', 'Address'],
    data: DATA,
    width: 2200
  }));
}), _defineProperty(_examples$TABLE$virtu, "horizontalScroll", function Horizontal() {
  return React.createElement("div", {
    style: {
      height: '500px',
      maxWidth: '1200px',
      marginTop: '48px'
    }
  }, React.createElement(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);