'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var miscUtil = require('../utils/miscUtil.cjs');
var dateUtil = require('../utils/dateUtil.cjs');

function useRangeDisabled({
  picker,
  locale,
  selectedValue,
  disabledDate,
  disabled,
  generateConfig
}, openRecordsRef) {
  const startDate = vue.computed(() => miscUtil.getValue(selectedValue.value, 0));
  const endDate = vue.computed(() => miscUtil.getValue(selectedValue.value, 1));
  function weekFirstDate(date) {
    return generateConfig.value.locale.getWeekFirstDate(locale.value.locale, date);
  }
  function monthNumber(date) {
    const year = generateConfig.value.getYear(date);
    const month = generateConfig.value.getMonth(date);
    return year * 100 + month;
  }
  function quarterNumber(date) {
    const year = generateConfig.value.getYear(date);
    const quarter = dateUtil.getQuarter(generateConfig.value, date);
    return year * 10 + quarter;
  }
  const disabledStartDate = (date) => {
    var _a;
    if (disabledDate && ((_a = disabledDate == null ? void 0 : disabledDate.value) == null ? void 0 : _a.call(disabledDate, date)))
      return true;
    if (disabled[1] && endDate) {
      return !dateUtil.isSameDate(generateConfig.value, date, endDate.value) && generateConfig.value.isAfter(date, endDate.value);
    }
    if (openRecordsRef.value[1] && endDate.value) {
      switch (picker.value) {
        case "quarter":
          return quarterNumber(date) > quarterNumber(endDate.value);
        case "month":
          return monthNumber(date) > monthNumber(endDate.value);
        case "week":
          return weekFirstDate(date) > weekFirstDate(endDate.value);
        default:
          return !dateUtil.isSameDate(generateConfig.value, date, endDate.value) && generateConfig.value.isAfter(date, endDate.value);
      }
    }
    return false;
  };
  const disabledEndDate = (date) => {
    var _a;
    if ((_a = disabledDate.value) == null ? void 0 : _a.call(disabledDate, date))
      return true;
    if (disabled[0] && startDate) {
      return !dateUtil.isSameDate(generateConfig.value, date, endDate.value) && generateConfig.value.isAfter(startDate.value, date);
    }
    if (openRecordsRef.value[0] && startDate.value) {
      switch (picker.value) {
        case "quarter":
          return quarterNumber(date) < quarterNumber(startDate.value);
        case "month":
          return monthNumber(date) < monthNumber(startDate.value);
        case "week":
          return weekFirstDate(date) < weekFirstDate(startDate.value);
        default:
          return !dateUtil.isSameDate(generateConfig.value, date, startDate.value) && generateConfig.value.isAfter(startDate.value, date);
      }
    }
    return false;
  };
  return [disabledStartDate, disabledEndDate];
}

exports.default = useRangeDisabled;
//# sourceMappingURL=useRangeDisabled.cjs.map
