"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _datePicker = _interopRequireDefault(require("@alifd/next/lib/date-picker"));
var _react = _interopRequireDefault(require("react"));
var _moment = _interopRequireDefault(require("moment"));
var _baseTableField = _interopRequireDefault(require("./baseTableField"));
var _excluded = ["nextTablePrefix", "value", "onChange", "rules", "name"];
var RangePicker = _datePicker["default"].RangePicker;
var DateRangeField = /*#__PURE__*/function (_BaseTableField) {
  (0, _inheritsLoose2["default"])(DateRangeField, _BaseTableField);
  function DateRangeField() {
    return _BaseTableField.apply(this, arguments) || this;
  }
  var _proto = DateRangeField.prototype;
  _proto.convertValueToSet = function convertValueToSet(value) {
    var start = value.start,
      end = value.end;
    return [start ? (0, _moment["default"])(start) : null, end ? (0, _moment["default"])(end) : null];
  };
  _proto.dataChangeHandler = function dataChangeHandler(value) {
    var onChange = this.props.onChange;
    if (onChange) {
      var start = value[0],
        end = value[1];
      onChange && onChange({
        start: start ? start.toDate().getTime() : undefined,
        end: end ? end.toDate().getTime() : undefined
      });
    }
  };
  _proto.renderField = function renderField() {
    var field = this.field;
    var _this$props = this.props,
      nextTablePrefix = _this$props.nextTablePrefix,
      value = _this$props.value,
      onChange = _this$props.onChange,
      rules = _this$props.rules,
      name = _this$props.name,
      rest = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
    return /*#__PURE__*/_react["default"].createElement(RangePicker, (0, _extends2["default"])({
      className: nextTablePrefix + "date-range-picker"
    }, field.init(name, {
      rules: rules
    }, rest)));
  };
  return DateRangeField;
}(_baseTableField["default"]);
exports["default"] = DateRangeField;