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

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var vue = require('vue');
var isArray = require('lodash/isArray');
var hooks_useVModel = require('../../hooks/useVModel.js');
var _common_js_datePicker_format = require('../../_common/js/date-picker/format.js');
var _common_js_datePicker_utils = require('../../_common/js/date-picker/utils.js');
require('lodash/kebabCase');
require('lodash/isString');
require('dayjs');
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-f4db2590.js');
require('../../_chunks/dep-b7fa06da.js');
require('lodash/chunk');

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

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

var PARTIAL_MAP = {
  first: "start",
  second: "end"
};
function useRangeValue(props) {
  var _toRefs = vue.toRefs(props),
    valueFromProps = _toRefs.value,
    modelValue = _toRefs.modelValue;
  var _useVModel = hooks_useVModel["default"](valueFromProps, modelValue, props.defaultValue, props.onChange),
    _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
    value = _useVModel2[0],
    onChange = _useVModel2[1];
  var formatRef = vue.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"));
  }
  if (!isArray__default["default"](value.value)) {
    console.error("typeof value: ".concat(value.value, " must be Array!"));
  } else if (!_common_js_datePicker_format.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 = vue.ref(false);
  var time = vue.ref(_common_js_datePicker_format.initYearMonthTime({
    value: value.value,
    mode: props.mode,
    format: formatRef.value.format,
    timeFormat: formatRef.value.timeFormat
  }).time);
  var month = vue.ref(_common_js_datePicker_format.initYearMonthTime({
    value: value.value,
    mode: props.mode,
    format: formatRef.value.format,
    enableTimePicker: props.enableTimePicker
  }).month);
  var year = vue.ref(_common_js_datePicker_format.initYearMonthTime({
    value: value.value,
    mode: props.mode,
    format: formatRef.value.format
  }).year);
  var cacheValue = vue.ref(_common_js_datePicker_format.formatDate(value.value, {
    format: formatRef.value.format
  }));
  vue.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.timeFormat, props.defaultTime);
  });
  return {
    year: year,
    month: month,
    value: value,
    time: time,
    isFirstValueSelected: isFirstValueSelected,
    cacheValue: cacheValue,
    onChange: onChange
  };
}

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