var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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

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

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

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

import React from 'react';
import { Table, TableHeader, TableBody } from '../index';

var SelectableTable = function (_React$Component) {
  _inherits(SelectableTable, _React$Component);

  function SelectableTable(props) {
    _classCallCheck(this, SelectableTable);

    var _this = _possibleConstructorReturn(this, (SelectableTable.__proto__ || Object.getPrototypeOf(SelectableTable)).call(this, props));

    _this.state = {
      columns: [{ title: 'Repositories' }, 'Branches', { title: 'Pull requests' }, 'Workspaces', 'Last Commit'],
      rows: [{
        cells: ['one', 'two', 'a', 'four', 'five']
      }, {
        cells: ['a', 'two', 'k', 'four', 'five']
      }, {
        cells: ['p', 'two', 'b', 'four', 'five']
      }]
    };
    _this.onSelect = _this.onSelect.bind(_this);
    return _this;
  }

  _createClass(SelectableTable, [{
    key: 'onSelect',
    value: function onSelect(event, isSelected, rowId) {
      var rows = void 0;
      if (rowId === -1) {
        rows = this.state.rows.map(function (oneRow) {
          oneRow.selected = isSelected;
          return oneRow;
        });
      } else {
        rows = [].concat(_toConsumableArray(this.state.rows));
        rows[rowId].selected = isSelected;
      }
      this.setState({
        rows: rows
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _state = this.state,
          columns = _state.columns,
          rows = _state.rows;


      return React.createElement(
        Table,
        { caption: 'Selectable Table', onSelect: this.onSelect, cells: columns, rows: rows },
        React.createElement(TableHeader, null),
        React.createElement(TableBody, null)
      );
    }
  }]);

  return SelectableTable;
}(React.Component);

export default SelectableTable;