import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _DatePicker from "@alifd/next/es/date-picker";
var _excluded = ["nextTablePrefix", "value", "onChange", "rules", "name"];
import React from "react";
import Moment from "moment";
import BaseTableField from "./baseTableField";
var RangePicker = _DatePicker.RangePicker;
var DateRangeField = /*#__PURE__*/function (_BaseTableField) {
  _inheritsLoose(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 ? Moment(start) : null, end ? Moment(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 = _objectWithoutPropertiesLoose(_this$props, _excluded);
    return /*#__PURE__*/React.createElement(RangePicker, _extends({
      className: nextTablePrefix + "date-range-picker"
    }, field.init(name, {
      rules: rules
    }, rest)));
  };
  return DateRangeField;
}(BaseTableField);
export { DateRangeField as default };