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

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var VueCompositionAPI = require('@vue/composition-api');
var _common_js_datePicker_format = require('../../_common/js/date-picker/format.js');
var hooks_useVModel = require('../../hooks/useVModel.js');
var _common_js_datePicker_utils = require('../../_common/js/date-picker/utils.js');
require('lodash/isString');
require('dayjs');
require('../../_chunks/dep-7c884501.js');
require('../../_common/js/log/log.js');
require('@babel/runtime/helpers/objectDestructuringEmpty');
require('@babel/runtime/helpers/extends');
require('@babel/runtime/helpers/defineProperty');
require('lodash/isFunction');
require('../../_chunks/dep-6e3fbdd7.js');
require('lodash/chunk');
require('@babel/runtime/helpers/typeof');
require('lodash/kebabCase');

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

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);

function useSingleValue(props) {
  var _toRefs = VueCompositionAPI.toRefs(props),
    valueFromProps = _toRefs.value;
  var _useVModel = hooks_useVModel["default"](valueFromProps, props.defaultValue, props.onChange, "change"),
    _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
    value = _useVModel2[0],
    onChange = _useVModel2[1];
  var formatRef = VueCompositionAPI.computed(function () {
    return _common_js_datePicker_format.getDefaultFormat({
      mode: props.mode,
      format: props.format,
      enableTimePicker: props.enableTimePicker
    });
  });
  if (props.enableTimePicker) {
    if (!_common_js_datePicker_utils.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 = VueCompositionAPI.ref(_common_js_datePicker_format.formatTime(value.value, formatRef.value.format, formatRef.value.timeFormat, props.defaultTime));
  var month = VueCompositionAPI.ref(_common_js_datePicker_format.parseToDayjs(value.value, formatRef.value.format).month());
  var year = VueCompositionAPI.ref(_common_js_datePicker_format.parseToDayjs(value.value, formatRef.value.format).year());
  var cacheValue = VueCompositionAPI.ref(_common_js_datePicker_format.formatDate(value.value, {
    format: formatRef.value.format
  }));
  VueCompositionAPI.watchEffect(function () {
    if (!value.value) {
      cacheValue.value = "";
      return;
    }
    if (!_common_js_datePicker_format.isValidDate(value.value, formatRef.value.format)) return;
    cacheValue.value = _common_js_datePicker_format.formatDate(value.value, {
      format: formatRef.value.format
    });
    time.value = _common_js_datePicker_format.formatTime(value.value, formatRef.value.format, formatRef.value.timeFormat, props.defaultTime);
  });
  return {
    year: year,
    month: month,
    value: value,
    time: time,
    cacheValue: cacheValue,
    onChange: onChange
  };
}

exports["default"] = useSingleValue;
//# sourceMappingURL=useSingleValue.js.map
