/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');

function useDefaultValue(value, defaultValue, onChange, propsName, eventName) {
  const {
    emit,
    vnode
  } = VueCompositionAPI.getCurrentInstance();
  const internalValue = VueCompositionAPI.ref();
  internalValue.value = defaultValue;
  if (Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, propsName)) {
    return [value, function (newValue) {
      for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        args[_key - 1] = arguments[_key];
      }
      emit(`update:${propsName}`, newValue, ...args);
      onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
      emit(eventName, newValue, ...args);
    }];
  }
  return [internalValue, function (newValue) {
    internalValue.value = newValue;
    for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
      args[_key2 - 1] = arguments[_key2];
    }
    emit(eventName, newValue, ...args);
    onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
  }];
}

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