"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosAntd = require("amos-antd"),
  _amosTool = require("amos-tool"),
  _AmosFilter = _interopRequireDefault(require("./../filter/AmosFilter")),
  _SearchBtn = _interopRequireDefault(require("./../btns/SearchBtn"));

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

function _getRequireWildcardCache() {
  if ("function" != typeof WeakMap) return null;
  var e = new WeakMap;
  return _getRequireWildcardCache = function() {
    return e
  }, e
}

function _interopRequireWildcard(e) {
  if (e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache();
  if (t && t.has(e)) return t.get(e);
  var r, o, i = {},
    n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((o = n ? Object.getOwnPropertyDescriptor(e, r) : null) && (o.get || o.set) ? Object.defineProperty(i, r, o) : i[r] = e[r]);
  return i.default = e, t && t.set(e, i), i
}

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var o = t[r];
    o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

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

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var o = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, o ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

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

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Date.prototype.toString.call(Reflect.construct(Date, [], function() {})), !0
  } catch (e) {
    return !1
  }
}

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

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
require("./style/amosGrid.scss");
var AmosGridTable = function() {
  _inherits(r, _react.Component);
  var t = _createSuper(r);

  function r(e) {
    var i;
    return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(i = t.call(this, e)), "onWindowResize", function(e) {
      i.getHeightOffset()
    }), _defineProperty(_assertThisInitialized(i), "onSelectChange", function(e, t) {
      i.setState({
        selectedRowKeys: e,
        selectedRows: t
      }, i.props.getSelectedRows(t, e))
    }), _defineProperty(_assertThisInitialized(i), "onSizeChange", function(e, t) {
      var r = i.props.setPageConfig;
      r && r({
        current: e,
        pageSize: t
      }), i.setState({
        current: e,
        pageSize: t
      }, i.reload)
    }), _defineProperty(_assertThisInitialized(i), "onPaginationChange", function(e) {
      var t = i.props.setPageConfig;
      t && t({
        current: e
      }), i.setState({
        current: e
      }, i.reload)
    }), _defineProperty(_assertThisInitialized(i), "getbtns", function() {
      var r = [];
      return i.props.operBtns.map(function(e, t) {
        r.push(_react.default.createElement("div", {
          key: "btn".concat(t),
          className: "amos-grid-oper-btn"
        }, e))
      }), r
    }), _defineProperty(_assertThisInitialized(i), "changeFilters", function(e) {
      var r = e,
        o = {};
      Object.keys(r).map(function(e) {
        var t = r[e];
        t && "" !== t && (o[e] = t, "enabled" === e && (o[e] = "启用" === t))
      }), i.setState({
        filter: o
      }, i.reload)
    }), _defineProperty(_assertThisInitialized(i), "openFilter", function() {
      var e = i.state.showFilter;
      i.setState({
        showFilter: !e
      })
    }), _defineProperty(_assertThisInitialized(i), "reload", function() {
      var e = i.state,
        t = e.current,
        r = e.pageSize,
        o = e.filter,
        e = e.otherFilter;
      i.props.getTableDataAction({
        current: t - 1,
        pageSize: r
      }, JSON.stringify(o), e), i.getHeightOffset()
    }), _defineProperty(_assertThisInitialized(i), "addOperateCol", function(e, t) {
      t = (0, i.props.operateCol)(e, t);
      return _react.default.createElement("div", {
        className: "operation-buttons"
      }, t)
    }), _defineProperty(_assertThisInitialized(i), "showTotal", function(e) {
      return "共 ".concat(e, " 条")
    }), _defineProperty(_assertThisInitialized(i), "generateRowkey", function(e, t) {
      return e.id || t + (i.state.current - 1) * i.state.pageSize
    }), _defineProperty(_assertThisInitialized(i), "getHeightOffset", function() {
      var e = i.props.getPanelHeight,
        e = void 0 === e ? 450 : e();
      e && i.setState({
        maxHeight: e
      })
    }), i.state = {
      selectedRowKeys: [],
      selectedRows: [],
      loading: !1,
      dataList: [],
      size: "middle",
      current: e.defaultPageConfig ? e.defaultPageConfig.current : 1,
      pageSize: e.defaultPageConfig ? e.defaultPageConfig.pageSize : 10,
      filter: {},
      totals: 1,
      showFilter: !0,
      otherFilter: e.otherFilter,
      maxHeight: 450
    }, i
  }
  return _createClass(r, [{
    key: "componentDidMount",
    value: function() {
      this.props.callBack(this.reload), this.getHeightOffset(), window.addEventListener("resize", this.onWindowResize)
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      e.url !== this.props.url && this.reload(), e.otherFilter && e.otherFilter !== this.props.otherFilter && this.setState({
        otherFilter: e.otherFilter
      }, this.reload)
    }
  }, {
    key: "componentWillUnmount",
    value: function() {
      window.removeEventListener("resize", this.onWindowResize)
    }
  }, {
    key: "isVisableSearch",
    value: function(e) {
      var t = !1;
      return e.map(function(e) {
        if (e.query) return t = !0
      }), t
    }
  }, {
    key: "render",
    value: function() {
      var r = this,
        e = this.state,
        t = e.loading,
        o = e.selectedRowKeys,
        i = e.size,
        n = e.maxHeight,
        a = this.props,
        s = a.columns,
        l = a.isChecked,
        u = a.operateCol,
        c = a.isTreeTable,
        p = a.isPageable,
        f = a.pagination,
        d = a.dataList,
        e = a.totals,
        a = a.rowClassName,
        o = {
          selectedRowKeys: this.props.selectedRowKeys || o,
          onChange: this.onSelectChange
        },
        o = l ? o : void 0;
      u && (s[s.length - 1].render = function(e, t) {
        return r.addOperateCol(e, t)
      });
      e = !1 !== f && (f || {
        size: "small",
        total: e,
        current: this.state.current,
        pageSize: this.state.pageSize,
        onShowSizeChange: this.onSizeChange,
        onChange: this.onPaginationChange,
        showSizeChanger: !0,
        showTotal: this.showTotal
      }), p = !1 !== p && e;
      _amosTool.Log.info("the table has pagination", !!p);
      var e = this.state.showFilter ? "other-table-bar" : "table-bar",
        y = {
          display: this.state.showFilter ? "block" : "none"
        };
      return _react.default.createElement("div", {
        className: "grid-content"
      }, _react.default.createElement("div", {
        className: "oper-bar"
      }, _react.default.createElement("div", {
        className: "amos-grid-oper-btns"
      }, this.getbtns())), _react.default.createElement("div", {
        className: e
      }, _react.default.createElement(_amosAntd.Table, {
        title: function() {
          return _react.default.createElement("div", {
            style: y
          }, _react.default.createElement(_AmosFilter.default, {
            filterSearchModel: s,
            closeFilter: r.openFilter,
            changeFilters: r.changeFilters
          }))
        },
        rowKey: c ? "key" : this.generateRowkey,
        loading: t,
        rowSelection: o,
        columns: s,
        dataSource: d,
        pagination: p,
        size: i,
        bordered: !0,
        scroll: {
          y: n
        },
        rowClassName: a
      })))
    }
  }]), r
}();
AmosGridTable.displayName = "AmosGridTable", AmosGridTable.propTypes = {
  url: _propTypes.default.string,
  columns: _propTypes.default.array,
  getSelectedRows: _propTypes.default.func,
  operBtns: _propTypes.default.array,
  isChecked: _propTypes.default.bool,
  operateCol: _propTypes.default.func,
  callBack: _propTypes.default.func,
  otherFilter: _propTypes.default.string,
  dataList: _propTypes.default.array,
  getTableDataAction: _propTypes.default.func,
  selectedRowKeys: _propTypes.default.array,
  totals: _propTypes.default.number,
  pagination: _propTypes.default.any,
  isPageable: _propTypes.default.bool,
  isTreeTable: _propTypes.default.bool,
  rowClassName: _propTypes.default.func,
  setPageConfig: _propTypes.default.func,
  defaultPageConfig: _propTypes.default.object,
  getPanelHeight: _propTypes.default.func
}, AmosGridTable.defaultProps = {
  operBtns: [],
  dataList: [],
  totals: 1,
  columns: [],
  isChecked: !0,
  isTreeTable: !1,
  otherFilter: ""
};
var _default = AmosGridTable;
exports.default = AmosGridTable, module.exports = exports.default;
