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

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var dayjs = require('dayjs');
var format = require('../../../chunks/format.js');
var utils = require('../../../chunks/utils.js');
var hooks_useVModel = require('../../../hooks/useVModel.js');
require('../../../chunks/dayjs.min-0f6442fd.js');
require('../../../chunks/_commonjsHelpers-fe796db6.js');
require('../../../chunks/log.js');
require('../../../chunks/isObjectLike-51896b77.js');
require('../../../chunks/defineProperty-19da3d4c.js');
require('../../../chunks/_isIndex-8b06cfbb.js');
require('../../../chunks/isFunction-cb08cfdf.js');
require('../../../chunks/isSymbol-0ea4cedf.js');
require('lodash/kebabCase');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);

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

exports["default"] = useSingleValue;
//# sourceMappingURL=use-single-value.js.map
