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

import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { toRefs, computed, ref, watchEffect } from '@vue/composition-api';
import useVModel from '../../hooks/useVModel.js';
import { getDefaultFormat, isValidDate, initYearMonthTime, formatDate, formatTime } from '../../_common/js/date-picker/format.js';
import { extractTimeFormat } from '../../_common/js/date-picker/utils.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/kebabCase';
import 'lodash/isString';
import 'dayjs';
import '../../_chunks/dep-be599ec8.js';
import '../../_common/js/log/index.js';
import '../../_common/js/log/log.js';
import '@babel/runtime/helpers/objectDestructuringEmpty';
import '@babel/runtime/helpers/extends';
import '@babel/runtime/helpers/defineProperty';
import 'lodash/isFunction';
import '../../_chunks/dep-2de45821.js';
import 'lodash/chunk';

var PARTIAL_MAP = {
  first: "start",
  second: "end"
};
function useRangeValue(props) {
  var _toRefs = toRefs(props),
    valueFromProps = _toRefs.value;
  var _useVModel = useVModel(valueFromProps, props.defaultValue, props.onChange, "change"),
    _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 (!Array.isArray(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.format, 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.js.map
