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

import { _ as _slicedToArray } from '../../_chunks/dep-55846619.mjs';
import { toRefs, computed, ref, watchEffect } from 'vue';
import { getDefaultFormat, formatTime, parseToDayjs, formatDate, isValidDate } from '../../_common/js/date-picker/format.mjs';
import useVModel from '../../hooks/useVModel.mjs';
import { extractTimeFormat } from '../../_common/js/date-picker/utils.mjs';
import '../../_chunks/dep-cfcedf47.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_chunks/dep-e3b14d70.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../_chunks/dep-6b4aa943.mjs';
import '../../_common/js/log/index.mjs';
import '../../_common/js/log/log.mjs';
import '../../_chunks/dep-eb20e23f.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-0f0c89ff.mjs';
import '../../_chunks/dep-47763a99.mjs';
import '../../_chunks/dep-6205fc47.mjs';
import '../../_chunks/dep-be27d184.mjs';
import '../../_chunks/dep-59c8420d.mjs';
import '../../_chunks/dep-ee57d235.mjs';
import '../../_chunks/dep-ae357f26.mjs';
import '../../_chunks/dep-92e7085e.mjs';
import '../../_chunks/dep-8f777748.mjs';
import '../../_chunks/dep-10085c61.mjs';
import '../../_chunks/dep-c852a61a.mjs';
import '../../_chunks/dep-c4e1a112.mjs';
import '../../_chunks/dep-74848b92.mjs';
import '../../_chunks/dep-37ba476d.mjs';

function useSingleValue(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"));
  }
  var time = ref(formatTime(value.value, formatRef.value.format, formatRef.value.timeFormat, props.defaultTime));
  var month = ref(parseToDayjs(value.value, formatRef.value.format).month());
  var year = ref(parseToDayjs(value.value, 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,
    cacheValue: cacheValue,
    onChange: onChange
  };
}

export { useSingleValue as default };
//# sourceMappingURL=useSingleValue.mjs.map
