"use strict";

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

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

var _dayjs = _interopRequireDefault(require("dayjs"));

var parseState = function parseState(props) {
  var defaultValue = props.defaultValue,
      mode = props.mode,
      direction = props.direction;
  var value = props.value;
  var tmpValue;
  value = value || defaultValue;
  value = Array.isArray(value) ? value : value ? [value] : [];
  tmpValue = value.map(function (item) {
    return (0, _dayjs.default)(item).toDate();
  }).sort(function (item1, item2) {
    return +item1 - +item2;
  });

  if (mode === 'range') {
    tmpValue = [tmpValue[0], tmpValue[tmpValue.length - 1]];
  }

  var min = props.min ? (0, _dayjs.default)(props.min).toDate() : (0, _dayjs.default)().toDate(); // const startMonth = dayjs(min).toDate();

  var max = props.max ? (0, _dayjs.default)(props.max).toDate() : (0, _dayjs.default)(min).add(1, 'year').toDate(); // min、max 排序

  var duration = [min, max].sort(function (item1, item2) {
    return +item1 - +item2;
  });
  var steps = mode === 'range' ? 2 : 1;
  return {
    value: tmpValue,
    min: duration[0],
    max: duration[1],
    // 是否是入参更新(主要是月份跨度更新，需要重新定位)
    refresh: false,
    // 注掉该逻辑，强制根据 multiple 控制节点个数，后面改进
    // steps:Math.max(tmp.value.length, tmp.defaultValue.length);
    steps: steps,
    // 初始化点击步数
    mode: mode,
    direction: direction
  };
};

var _default = parseState;
exports.default = _default;