/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _slicedToArray } from '../../_chunks/dep-84acf3c2.mjs';
import { toRefs, computed, ref, watchEffect } from 'vue';
import { i as isArray_1 } from '../../_chunks/dep-b57180d0.mjs';
import useVModel from '../../hooks/useVModel.mjs';
import { getDefaultFormat, isValidDate, initYearMonthTime, formatDate, formatTime } from '../../_common/js/date-picker/format.mjs';
import { extractTimeFormat } from '../../_common/js/date-picker/utils.mjs';
import '../../_chunks/dep-b8d7992c.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-9a85dac1.mjs';
import '../../_chunks/dep-1372b2d3.mjs';
import '../../_chunks/dep-42cc3015.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-2bc37d52.mjs';
import '../../_chunks/dep-3da99438.mjs';
import '../../_chunks/dep-876fb3ec.mjs';
import '../../_chunks/dep-9888611c.mjs';
import '../../_common/js/log/index.mjs';
import '../../_common/js/log/log.mjs';
import '../../_chunks/dep-2db7b3ec.mjs';
import '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-a8bcacea.mjs';
import '../../_chunks/dep-d24841dc.mjs';
import '../../_chunks/dep-f709f709.mjs';
import '../../_chunks/dep-8b989474.mjs';
import '../../_chunks/dep-345e1be3.mjs';
import '../../_chunks/dep-855db8bc.mjs';
import '../../_chunks/dep-9262ee2f.mjs';
import '../../_chunks/dep-2e7f59b1.mjs';
import '../../_chunks/dep-9fe2ef12.mjs';
import '../../_chunks/dep-42a19209.mjs';

var PARTIAL_MAP = {
  first: "start",
  second: "end"
};
function useRangeValue(props) {
  var _toRefs = toRefs(props),
    valueFromProps = _toRefs.value,
    modelValue = _toRefs.modelValue;
  var _useVModel = useVModel(valueFromProps, modelValue, props.defaultValue, props.onChange),
    _useVModel2 = _slicedToArray(_useVModel, 2),
    value = _useVModel2[0],
    onChange = _useVModel2[1];
  var formatRef = computed(function () {
    return getDefaultFormat({
      mode: props.mode,
      format: props.format,
      enableTimePicker: props.enableTimePicker
    });
  });
  if (props.enableTimePicker) {
    if (!extractTimeFormat(formatRef.value.format)) console.error("format: ".concat(formatRef.value.format, " \u4E0D\u89C4\u8303\uFF0C\u5305\u542B\u65F6\u95F4\u9009\u62E9\u5FC5\u987B\u8981\u6709\u65F6\u95F4\u683C\u5F0F\u5316 HH:mm:ss"));
  }
  if (!isArray_1(value.value)) {
    console.error("typeof value: ".concat(value.value, " must be Array!"));
  } else if (!isValidDate(value.value, formatRef.value.format)) {
    console.error("value: ".concat(value.value, " is invalid dateTime! Check whether the value is consistent with format: ").concat(formatRef.value.format));
  }
  var isFirstValueSelected = ref(false);
  var time = ref(initYearMonthTime({
    value: value.value,
    mode: props.mode,
    format: formatRef.value.format,
    timeFormat: formatRef.value.timeFormat
  }).time);
  var month = ref(initYearMonthTime({
    value: value.value,
    mode: props.mode,
    format: formatRef.value.format,
    enableTimePicker: props.enableTimePicker
  }).month);
  var year = ref(initYearMonthTime({
    value: value.value,
    mode: props.mode,
    format: formatRef.value.format
  }).year);
  var cacheValue = ref(formatDate(value.value, {
    format: formatRef.value.format
  }));
  watchEffect(function () {
    if (!value.value) {
      cacheValue.value = [];
      return;
    }
    if (!isValidDate(value.value, formatRef.value.format)) return;
    cacheValue.value = formatDate(value.value, {
      format: formatRef.value.format
    });
    time.value = formatTime(value.value, formatRef.value.timeFormat, props.defaultTime);
  });
  return {
    year: year,
    month: month,
    value: value,
    time: time,
    isFirstValueSelected: isFirstValueSelected,
    cacheValue: cacheValue,
    onChange: onChange
  };
}

export { PARTIAL_MAP, useRangeValue as default };
//# sourceMappingURL=useRangeValue.mjs.map
