import { InternalDateGetter } from "../InternalDateGetter";
import { InternalDateComponentType } from "../types";
export var InternalDateCalculator = /*#__PURE__*/function () {
  function InternalDateCalculator() {}
  InternalDateCalculator.calcRangeStartDateComponent = function calcRangeStartDateComponent(type, _ref, _ref2) {
    var year = _ref.year,
      month = _ref.month;
    var startYear = _ref2.year,
      startMonth = _ref2.month,
      startDate = _ref2.date;
    if (type === InternalDateComponentType.Year) {
      return startYear;
    } else if (type === InternalDateComponentType.Month) {
      return year === startYear ? startMonth : InternalDateGetter.getDefaultMin(type);
    }
    return year === startYear && month === startMonth ? startDate : InternalDateGetter.getDefaultMin(type);
  };
  InternalDateCalculator.calcRangeEndDateComponent = function calcRangeEndDateComponent(type, _ref3, _ref4) {
    var year = _ref3.year,
      month = _ref3.month,
      date = _ref3.date;
    var endYear = _ref4.year,
      endMonth = _ref4.month,
      endDate = _ref4.date;
    if (type === InternalDateComponentType.Year) {
      return endYear;
    } else if (type === InternalDateComponentType.Month) {
      return year === endYear ? endMonth : InternalDateGetter.getDefaultMax(type);
    }
    return year === endYear && month === endMonth ? endDate : InternalDateGetter.getDefaultMax(type, {
      year: year,
      month: month,
      date: date
    });
  };
  InternalDateCalculator.calcShiftValueDateComponent = function calcShiftValueDateComponent(step, prevValue, start, end, isLoop) {
    if (isLoop === void 0) {
      isLoop = true;
    }
    var value = step + Number(prevValue);
    if (step !== 0 && (start - value > Math.abs(step) || value - end > Math.abs(step))) {
      return step < 0 ? end : start;
    }
    if (isLoop) {
      if (value < start) {
        return end;
      } else if (value > end) {
        return start;
      }
      return value;
    }
    if (value < start) {
      return start;
    } else if (value > end) {
      return end;
    }
    return value;
  };
  return InternalDateCalculator;
}();