/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

import { toRefs, computed, ref, watchEffect } from '@vue/composition-api';
import dayjs from 'dayjs';
import { g as getDefaultFormat, a as formatTime, f as formatDate, i as isValidDate } from '../../../_chunks/dep-45f37c99.js';
import { b as extractTimeFormat } from '../../../_chunks/dep-52f1cb4f.js';
import useVModel from '../../../hooks/useVModel.js';
import '../../../_chunks/dep-72951546.js';
import '../../../_chunks/dep-102361be.js';
import '../../../_chunks/dep-eaa95999.js';
import '../../../_chunks/dep-52c80d08.js';
import '../../../_chunks/dep-aacc31a3.js';
import '../../../_chunks/dep-40693b6f.js';
import '../../../_chunks/dep-c3acb800.js';
import '../../../_chunks/dep-128cad98.js';
import 'lodash/kebabCase';

function useSingleValue(props) {
  const {
    value: valueFromProps
  } = toRefs(props);
  const [value, onChange] = useVModel(valueFromProps, props.defaultValue, props.onChange, "change");
  const formatRef = computed(() => getDefaultFormat({
    mode: props.mode,
    format: props.format,
    enableTimePicker: props.enableTimePicker
  }));
  if (props.enableTimePicker) {
    if (!extractTimeFormat(formatRef.value.format)) console.error(`format: ${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`);
  }
  const time = ref(formatTime(value.value, formatRef.value.timeFormat));
  const month = ref(dayjs(value.value).month() || new Date().getMonth());
  const year = ref(dayjs(value.value).year() || new Date().getFullYear());
  const cacheValue = ref(formatDate(value.value, {
    format: formatRef.value.format
  }));
  watchEffect(() => {
    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);
  });
  return {
    year,
    month,
    value,
    time,
    cacheValue,
    onChange
  };
}

export { useSingleValue as default };
//# sourceMappingURL=use-single-value.js.map
