/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import { getCurrentInstance, ref } from '@vue/composition-api';

function useDefaultValue(value, defaultValue, onChange, propsName, eventName) {
  var _getCurrentInstance = getCurrentInstance(),
      emit = _getCurrentInstance.emit,
      vnode = _getCurrentInstance.vnode;

  var internalValue = 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.apply(void 0, ["update:".concat(propsName), newValue].concat(args));
      onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, [newValue].concat(args));
      emit.apply(void 0, [eventName, newValue].concat(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.apply(void 0, [eventName, newValue].concat(args));
    onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, [newValue].concat(args));
  }];
}

export { useDefaultValue as default };
//# sourceMappingURL=useDefaultValue.js.map
