"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _ = _interopRequireDefault(require(".."));
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Table/DataTable/docs/ExampleSortable.jsx";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(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; })(); }
var baseData = [{
  firstName: 'Meghan',
  lastName: 'Bishop'
}, {
  firstName: 'Sara',
  lastName: 'Porter'
}, {
  firstName: 'Deborah',
  lastName: 'Rhodes'
}, {
  firstName: 'Walter',
  lastName: 'Jenning'
}, {
  firstName: 'Amanda',
  lastName: 'Woods'
}];
var DataTableSortableExample = /*#__PURE__*/function (_React$Component) {
  function DataTableSortableExample(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, DataTableSortableExample);
    _this = _callSuper(this, DataTableSortableExample, [props]);
    _this.state = {
      sort: {},
      data: baseData
    };
    return _this;
  }
  (0, _inherits2["default"])(DataTableSortableExample, _React$Component);
  return (0, _createClass2["default"])(DataTableSortableExample, [{
    key: "handleSortClick",
    value: function handleSortClick(colNum) {
      var desc = !this.state.sort[colNum];
      var sort = _objectSpread(_objectSpread({}, this.state.sort), {}, (0, _defineProperty2["default"])({}, colNum, desc));
      var fields = {
        1: 'firstName',
        2: 'lastName'
      };
      var sortedData = this.sortDataByField(fields[colNum], desc);
      this.setState({
        sort: sort,
        data: sortedData
      });
    }
  }, {
    key: "sortDataByField",
    value: function sortDataByField(field, desc) {
      return this.state.data.sort(function (a, b) {
        return desc ? ~~(field ? a[field] < b[field] : a < b) : ~~(field ? a[field] > b[field] : a > b);
      }); // eslint-disable-line
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      return /*#__PURE__*/_react["default"].createElement("div", {
        style: this.props.style,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 41,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement(_["default"], {
        dataHook: this.props.dataHook,
        data: this.state.data,
        onSortClick: function onSortClick(col, colNum) {
          return _this2.handleSortClick(colNum);
        },
        itemsPerPage: 20,
        columns: [{
          title: 'Row Number',
          render: function render(row, rowNum) {
            return '#' + (rowNum + 1);
          },
          width: '20%',
          important: true,
          infoTooltipProps: {
            content: 'Very informative tooltip text'
          }
        }, {
          title: 'First Name',
          sortable: true,
          sortDescending: !!this.state.sort[1],
          render: function render(row) {
            return /*#__PURE__*/_react["default"].createElement("span", {
              __self: _this2,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 59,
                columnNumber: 30
              }
            }, row.firstName);
          },
          width: '40%'
        }, {
          title: 'Last Name',
          sortable: true,
          sortDescending: !!this.state.sort[2],
          render: function render(row) {
            return /*#__PURE__*/_react["default"].createElement("span", {
              __self: _this2,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 66,
                columnNumber: 30
              }
            }, row.lastName);
          },
          width: '40%',
          infoTooltipProps: {
            content: 'Very informative tooltip text'
          }
        }],
        showLastRowDivider: false,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 42,
          columnNumber: 9
        }
      }));
    }
  }]);
}(_react["default"].Component);
DataTableSortableExample.defaultProps = {
  style: {
    width: '966px'
  },
  dataHook: 'story-data-table-sortable'
};
var _default = exports["default"] = DataTableSortableExample;