/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

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

function useVModel(value, defaultValue, onChange, eventName) {
  var _getCurrentInstance = VueCompositionAPI.getCurrentInstance(),
      emit = _getCurrentInstance.emit;

  var internalValue = VueCompositionAPI.ref();
  internalValue.value = defaultValue;

  if (typeof value.value !== "undefined") {
    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 === null || emit === void 0 ? void 0 : emit.apply(void 0, ["input", newValue].concat(args));
      onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, [newValue].concat(args));

      if (eventName && eventName !== "input") {
        emit === null || emit === void 0 ? void 0 : 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];
    }

    onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, [newValue].concat(args));

    if (eventName && eventName !== "input") {
      emit === null || emit === void 0 ? void 0 : emit.apply(void 0, [eventName, newValue].concat(args));
    }
  }];
}

exports["default"] = useVModel;
//# sourceMappingURL=use-vmodel.js.map
