import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Component } from 'react';
import classnames from 'classnames';
import omit from 'lodash/omit';
export default function createTableRow() {
  var Cmp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'tr';

  var BodyRow = /*#__PURE__*/function (_Component) {
    _inherits(BodyRow, _Component);

    var _super = _createSuper(BodyRow);

    function BodyRow(props) {
      var _this;

      _classCallCheck(this, BodyRow);

      _this = _super.call(this, props);
      _this.store = props.store;

      var _this$store$getState = _this.store.getState(),
          selectedRowKeys = _this$store$getState.selectedRowKeys;

      _this.state = {
        selected: selectedRowKeys.indexOf(props.rowKey) >= 0
      };
      return _this;
    }

    _createClass(BodyRow, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        this.subscribe();
      }
    }, {
      key: "componentWillUnmount",
      value: function componentWillUnmount() {
        if (this.unsubscribe) {
          this.unsubscribe();
        }
      }
    }, {
      key: "subscribe",
      value: function subscribe() {
        var _this2 = this;

        var _this$props = this.props,
            store = _this$props.store,
            rowKey = _this$props.rowKey;
        this.unsubscribe = store.subscribe(function () {
          var state = _this2.state;

          var _this2$store$getState = _this2.store.getState(),
              selectedRowKeys = _this2$store$getState.selectedRowKeys;

          var selected = selectedRowKeys.indexOf(rowKey) >= 0;

          if (selected !== state.selected) {
            _this2.setState({
              selected: selected
            });
          }
        });
      }
    }, {
      key: "render",
      value: function render() {
        var props = this.props;
        var selected = this.state.selected;
        var className = props.className,
            prefixCls = props.prefixCls,
            children = props.children;
        var omits = ['prefixCls', 'rowKey', 'store', 'children'];

        if (Cmp === 'tr') {
          omits.push('record');
        }

        var otherProps = omit(props, omits);
        var classString = classnames(className, _defineProperty({}, "".concat(prefixCls, "-row-selected"), selected));
        return /*#__PURE__*/React.createElement(Cmp, _extends({}, otherProps, {
          className: classString
        }), children);
      }
    }]);

    return BodyRow;
  }(Component);

  return BodyRow;
}
//# sourceMappingURL=createBodyRow.js.map
