"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = require("react");

var _TableContext = _interopRequireDefault(require("./TableContext"));

var _enum = require("../data-set/enum");

var Profiler = /*#__PURE__*/function (_PureComponent) {
  (0, _inherits2["default"])(Profiler, _PureComponent);

  var _super = (0, _createSuper2["default"])(Profiler);

  function Profiler(props, context) {
    var _this;

    (0, _classCallCheck2["default"])(this, Profiler);
    _this = _super.call(this, props, context);
    var tableStore = context.tableStore,
        dataSet = context.dataSet;

    if (tableStore.performanceEnabled) {
      if (dataSet.status === _enum.DataSetStatus.ready && dataSet.length) {
        tableStore.performanceOn = true;
        tableStore.timing.renderStart = Date.now();
      }
    }

    return _this;
  }

  (0, _createClass2["default"])(Profiler, [{
    key: "componentWillUpdate",
    value: function componentWillUpdate() {
      var tableStore = this.context.tableStore;

      if (tableStore.performanceEnabled && tableStore.performanceOn) {
        tableStore.timing.renderStart = Date.now();
      }
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      this.handlePerformance();
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      this.handlePerformance();
    }
  }, {
    key: "handlePerformance",
    value: function handlePerformance() {
      var _this$context = this.context,
          code = _this$context.code,
          tableStore = _this$context.tableStore,
          dataSet = _this$context.dataSet;

      if (tableStore.performanceEnabled && tableStore.performanceOn) {
        var timing = tableStore.timing;
        var performance = dataSet.performance;
        var onPerformance = tableStore.getConfig('onPerformance');
        timing.renderEnd = Date.now();
        onPerformance('Table', {
          name: code,
          url: performance.url,
          size: dataSet.length,
          timing: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, performance.timing), timing)
        });
        tableStore.performanceOn = false;
      }
    }
  }, {
    key: "render",
    value: function render() {
      var children = this.props.children;
      return children;
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _TableContext["default"];
    }
  }]);
  return Profiler;
}(_react.PureComponent);

exports["default"] = Profiler;
Profiler.displayName = 'Profiler';
//# sourceMappingURL=Profiler.js.map
