import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/Table/DataTable/docs/ExampleCallingServer.jsx";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React from 'react';
import DataTable from '..';
var style = {
  width: '966px'
};
var baseData = [{
  firstName: 'Meghan',
  lastName: 'Bishop'
}, {
  firstName: 'Sara',
  lastName: 'Porter'
}, {
  firstName: 'Deborah',
  lastName: 'Rhodes'
}, {
  firstName: 'Walter',
  lastName: 'Jenning'
}];
var generateData = function generateData(count) {
  var data = [];
  for (var i = 0; i < count; i++) {
    data = data.concat(baseData);
  }
  return data;
};
var DataTableExample = /*#__PURE__*/function (_React$Component) {
  function DataTableExample(props) {
    var _this;
    _classCallCheck(this, DataTableExample);
    _this = _callSuper(this, DataTableExample, [props]);
    _this.state = {
      hasMore: true,
      count: 5
    };
    _this.loadMore = _this.loadMore.bind(_this);
    return _this;
  }
  _inherits(DataTableExample, _React$Component);
  return _createClass(DataTableExample, [{
    key: "loadMore",
    value: function loadMore() {
      var _this2 = this;
      var loadMoreData = function loadMoreData() {
        _this2.setState({
          count: _this2.state.count + 5
        });
        if (_this2.state.count > 20) {
          _this2.setState({
            hasMore: false
          });
        }
      };
      setTimeout(loadMoreData, 3000);
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;
      return /*#__PURE__*/React.createElement("div", {
        style: style,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 42,
          columnNumber: 7
        }
      }, /*#__PURE__*/React.createElement(DataTable, {
        dataHook: "story-data-table-infinite-scroll",
        data: generateData(this.state.count),
        onRowClick: function onRowClick(row, rowNum) {
          window.alert("You clicked \"".concat(row.firstName, " ").concat(row.lastName, "\", row number ").concat(rowNum + 1));
        },
        infiniteScroll: true,
        itemsPerPage: 20,
        columns: [{
          title: 'Row Number',
          render: function render(row, rowNum) {
            return '#' + (rowNum + 1);
          },
          width: '20%',
          important: true
        }, {
          title: 'First Name',
          render: function render(row) {
            return /*#__PURE__*/React.createElement("span", {
              __self: _this3,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 64,
                columnNumber: 30
              }
            }, row.firstName);
          },
          width: '40%'
        }, {
          title: 'Last Name',
          render: function render(row) {
            return /*#__PURE__*/React.createElement("span", {
              __self: _this3,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 69,
                columnNumber: 30
              }
            }, row.lastName);
          },
          width: '40%'
        }],
        hasMore: this.state.hasMore,
        loadMore: this.loadMore,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 43,
          columnNumber: 9
        }
      }));
    }
  }]);
}(React.Component);
export default DataTableExample;