function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

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

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

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

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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

// @ts-nocheck
import React, { Component } from "react";
import PropTypes from "prop-types";
import moment from "moment";
import Slider from "antd/es/slider";
var DEFAULT_FORMAT_DATE = "YYYY-MM-DD";
var DEFAULT_FORMAT_MONTH = "YYYY-MM";
var DEFAULT_VIEWTYPE = "day";
var DEFAULT_OPTS = {
  min: 0,
  step: 1
};

var returnDiff = function returnDiff(start, end, viewType) {
  return moment(end).diff(moment(start), viewType === "day" ? "days" : "months");
};

var returnAdd = function returnAdd(start, addNum, viewType) {
  return moment(start).add(addNum, viewType === "day" ? "days" : "months");
};

var compareDate = function compareDate(start, end) {
  return moment(end).isAfter(moment(start));
};

var formatValue = function formatValue(value, format) {
  return moment(value).format(format);
};

var calculateDiff = function calculateDiff(props) {
  var min = props.min,
      max = props.max,
      defaultValue = props.defaultValue,
      viewType = props.viewType,
      format = props.format;
  var defaultState = {
    format: format || (viewType === "day" ? DEFAULT_FORMAT_DATE : DEFAULT_FORMAT_MONTH),
    diff: returnDiff(min, max, viewType),
    defaultValue: defaultValue && compareDate ? returnDiff(min, defaultValue, viewType) : 0
  };
  return defaultState;
};

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

  var _super = _createSuper(SliderDate);

  function SliderDate(props) {
    var _this;

    _classCallCheck(this, SliderDate);

    _this = _super.call(this, props);

    _this.handleProps = function () {
      var _marks;

      var _this$state = _this.state,
          diff = _this$state.diff,
          defaultValue = _this$state.defaultValue,
          format = _this$state.format;
      var _this$props = _this.props,
          min = _this$props.min,
          max = _this$props.max,
          _this$props$defaultVa = _this$props.defaultValue,
          propDefault = _this$props$defaultVa === void 0 ? min : _this$props$defaultVa;
      var marks = (_marks = {
        0: formatValue(min, format)
      }, _defineProperty(_marks, defaultValue, formatValue(propDefault, format)), _defineProperty(_marks, diff, formatValue(max, format)), _marks);

      var sliderProps = _objectSpread(_objectSpread({}, DEFAULT_OPTS), {}, {
        max: diff,
        defaultValue: defaultValue,
        marks: marks
      });

      return sliderProps;
    };

    _this.handleAfterChange = function (value) {
      var onAfterChange = _this.props.onAfterChange;
      onAfterChange(_this.formatter(value));
    };

    _this.handleChange = function (value) {
      var onChange = _this.props.onChange;
      onChange(_this.formatter(value));
    };

    _this.formatter = function (value) {
      var _this$props2 = _this.props,
          min = _this$props2.min,
          viewType = _this$props2.viewType;
      var format = _this.state.format;
      var nVal = returnAdd(min, value, viewType);
      return formatValue(nVal, format);
    };

    _this.state = _objectSpread({}, calculateDiff(props));
    return _this;
  }

  _createClass(SliderDate, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(Slider, _extends({}, this.props, this.handleProps(), {
        tipFormatter: this.formatter,
        onAfterChange: this.handleAfterChange,
        onChange: this.handleChange
      }));
    }
  }]);

  return SliderDate;
}(Component);

SliderDate.propTypes = {
  viewType: PropTypes.string,
  // format: PropTypes.string,
  onChange: PropTypes.func,
  onAfterChange: PropTypes.func
};
SliderDate.defaultProps = {
  viewType: DEFAULT_VIEWTYPE,
  onChange: function onChange() {},
  onAfterChange: function onAfterChange() {}
};
export { SliderDate as default };