"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

var _button = _interopRequireDefault(require("../../button"));

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

var _reactDom = _interopRequireDefault(require("react-dom"));

var _ = _interopRequireDefault(require(".."));

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

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

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

var ExpandedApp = /*#__PURE__*/function (_React$Component) {
  _inherits(ExpandedApp, _React$Component);

  var _super = _createSuper(ExpandedApp);

  function ExpandedApp(props) {
    var _this;

    _classCallCheck(this, ExpandedApp);

    _this = _super.call(this, props);
    _this.state = {
      dataSource: _this.props.dataSource
    };
    return _this;
  }

  _createClass(ExpandedApp, [{
    key: "load",
    value: function load() {
      var dataSource = this.state.dataSource;
      dataSource = dataSource.concat(dataSource);
      this.setState({
        dataSource: dataSource
      });
    }
  }, {
    key: "render",
    value: function render() {
      var style = {
        borderTop: '1px solid #eee',
        textAlign: 'center',
        background: '#f8f8f8',
        lineHeight: '28px'
      };
      return /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          marginTop: 10
        }
      }, /*#__PURE__*/_react["default"].createElement(_["default"], {
        dataSource: this.state.dataSource,
        hasHeader: false,
        hasBorder: false
      }, /*#__PURE__*/_react["default"].createElement(_["default"].Column, {
        title: "Title",
        dataIndex: "title"
      }), /*#__PURE__*/_react["default"].createElement(_["default"].Column, {
        title: "Time",
        dataIndex: "time",
        width: 200
      })), /*#__PURE__*/_react["default"].createElement("p", {
        style: style,
        onClick: this.load.bind(this)
      }, this.props.index, ": Load more data.", ' '));
    }
  }]);

  return ExpandedApp;
}(_react["default"].Component);

var dataSource = function dataSource() {
  var result = [];

  for (var i = 0; i < 5; i++) {
    result.push({
      title: "Quotation for 1PCS Nano ".concat(3 + i, ".0 controller compatible"),
      id: 100306660940 + i,
      time: 2000 + i,
      children: [{
        title: "Sub title for Quotation ".concat(3 + i),
        time: 2000 + i
      }, {
        title: "Sub2 title for Quotation ".concat(3 + i),
        time: 2000 + i
      }]
    });
  }

  return result;
},
    _render = function render(value, index, record) {
  return /*#__PURE__*/_react["default"].createElement("a", null, "Remove(", record.id, ")");
},
    expandedRowRender = function expandedRowRender(record, index) {
  var children = record.children;
  return /*#__PURE__*/_react["default"].createElement(ExpandedApp, {
    dataSource: children,
    index: index
  });
};

var App = /*#__PURE__*/function (_React$Component2) {
  _inherits(App, _React$Component2);

  var _super2 = _createSuper(App);

  function App(props) {
    var _this2;

    _classCallCheck(this, App);

    _this2 = _super2.call(this, props);
    _this2.state = {
      dataSource: dataSource(),
      hasBorder: false,
      openRowKeys: []
    };
    return _this2;
  }

  _createClass(App, [{
    key: "onSort",
    value: function onSort(dataIndex, order) {
      var dataSource = this.state.dataSource.sort(function (a, b) {
        var result = a[dataIndex] - b[dataIndex];
        return order === 'asc' ? result > 0 ? 1 : -1 : result > 0 ? -1 : 1;
      });
      this.setState({
        dataSource: dataSource
      });
    }
  }, {
    key: "disabledExpandedCol",
    value: function disabledExpandedCol() {
      this.setState({
        getExpandedColProps: function getExpandedColProps(record, index) {
          console.log(index);

          if (index === 3) {
            return {
              disabled: true
            };
          }
        }
      });
    }
  }, {
    key: "toggleCol",
    value: function toggleCol() {
      this.setState({
        hasExpandedRowCtrl: false
      });
    }
  }, {
    key: "onRowOpen",
    value: function onRowOpen(openRowKeys) {
      this.setState({
        openRowKeys: openRowKeys
      });
    }
  }, {
    key: "toggleExpand",
    value: function toggleExpand(record) {
      var key = record.id,
          openRowKeys = this.state.openRowKeys,
          index = openRowKeys.indexOf(key);

      if (index > -1) {
        openRowKeys.splice(index, 1);
      } else {
        openRowKeys.push(key);
      }

      this.setState({
        openRowKeys: openRowKeys
      });
    }
  }, {
    key: "rowProps",
    value: function rowProps(record, index) {
      console.log('rowProps', record, index);
      return {
        className: "next-myclass-".concat(index)
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;

      var renderTitle = function renderTitle(value, index, record) {
        return /*#__PURE__*/_react["default"].createElement("div", null, value, /*#__PURE__*/_react["default"].createElement("span", {
          onClick: _this3.toggleExpand.bind(_this3, record)
        }, "index:", index, " +++++"));
      };

      return /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement("p", null, ' ', /*#__PURE__*/_react["default"].createElement(_button["default"], {
        onClick: this.disabledExpandedCol.bind(this)
      }, ' ', "disable fourth row", ' '), /*#__PURE__*/_react["default"].createElement("span", {
        style: {
          marginRight: 20
        }
      }), /*#__PURE__*/_react["default"].createElement(_button["default"], {
        onClick: this.toggleCol.bind(this)
      }, " hide + ")), /*#__PURE__*/_react["default"].createElement(_["default"], {
        dataSource: this.state.dataSource,
        expandedIndexSimulate: true,
        isZebra: this.state.isZebra,
        hasBorder: this.state.hasBorder,
        onSort: this.onSort.bind(this),
        expandedRowRender: expandedRowRender,
        expandedRowIndent: [1, 1],
        openRowKeys: this.state.openRowKeys,
        getExpandedColProps: this.state.getExpandedColProps,
        hasExpandedRowCtrl: this.state.hasExpandedRowCtrl,
        onRowOpen: this.onRowOpen.bind(this),
        rowProps: this.rowProps.bind(this)
      }, /*#__PURE__*/_react["default"].createElement(_["default"].Column, {
        title: "Id",
        dataIndex: "id",
        sortable: true
      }), /*#__PURE__*/_react["default"].createElement(_["default"].Column, {
        title: "Title",
        dataIndex: "title",
        cell: renderTitle
      }), /*#__PURE__*/_react["default"].createElement(_["default"].Column, {
        title: "Time",
        dataIndex: "time",
        width: 200
      }), /*#__PURE__*/_react["default"].createElement(_["default"].Column, {
        cell: _render,
        width: 200
      })));
    }
  }]);

  return App;
}(_react["default"].Component);

_reactDom["default"].render( /*#__PURE__*/_react["default"].createElement(App, null), document.getElementById('table-demo-8'));